public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* avr compilation
@ 2011-03-18  8:48 Paulo J. Matos
  2011-03-18 10:08 ` WANG.Jiong
  2011-03-18 13:26 ` Georg-Johann Lay
  0 siblings, 2 replies; 9+ messages in thread
From: Paulo J. Matos @ 2011-03-18  8:48 UTC (permalink / raw)
  To: gcc

Hi all,

I am looking at the avr backend in order to try to sort some things out 
on my own backend.

One of the tests I am doing is by compiling the following:
int x = 0x1010;
int y = 0x0101;

int add(void)
{
   return x+y;
}

It compiles to (in gcc-4.3.5_avr with -Os)
add:
/* prologue: function */
/* frame size = 0 */
         lds r18,y
         lds r19,(y)+1
         lds r24,x
         lds r25,(x)+1
         add r18,r24
         adc r19,r25
         mov r24,r18
         mov r25,r19
/* epilogue start */
         ret

I don't know much avr assembler so bear with me but I would expect this 
to be written:
add:
/* prologue: function */
/* frame size = 0 */
         lds r18,y
         lds r19,(y)+1
         lds r24,x
         lds r25,(x)+1
         add r24,r18
         adc r25,r19
/* epilogue start */
         ret

By inverting the add arguments we save two mov instructions.

If it can be written like this any ideas on why GCC is avoiding it?

Cheers,

--
PMatos

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-03-18 14:50 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-18  8:48 avr compilation Paulo J. Matos
2011-03-18 10:08 ` WANG.Jiong
2011-03-18 10:15   ` Paulo J. Matos
2011-03-18 12:11     ` David Brown
2011-03-18 13:37       ` Paulo J. Matos
2011-03-18 13:26 ` Georg-Johann Lay
2011-03-18 13:40   ` Paulo J. Matos
2011-03-18 14:20     ` Ian Lance Taylor
2011-03-18 14:50       ` Paulo J. Matos

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).