RE: [GD-Windows] VC.NET 'Optimization'
Brought to you by:
vexxed72
From: Mat N. \(BUNGIE\) <mat...@mi...> - 2005-04-12 19:03:05
|
What worries you? The compiler optimizing out essentially dead code, or the optimization pass that destroys trivial profiling code? MSN -----Original Message----- From: gam...@li... [mailto:gam...@li...] On Behalf Of yogiwp Sent: Tuesday, April 12, 2005 11:52 AM To: gam...@li... Subject: Re: [GD-Windows] VC.NET 'Optimization' ----- Original Message -----=20 From: Kent Quirk=20 > fib is declared locally, and no one ever takes its address. The compiler is pretty safe in assuming=20 > that no sane code could possibly affect the value of fib. Similarly, the fibonacci function only=20 > takes a constant argument. If it's in the same source file, it might even know that the function has=20 > no aliasing issues. Consequently, it's reasonable to optimize away the creation of the fib variable=20 > and simply embed the function call in the printf call. >=20 > My guess is that what the compiler did was optimize this to: >=20 > ---------------------------------------------------- > timer.Restart(); > printf( "time=3D%f, result=3D%d\n", timer.GetElapsed(), = fibonacci(42) ); > ---------------------------------------------------- Yes, this is exactly what happened (disassembly below). Sigh. I must say that this makes my worry. Btw, #pragma optimize("a",off) and/or ("w",off) have no effect; it's still generating the exact same code. Declaring msTime as 'volatile' does fix it. ------------------------------------------------------------------------ ------- ; 5215 : timer.Restart(); lea ecx, DWORD PTR _timer$[esp+148] call ?Restart@CRealTimer@Torture@@QAEXXZ ; Torture::CRealTimer::Restart ; 5216 : int fib =3D fibonacci( 42 ); ; 5217 : float msTime =3D timer.GetElapsed(); lea ecx, DWORD PTR _timer$[esp+148] call ?GetElapsed@CRealTimer@Torture@@QAEMXZ ; Torture::CRealTimer::GetElapsed push 41 ; 00000029H call ?fibonacci@@YAHH@Z ; fibonacci push 40 ; 00000028H mov edx, eax call ?fibonacci@@YAHH@Z ; fibonacci add esp, 8 add edx, eax ; 5218 : printf( "msTime=3D%f, result=3D%d\n", msTime, fib ); push edx sub esp, 8 fstp QWORD PTR [esp] push OFFSET FLAT:??_C@_0BG@BEAEGCGA@msTime?$DN?$CFf?0?5result?$DN?$CFd?6?$AA@ call _printf add esp, 16 ; 00000010H ------------------------------------------------------------------------ ------- (There are 2 fibonacci() calls because of inlining -- fibonacci() is a recursive function calling itself twice.) Yogi Wahyu Prasidha ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=3D6595&alloc_id=3D14396&op=3Dclick _______________________________________________ Gamedevlists-windows mailing list Gam...@li... https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=3D555 |