tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: KNF and the C preprocessor



On Mon, Dec 10, 2012 at 09:55:14PM +0000, Paul_Koning%Dell.com@localhost wrote:
> > 
> > The compiler has some heuristics about what it is good to inline.
> > gcc tends to treat 'inline' as just a hint.
> 
> I wouldn't describe it that way.  And I don't think the GCC
> documentation does.  It does talk about heuristic inlining,
> but that's for the -O3 feature of inlining stuff that's *not* marked,
> based on heuristics that it might be useful.
> > 
> > Genarally it likes inlining static functions that are only called once.
> > But it doesn't always do so - even when marked 'inline'
> > (marking them inline may have no effect).
> 
> There are switches that control what gets inlined.  In particular,
> there is one that says not to inline things (other than called-once things)
> that are bigger than X.  If things are not getting inlined when expected,
> that is one possible cause.

I was having issues with static functions that are only called once.
They are quite large (not large for a function) but adding a couple
of 'boring' lines of code stopped them being inlined, and also
stopped some 1 line functions being inlined.
Marking everything with __attribute__((always_inline)) fixed it.

That particular code (part of an embedded system) has to have everything
inlined - any register spills to stack make it too slow.
I almosted hacked gcc enough to remove the function prologue (which
saves some registers on stack even though the function can't return)
so that I could use %sp as a general purpose register!
There are a couple of other candidate registers that never used
(It is MIPS like, and %r1 is reserved for assembler macros of which
there are exactly none, the only interrupts are fatal so the interrupt
%pc save (and debug %pc save) are also unused.)

        David

-- 
David Laight: david%l8s.co.uk@localhost


Home | Main Index | Thread Index | Old Index