Advertisement Jump to content
Sign in to follow this  

Test32Args fail when using /O2-flag

This topic is 3674 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Some tests in the test_feature-directory fail for me when I use the /O2 (Optimize for Speed) flag in Visual Studio. The problem goes away when I use /O1 (Optimize for Size) or no optimization at all. This happens in both Angelscript 2.14.1 and 2.15.0. The failing tests are TestExecute32Args, TestExecute32MixedArgs and TestExecuteThis32MixedArgs. In case of TestExecute32MixedArgs, for example, I get:
TestExecute32Args (mixed arguments): testVal is not of expected value. Got:

ivalue[0]: 1
ivalue[1]: 2
ivalue[2]: 3
ivalue[3]: 4
fvalue[0]: 5.000000
fvalue[1]: 6.000000
fvalue[2]: 7.000000
fvalue[3]: 8.000000
ivalue[4]: 9
ivalue[5]: 10
ivalue[6]: 11
ivalue[7]: 12
fvalue[4]: 13.000000
fvalue[5]: 14.000000
fvalue[6]: -1.#IND00
fvalue[7]: -1.#IND00
ivalue[8]: 17
ivalue[9]: 18
ivalue[10]: 19
ivalue[11]: 20
fvalue[8]: 21.000000
fvalue[9]: 22.000000
fvalue[10]: 23.000000
fvalue[11]: 24.000000
ivalue[12]: 25
ivalue[13]: 26
ivalue[14]: 27
ivalue[15]: 28
fvalue[12]: 29.000000
fvalue[13]: 30.000000
fvalue[14]: 31.000000
fvalue[15]: 32.000000

The complete command line for the compiler is:
/O2 /GL /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_CRT_SECURE_NO_WARNINGS" /D "_MBCS" /GF /FD /EHsc /MD /W3 /nologo /c /Wp64 /Zi /TP /errorReport:prompt
Hope you can reproduce, find and fix this problem. Thanks.

Share this post

Link to post
Share on other sites
Yea, I've reported this to Andreas. I should find some time to hunt it down myself to help out. So busy though...

Share this post

Link to post
Share on other sites
Thanks DaBono,

this information should prove quite useful in the investigation on this problem. midnite reported the same problem back in September, but I've been too busy to look into it.

I'll try to give this some more priority early next year when I come back from my vacation.


Share this post

Link to post
Share on other sites
Hi Andreas, hi midnite,

I've dug a little deeper (and brushed off my assembly skills) and I've seem to have found what happens.

The optimizer assumes it has the whole FPU-stack (ST(0..7)) available to place the arguments on. That way it can efficiently store them in fvalues[] and use them to compare them to the expected values. However, on entry of the function, the FPU-stack already contains 2 elements (TAGS=0x0FFF). So, when f15 and f16 are pushed on the stack, the stack is full, leading to the failed test.

I've currently 'fixed' TestExecuteThis32MixedArgs by modifying CallThisCallFunction by adding fsave/frstor instructions (see below).

I'm however not really sure about the ramifications. The overhead for fsave/frstor is now payed for every function call, but I'm unsure how much that is exactly. I have no idea what the existing values on the stack represent, and if they need to be restored at all. Maybe a fninit-instruction can be used without harm?
This would be something a more asm-savvy person should look into, I guess.

Anyway, I hope this helps. Enjoy your holiday!

void CallThisCallFunction(const void *obj, const asDWORD *args, int paramSize, size_t func)
---> char fpuState[108];

// We must save registers that are used
push ecx
---> fsave fpuState

// Copy arguments from script
// stack to application stack
mov ecx, paramSize
mov eax, args
add eax, ecx
cmp ecx, 0
je endcopy
sub eax, 4
push dword ptr [eax]
sub ecx, 4
jne copyloop

// Move object pointer to ECX
mov ecx, obj

// Call function
call [func]

// Restore registers
pop ecx
---> frstor fpuState

// Return value in EAX or EAX:EDX

Share this post

Link to post
Share on other sites
That makes sense.

I'll need to figure out where the stray values in the FPU stack comes from, because I'm quite certain that it's not correct that values are left around there unused. It could be that I need to add some extra instruction in the virtual machine to clean up the stack after floating point instructions.

Thanks a lot for looking into this while I'm away.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!