Doomulation
April 6th, 2004, 14:20
I was kinda wondering here...has anyone experienced the compiler optimizing "too much" when using c++? At least the compiler I'm using, as MSVC++.net.
Because I'm having trouble with its over-optimization. Now I don't remember much asm, so I don't really know how to fix it.
The thing is, that the compiler is over optimizing and removing some code used to intialize a structure. At least the bit flag field.
Kindof like this:
int fnc(..., byte flags)
{
some_struct struct;
struct.bytefield = someflag1|someflag2|flags; <--- here's the problem
...
}
According to the assembly generated, the "flags" argument is passed in the cl register. Now, it doesn't save this register, but overwrites it earlier in the function for other purposes. Thus, when it comes to that line, it skips it completly. No code at all.
I was wondering how to fix this.
Perhaps some asm optimization to use another register or push the value to stack somehow? I don't remember how to retrieve data from the stack, however...
Some help would be greatly appreciated.
Azimer
April 6th, 2004, 23:58
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_core_optimization_problem.asp
Might help... Not sure what's up with .Net
Doomulation
April 7th, 2004, 07:58
Well, that's what I'm currently doing I'm afraid. Disabling global optimization for the function. Still, this means it doesn't get optimized. Some asm would probably be loads helpful, but I'm still an apprentice in that area.
smcd
June 7th, 2004, 23:48
If you know that it is the CL register that is being used, and that it is being corrupted earlier, you can do some inline assembly in there... __asm PUSH CL before the location where it gets used/corrupted then later (before the initialization) do __asm POP CL to restore the previous value.
Doomulation
June 8th, 2004, 09:26
Aha... I see, thanks for the input.
vBulletin v3.6.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.