deepzero Posted February 19, 2012 Posted February 19, 2012 hi,i am writing a function in c++ (msvc2008 pro), which has to be "portable" (ie. no calls to other functions or APIs) and fast.At one point i am using something like while(tlen++ < total) *str++ = leChar;which works fine, but msvc choses to "optimize" it to a crt-memset call. :/I generally noticed msvc is very keen on replacing code with crt calls to memset, even my custom memset-function, which uses an inlined REPMOV (and serves the sole purpose of making me independant from the crt...).Is there anyway i can turn off this specific optimization feature?I tried all sorts of linker switches; none of which worked properly.
Aguila Posted February 19, 2012 Posted February 19, 2012 look here:/>http://www.benshoof.org/blog/minicrt/you can further optimize the minicrt code with inline assembly and stuff.... 1
deepzero Posted February 19, 2012 Author Posted February 19, 2012 (edited) thanks, i am aware of minicrt, using it in quiet some projects. However, in this case i make extensive use of advanced crt features, so that`s not an option. I also doubt it would solve the problem...? anyways, the easiest solution is while(tlen++ < total){ _asm{NOP} *str++ = leChar;} which effectively prevents the memset optimization. I still dont see how memset is an optimization, though. It takes more space and is slower. Edited February 19, 2012 by deepzero
metr0 Posted February 19, 2012 Posted February 19, 2012 I had some kind of workaround back then. Something like outsourcing the code in question (in your case the loop) into a __forceinline function with #pragma optimize("", off) and on around it, respectively.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now