Hi

Would it be possible for someone to compile the following function with the
gcc compiler, at it;s highest level of optimization, and post the
disassembled output. I'd like to compare code produced by codewarrior, and
that produced by the gcc compiler.

This function..
unsigned int test(unsigned int a)
{
 unsigned int z;
 z=(a<<6)+(a<<5);
 return z;
}

produced this code with Codewarrior, at optimization level 4

 link      a6,#0
 move.w    8(a6),d0
 lsl.w     #5,d0
 move.w    8(a6),d1
 lsl.w     #6,d1
 add.w     d0,d1
 move.w    d1,d0
 unlk      a6
 rts

wouldn't it be more efficient to copy the first parameter from the stack
into d0, and then copy d0->d1, instead of re-copying
the parameter off the stack into d1


link      a6,#0
move.w    8(a6),d0
move.w    d0,d1        // changed code
lsl.w     #5,d0
lsl.w     #6,d1
add.w     d0,d1
move.w    d1,d0
unlk      a6
rts

as a last optimization, instead of  add.w d0,d1 couldn't we do add.w d1,d0,
then the return value would already be in the correct register.

Lastly, if my assumptions about the above optimizations are correct, is this
a sign of an inefficient compiler, or is it impossible to get a compiler to
remove the inefficiencies pointed out?

Garth Watkins


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to