On 7/8/07, Bevan Weiss <[email protected]> wrote:
Steve Underwood wrote:
> Bevan Weiss wrote:
>> eg (from the listing file)
>> inline void IRBoostOn( void )
>> {
>> f9ca: 05 12 push r5 ;
>> f9cc: 04 12 push r4 ;
>> P1OUT |= LT1930_ON;
>> f9ce: e2 d2 21 00 bis.b #4, &0x0021 ;r2 As==10
>> }
>> f9d2: 34 41 pop r4 ;
>> f9d4: 35 41 pop r5 ;
>> f9d6: 30 41 ret
>>
>> Can't the compiler see that r4 and r5 just aren't required in this
>> function and so suppress the generation of the pushes?
I tried this quickly, and any level of optimization other than -O0
eliminated the pushes and pops. I've found -O2 is usually the best choice,
often creating code that is smaller than -Os.
Using the naked attribute removes the
push/pop combo, but also removes the return instruction. I thought
naked only removed prologue/epilogue and that this didn't include the
subroutine return instruction... am I mistaken on this?
I'm not sure about naked, but an inline function doesn't need to return. If
the "IRBoostOn()" exists in your elf file, then it's either never being used
inline, or is being linked to allow it to be used non-inline.
To have a function be only used inline, declare it "static inline". If it
needs to be accessed from several .c files, put its definition (not just
declaration) in a header file. This way, the compiler can do the inlining
in each .c file.
The linker is unable to make functions inline, so any calls to a non-static
inline function will be a regular function call, unless the non-static
inline function is defined in the same .c file as the caller.
Neil