Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

MatuX

Visual C++ Optimizations

This topic is 5903 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

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!