Steve Underwood wrote:
Bevan Weiss wrote:
Hi Guys,
I've hit the code size limits for my particular device (a small
MSP430F2003) and so have started to look into the generated assembly
code to see what improvements can be made to it by hand. It seems
there's quite a few sections of code which are non-optimally generated
by the compiler.. Just wondering if anyone has a solution to improve
these without hand editing the assembly file (or using inline assembly).
One thing that I've noticed is that r4 and r5 are always pushed and
popped, regardless of whether or not they're used.. I like to use small
enabling and disabling functions (to turn on or off particular outputs)
however the overhead this seems to generate isn't working too well.
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?
The other one is with boolean negation.. I don't have a listing example
of it, as I've just fixed up all the code sections with it in, however
it was quite horrible. It was something like 4 or so instructions just
to invert the boolean value.
Is there anyone out there that could direct me to the compiler internals
responsible for these kind of optimizations so that I can contribute to
the compiler development?
Did you use -O2? You shouldn't get so much waste if you do.
Steve
Hi Steve,
I'm currently using -Os as there's really not much FLASH on the 2003
(1KB just doesn't go that far).
I would have thought things like boolean negations would be almost like
an atomic thing that couldn't get optimized any further.
I must say I expected the push/pops to be slightly more optimized (I
believe I was in -O0 mode at that time), as really that's not strictly
code optimization. It doesn't impact on my code at all whether or not
the compiler inserts needless push/pops, and if anything moves it away
from the intent of my code. 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?
Bevan