here's the c++ code
u32 Log2( float _f ) { #ifdef XTM_MACOSX return ilogbf( _f ); #else const float b = 1.4426950f; // this is 1.0f / log( 2.0f ); float r = log( _f ) * b; return ((u32)r); #endif }
Here's the debug asm
?Log2@xtm@@YAKM@Z PROC ; xtm::Log2; 28 : { push ebp mov ebp, esp sub esp, 24 ; 00000018H mov eax, -858993460 ; ccccccccH mov DWORD PTR [ebp-24], eax mov DWORD PTR [ebp-20], eax mov DWORD PTR [ebp-16], eax mov DWORD PTR [ebp-12], eax mov DWORD PTR [ebp-8], eax mov DWORD PTR [ebp-4], eax; 29 : #ifdef XTM_MACOSX; 30 : return ilogbf( _f );; 31 : #else; 32 : //TODO bug inconsistent calculation between release & debug ( IEEE Strict & fast floating point ? examine asm ); 33 : ; 34 : //return log( _f ) / log( 2.0f );; 35 : const float b = 1.4426950f; // 1.0f / log( 2.0f ); movss xmm0, DWORD PTR __real@3fb8aa3b movss DWORD PTR _b$[ebp], xmm0; 36 : float r = log( _f ) * b; push ecx movss xmm0, DWORD PTR __f$[ebp] movss DWORD PTR [esp], xmm0 call ?log@@YAMM@Z ; log add esp, 4 fmul DWORD PTR _b$[ebp] fstp DWORD PTR _r$[ebp]; 37 : //printf( "log(%f) = %f (%u)\n", _f, r, (u32)r );; 38 : return ((u32)r); fld DWORD PTR _r$[ebp] fnstcw WORD PTR tv74[ebp] movzx eax, WORD PTR tv74[ebp] or eax, 3072 ; 00000c00H mov DWORD PTR tv77[ebp], eax fldcw WORD PTR tv77[ebp] fistp QWORD PTR tv79[ebp] fldcw WORD PTR tv74[ebp] mov eax, DWORD PTR tv79[ebp]; 39 : #endif; 40 : } add esp, 24 ; 00000018H cmp ebp, esp call __RTC_CheckEsp mov esp, ebp pop ebp ret 0
And the release asm:
?Log2@xtm@@YAKM@Z PROC ; xtm::Log2; 28 : { push ebp mov ebp, esp sub esp, 8; 29 : #ifdef XTM_MACOSX; 30 : return ilogbf( _f );; 31 : #else; 32 : //TODO bug inconsistent calculation between release & debug ( IEEE Strict & fast floating point ? examine asm ); 33 : ; 34 : //return log( _f ) / log( 2.0f );; 35 : const float b = 1.4426950f; // 1.0f / log( 2.0f );; 36 : float r = log( _f ) * b;; 37 : //printf( "log(%f) = %f (%u)\n", _f, r, (u32)r );; 38 : return ((u32)r); fld DWORD PTR __f$[ebp] fldln2 fxch ST(1) fnstcw WORD PTR tv78[ebp] fyl2x movzx eax, WORD PTR tv78[ebp] or eax, 3072 ; 00000c00H mov DWORD PTR tv80[ebp], eax fmul DWORD PTR __real@3fb8aa3b fldcw WORD PTR tv80[ebp] fistp QWORD PTR tv64[ebp] mov eax, DWORD PTR tv64[ebp] fldcw WORD PTR tv78[ebp]; 39 : #endif; 40 : } mov esp, ebp pop ebp ret 0
In debug Log2( 1024.0f ) returns 9 and in release 10
I'm compiling under VS2010 with the following settings:
Debug Release
Optim Disabled Full
Enable Intrinsic Functions No Yes
Enable Ehanced Instr. set SSE2 SSE2
Floating point model Fast Fast
Floating Point Exceptions No No
Can you see what's wrong here ? I would greatly appreciate any help with this issue