J
janus
Hello All,
Could someone explain "inline" for me?
Janus
Could someone explain "inline" for me?
Janus
janus said:Could someone explain "inline" for me?
Making a function an inline function suggests that
calls to the function be as fast as possible.
Tom St Denis said:Not quite. "inline" hints to the compiler to place the function *in-
line* with the caller, thus REMOVING the call altogether.
It's a
redundant keyword nowadays as most compilers will automatically inline
things when its useful.
Hello All,
Could someone explain "inline" for me?
Janus
Incorrect.
It hints to replace the call. Not inline *with* it.
There's nothing wrong with quoting the standard which is what Stefan
Ram did. One can imagine an architecture with executable "code
registers" where there might be a faster method than conventional
in-lining so the standard is wise to avoid saying what inline must
actually do.
Even then it is not quite redundant in that the compiler can diagnose
constraints when the function is marked as inline.
jacob said:janus a écrit :
The "inline" directive slows down a program by bloating its code. With
today's CPUs programs go so fast that you can't see the bugs.
To avoid that, you slow down your program using the "inline" directive.
This directive tells the compiler to replace a call to a function
with an insertion of the function's body at each call site.
This bloats the code in most cases. The bloated code slows down the
program that has to load more code into the cache from main memory.
Since most system busses go at 333MHZ or 666 MHZ at most, a CPU at
3GHZ must inserty wait states to wait until the RAM gives it the
new instructions to execute.
Tom said:I'm saying that in most modern compilers you will get function
inlining whether you use the keyword or not. So it's largely
academic.
It's like saying "auto" on stack variables...
jacob said:janus a écrit :
The "inline" directive slows down a program by bloating its code. With
today's CPUs programs go so fast that you can't see the bugs.
To avoid that, you slow down your program using the "inline" directive.
This directive tells the compiler to replace a call to a function
with an insertion of the function's body at each call site.
This bloats the code in most cases. The bloated code slows down the
program that has to load more code into the cache from main memory.
Since most system busses go at 333MHZ or 666 MHZ at most, a CPU at
3GHZ must inserty wait states to wait until the RAM gives it the
new instructions to execute.
If you want to make your program faster, avoid inline. Remember that
a call instruction is very small, and can be predicted in MOST cases
(unless it is a cal through a function pointer). This means that the
pipeline will keep full, and more code will fit in the code caches,
making the program go faster.
jacob navia said:janus a écrit :
The "inline" directive slows down a program by bloating its code. With
today's CPUs programs go so fast that you can't see the bugs.
To avoid that, you slow down your program using the "inline" directive.
This directive tells the compiler to replace a call to a function
with an insertion of the function's body at each call site.
This bloats the code in most cases. The bloated code slows down the
program that has to load more code into the cache from main memory.
Since most system busses go at 333MHZ or 666 MHZ at most, a CPU at
3GHZ must inserty wait states to wait until the RAM gives it the
new instructions to execute.
If you want to make your program faster, avoid inline. Remember that
a call instruction is very small, and can be predicted in MOST cases
(unless it is a cal through a function pointer). This means that the
pipeline will keep full, and more code will fit in the code caches,
making the program go faster.
This runs counter to my experience. Maybe you can give an example
where inlining slows down the code. I'd like to see what sort of code
leads you to this conclusion.
Antoninus Twink said:I'd also be interested to hear this - my exprience accords with yours,
Ben. (Obviously inlining code will make the executable bigger, but it's
been a long time since disk space for binaries, or RAM to load them, was
an issue.)
Making a function an inline function suggests that
calls to the function be as fast as possible.
Not quite. [...]
janus a écrit :
The "inline" directive slows down a program by bloating its code. With
today's CPUs programs go so fast that you can't see the bugs.
To avoid that, you slow down your program using the "inline" directive.
This directive tells the compiler to replace a call to a function
with an insertion of the function's body at each call site.
This bloats the code in most cases.
The bloated code slows down the program that has to load more code into the
cache from main memory.
If you want to make your program faster, avoid inline. Remember that
a call instruction is very small
and can be predicted in MOST cases
(unless it is a cal through a function pointer).
This means that the
pipeline will keep full
jacob navia said:janus a écrit :
The "inline" directive slows down a program by bloating its code. With
today's CPUs programs go so fast that you can't see the bugs.
To avoid that, you slow down your program using the "inline" directive.
This directive tells the compiler to replace a call to a function
with an insertion of the function's body at each call site.
This bloats the code in most cases. The bloated code slows down the
program that has to load more code into the cache from main memory.
Since most system busses go at 333MHZ or 666 MHZ at most, a CPU at
3GHZ must inserty wait states to wait until the RAM gives it the
new instructions to execute.
If you want to make your program faster, avoid inline. Remember that
a call instruction is very small, and can be predicted in MOST cases
(unless it is a cal through a function pointer). This means that the
pipeline will keep full, and more code will fit in the code caches,
making the program go faster.
Well, it /is/ an issue (regarding speed) whether the code
will fit into the processor cache or not.
Antoninus Twink said:I'd also be interested to hear this - my exprience accords with yours,
Ben. (Obviously inlining code will make the executable bigger, but it's
been a long time since disk space for binaries, or RAM to load them, was
an issue.)
On the other hand, I am a firm believer that loop unrolling can cause
the problems Jacob mentions, and for the reasons he describes. I suspect
that this is why (emprically) gcc's -O3 is almost always slower than
-O2.
I'd also be interested to hear this - my exprience accords with yours,
Ben. (Obviously inlining code will make the executable bigger, but it's
been a long time since disk space for binaries, or RAM to load them, was
an issue.)
Ian Collins said:I don't have a figure for the ratio of embedded devices to desktops
and servers, but I'm sure it's high enough to invalidate that
statement.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.