When does the combiler optimize?

Started by
12 comments, last by Craazer 21 years, 2 months ago
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..
Advertisement
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)
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]
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.
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.
Yeah, in the MSVC project setttings for Inline Function Expansion, you have "Disable*", "Only __inline", and "Any Suitable".
see middle of my post
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.

If my compiler actually <b>comb</b>iled, there would be no need for a deb<b>o</b>gger. No offense.
The keywords "register" and "inline" are only suggestions to most compilers that you wish for certain optimizations to happen. The choice over these is usually down to the compiler.
The inline keyword means that the compiler would eliminate the overhead of calling the function by placing the functions code directly into the calling function, increasing speed but increasing the executable size at the same time. The compiler is free to ignore the inline keyword, as certain functions cannot be inlined, namely recursive functions. __forceinline is defined by Visual C++ to always force the function to be inlined, however I''m not sure what would happen if you did this to a recrusive function (try it). Any function defined within the definition of a class/struct "getbleh() { bleh = 1; }" is normally inlined by the compiler, though i''m not sure on the standards on this subject.
The register keywords means the compiler registers (eax, ebx, ecx, edx). The compiler has no control over the cache, however it does behind the scene use these for any variables used a lot (like loop variables). Once again it is only asking the compiler to use one of the CPU registers.

NB: inline functions can lead to rather large executables if used to often, so don''t inline everything. Large executables take more memory to store in the CPU, which means less space for holding any data that your executable wishs to use.

- Kehoeshi

This topic is closed to new replies.

Advertisement