Is there a way to make a non-inline function inline for a single call?
9 replies to this topic
#1
Posted 26 October 2010 - 10:09 PM
Dave
|
|
|
#2
Posted 26 October 2010 - 10:22 PM
Stupid cheap way:
Just call __inline_blah() that one time. I think that'll work, but don't quote me on it.
inline void __inline_blah()
{
...stuff...
}
void blah()
{
__inline_blah();
}
Just call __inline_blah() that one time. I think that'll work, but don't quote me on it.
sudo rm -rf /
#3
Posted 27 October 2010 - 07:12 AM
>>Is there a way to make a non-inline function inline for a single call?
No -- it's either inline or it isn't. Note that __inline is only a hint to the compiler -- the compiler is free to ignore it if it wishes.
No -- it's either inline or it isn't. Note that __inline is only a hint to the compiler -- the compiler is free to ignore it if it wishes.
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.
#4
Posted 27 October 2010 - 08:12 AM
Microsoft compilers will actually refuse to compile if your program contains the keyword.
sudo rm -rf /
#5
Posted 27 October 2010 - 06:19 PM
#6
Posted 27 October 2010 - 08:57 PM
dargueta said:
Microsoft compilers will actually refuse to compile if your program contains the keyword.
I never had a problem with them -- I have been using M$ compilers since about 1990. You must have done something else that was not legal.
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.
#7
Posted 27 October 2010 - 10:41 PM
A number of years ago, when I was using Visual Studio 2005 (or something along those lines) I tried using those keywords for the first time, and VS barfed on me. It specifically complained that it was deliberately ignoring register and inline. I distinctly remember being pissed.
Whether this is still the case, I don't know. I'll test it on my VM (too lazy to reboot) and see.
Whether this is still the case, I don't know. I'll test it on my VM (too lazy to reboot) and see.
sudo rm -rf /
#8
Posted 28 October 2010 - 02:19 AM
I think that MS compilers are still (silently) ignoring register and inline directives. That is somehow correct, because optimizers have become so good these days that your decision to make something inline or to force some variable to be kept in register looks provisional compared to elaborate analyses performed by the optimizer.
When deciding what will be inline and what will be stored in register, compiler and optimizer must take into account many things, including CPU architecture, observed memory speed, etc. For example, knowing that CPU pipeline is flushed on every falsely predicted branch instruction (because subsequent instructions executions have been started by mistake), then optimizes tend to reorganize code so that pipeline flush has least possible impact.
Now, imagine that you enforce inline and/or register directives - how can you be sure that it will not put optimizer into situation to be unable to increase efficiency of compiled code because of unnatural constraints? As a result of all this, optimizers operate differently on different CPU architectures, when given the same C++ code on input.
On an unrelated note - Microsoft code since many years ago is generally compiled with "optimize for size" switch on.
When deciding what will be inline and what will be stored in register, compiler and optimizer must take into account many things, including CPU architecture, observed memory speed, etc. For example, knowing that CPU pipeline is flushed on every falsely predicted branch instruction (because subsequent instructions executions have been started by mistake), then optimizes tend to reorganize code so that pipeline flush has least possible impact.
Now, imagine that you enforce inline and/or register directives - how can you be sure that it will not put optimizer into situation to be unable to increase efficiency of compiled code because of unnatural constraints? As a result of all this, optimizers operate differently on different CPU architectures, when given the same C++ code on input.
On an unrelated note - Microsoft code since many years ago is generally compiled with "optimize for size" switch on.
#9
Posted 28 October 2010 - 06:42 AM
Saying Microsoft compilers ignore inline keyword is a lot different than saying the compilers refuse to compile the code.
register Keyword (C++)
The inline keyword is somewhat different -- it may or may not be honored, depending on the program
inline, __inline, __forceinline
register Keyword (C++)
Quote
Microsoft Specific
The compiler does not accept user requests for register variables; instead, it makes its own register choices when global register-allocation optimization (/Oe option) is on. However, all other semantics associated with the register keyword are honored.
The compiler does not accept user requests for register variables; instead, it makes its own register choices when global register-allocation optimization (/Oe option) is on. However, all other semantics associated with the register keyword are honored.
The inline keyword is somewhat different -- it may or may not be honored, depending on the program
inline, __inline, __forceinline
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.
#10
Posted 28 October 2010 - 07:52 AM
Seriously, I distinctly remember the compiler crapping out on me, and as soon as I removed inline or register it worked just fine. Maybe it was because I was using a trial version? I really don't know.
sudo rm -rf /
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









