Skip to main content
GameDev.net gamedev.net
🔒 Locked

When does the combiler optimize?

Started by Craazer Jan 28, 2003 at 4:09 PM 12 replies 850+ views
Original Post
Craazer
Craazer
If u use register or inline for example these are just suggestions to combiler, am I right? So can u know when combiler does the trick? Just curius..
Tazel
Tazel
Do you mean "compiler"?



tcache
Contact Me
-----------
AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
JoeyBlow2
JoeyBlow2
The "combiler" will do exactly what you tell it to do...

register is telling the "combiler" to mark a variable as cacheable to the CPU... Now, when the program is run the CPU might not cache it... If it does not have room in the cache to store the variable, it will just place it into system memory... However, the "combiler" will mark it cacheable no matter what, its just up the CPU to listen.

inline is telling the "combiler" to place the contents of a function into the place where the function is called... That kinda sounds like the "combiler" is changing your code. The "combiler" does not change your code, only the .obj files it generates while its being "combiled." To the programmer, it looks like any other function with just "inline" in front.. An inline function removes the overhead of allocating/deallocating of stack space and because of that inline functions runs faster. Small functions should always be inlined. The "combiler" will optimize small functions in release mode and automatically generate them as inline. However, it might not (depending on the quality of the optimizer), thats why you should specifically mark small (with no/low variables) functions as inline...


[edited by - JoeyBlow2 on January 28, 2003 6:11:08 PM]
Wyrframe
Wyrframe
Some compilers take them as commands.
Some compilers take them as suggestions.
Some compilers ignore you, and work out what is best on their own.

For example, Microsoft''s CL (the VC++ compiler) ignores the "register" tag completely, and will optimize this sort of thing as it sees fit. However, it will not do any inlining without your say-so, although you do have to use "__inline" instead... "inline" is ignored, and considered "antiquated" (*spits* But it should be accepted for effing compatibility).

I don''t know for any other compilers, though. Read ''em up.
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
Bullmax
Bullmax
huh.... I knew that "inline" could be ignored, but I did not know that "__inline" could overide the compiler monopoly. Altought, can it be dangerous to use it if the function is too big or complicated ?



/* Bullmax */
-------------
Reality has many forms : good and evil, black and white, yin and yang.
/ Bullmax /-------------Reality has many forms : good and evil, black and white, yin and yang.
Zipster
Zipster
Yeah, in the MSVC project setttings for Inline Function Expansion, you have "Disable*", "Only __inline", and "Any Suitable".
CWizard
CWizard
quote:
Original post by JoeyBlow2
register is telling the "combiler" to mark a variable as cacheable to the CPU... Now, when the program is run the CPU might not cache it... If it does not have room in the cache to store the variable, it will just place it into system memory... However, the "combiler" will mark it cacheable no matter what, its just up the CPU to listen.
Unless I''m totally off with new systems, that''s not what''s going on. register marks a variable to be stored in a CPU register (eax, edx, etc.) rather than in memory; it has nothing to do with cache. I needs to be desided on when the compilation takes place, as it will generate different machine code.

Methods for marking instructions (or any memory) as cachable or uncachable, while possible with some processors, is AFAIK not implemented in standard C++. Some compilers might do such things on volatile variables on some platforms, but I doubt it.


Craazer
Craazer
quote:
Original post by Tazel
Do you mean "comp iler"?



tcache
Contact Me
-----------
AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)


Oh yes sorry my bad english.
Craazer
Craazer
Actualy I knew what they are, but the queston is when do I know WHEN does the compiler optimize?

I mean can u see it in some log or shometing? Im using visual studio.
CWizard
CWizard
quote:
Original post by Craazer
Actualy I knew what they are, but the queston is when do I know WHEN does the compiler optimize?
You usually can not; they are only suggestions to the compiler.
quote:
I mean can u see it in some log or shometing? Im using visual studio.
Check the assembly . You can make VC++ output the assembly to a file when assembling: Go to the Project | Settings menu and click C/C++ tab. Choose Listing files under category dropdown and one of the assembly options in the Listing file type dropdown.


Craazer
Craazer
quote:
Original post by CWizard
[quote]Original post by Craazer
Actualy I knew what they are, but the queston is when do I know WHEN does the compiler optimize?
You usually can not; they are only suggestions to the compiler.
quote:
I mean can u see it in some log or shometing? Im using visual studio.
Check the assembly . You can make VC++ output the assembly to a file when assembling: Go to the Project | Settings menu and click C/C++ tab. Choose Listing files under category dropdown and one of the assembly options in the Listing file type dropdown.




Ookey, thanks.
Even I was hoping something cool.
Well I learnd new things about register and inline though, so thanks to all!

Topic Locked

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

Sign in to reply to this topic.