
Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [tlug] A semi-related question
>>>>> "Josh" == Josh Glover <jmglov@example.com> writes:
Josh> I think that you are right about g++, but not about gcc. I
Josh> think gcc always honours "inline" when you turn on
Josh> optimisation: [cites gcc manual]
Nope. That's what -Winline is for, to let you know when GCC can't
hack inlining something.
Josh> On 4/22/05, Kenneth <emry@example.com> wrote:
>> I don't use inline much personaly anyway. Then again my current
>> programming skill is very minimal. ^^;
Josh> In general, this is the correct approach. In all but the
Josh> most extreme cases, the compiler knows better than you when
Josh> something should be inlined.
I believe on some systems the inline keyword causes the compiler to
emit meta information that permits the linker to do inlining. (I
don't know if any of them are actually in production, though.)
Josh> Of course, when you do a lot of systems programming, over
Josh> time, you encounter a lot of the corner cases where inlining
Josh> something can make your subsystem an order of magnitude
Josh> faster, but the compiler does not realise it. *That* is when
Josh> you use the inline keyword.
Unfortunately, it's generally not true that the compiler can hack
inlining stuff that's complicated enough that it can't figure out that
function call overhead is too high. For example, I once found a
speedup that was of the form
void /* this is crucial, of course */
dumbfunc (arg)
{
if (global_flag)
{
/* 100 lines of hairy expensive code including function calls */
}
and I won big with
#define dumbfunc(arg) do { if (global_flag) smartfunc (arg); } while (0)
void
smartfunc (arg)
{
/* 100 lines of hairy expensive code including function calls */
}
I don't think there are any production compilers smart enough to move
code out of a function like that.
--
School of Systems and Information Engineering http://turnbull.sk.tsukuba.ac.jp
University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
Ask not how you can "do" free software business;
ask what your business can "do for" free software.
Home |
Main Index |
Thread Index