Skip to main content
gamedev.net
🔒 Locked

Visual C++ Optimizations

Started by MatuX 2 replies 500+ views
Original Post
MatuX
MatuX
Hey, I''ve a question about VC++ compiler optimizations. First at all, my assembler knowledge is almost null so that''s why I can''t check this out by myself using the IDE''s dissasembly, I promise I will learn! But in the meantime, can anybody answer my small question? First, shiftings. If I have a #define NUMBER 64 or const int NUMBER = 64; and I do int anewnum = 5 * NUMBER; Does the compiler optimize the equation as if I would write 5 << 6? And what about int anewnum = NUMBER * 5; ? That''s all! BTW, is there a place where I can see the compiler behavior when optimizing for speed? It would be interesting to watch differences between VC++, BC++ and GCC. Thanks all.
Sneftel
Sneftel
If you compile the code as shown, neither will be the case; the compiler will realize that that statement always results in 320, and simply assign 320 to anewnum.

In the more general case, however, yes, you can expect the compiler to use the most efficient opcode for your case.

As for looking at the differences, I suggest simply looking at the assember output in the debugger.



Don''t listen to me. I''ve had too much coffee.
MatuX
MatuX
Thanks for the answer!

And yes, when I say 5, I mean a variable, eg: int anewnum = x * NUMBER;

I will try and check the asm output, I know SHL and SHR are the shifts so I may understand something

Umm... What about:

float anewnum = static_cast[float](x * NUMBER);

Is the compiler smart enough to first do the shifting and then the cast or it behaves completely differently?

Anyway, I'll just dissasemble and try seeing it by myself.

[edited by - MatuX on July 28, 2002 1:17:10 PM]
MatuX
MatuX
Ah.. it optimizes the cast, too

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.