avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] not optimal code generation (avr-gcc 3.4.3 -Os)


From: E. Weddington
Subject: Re: [avr-gcc-list] not optimal code generation (avr-gcc 3.4.3 -Os)
Date: Wed, 23 Feb 2005 09:29:51 -0700
User-agent: Mozilla Thunderbird 0.7.3 (Windows/20040803)

Christof Krueger wrote:

Hello,

when compiling the following code I get not optimal code:

--------------------------------------
#include <avr/io.h>

int
main(void)
{
  volatile uint8_t foo=3;
  uint16_t bar;

  bar = (uint8_t)(64+foo)<<8; // *

  return bar;
}
--------------------------------------

As you can see, I want to set the upper byte of bar using foo which can change before the line in question (marked with a *).

Compiling with
avr-gcc main.c -mmcu=atmega162 -Wa,-adhlns=main.lst -Os
yields following asm code:

  20 0008 83E0          ldi r24,lo8(3)
  21 000a 8983          std Y+1,r24
  22 000c 8981          ldd r24,Y+1
  23 000e 805C          subi r24,lo8(-(64))
  24 0010 9927          clr r25
  25 0012 982F          mov r25,r24
  26 0014 8827          clr r24

Why is r25 cleared just before moving r24 to r25 and is there a way to change my example code in a way that avr-gcc will not produce redundant code?

Hmm. Good question....

I would suggest filling out a bug report on the GCC project on this. Be sure to put "avr" in the "target" field of the bug report and mention "missed optimization".


Another question:
When accessing (uint8_t)(variable>>8) avr-gcc produces

 420 018e 8091 0000     lds r24,variable
 421 0192 9091 0000     lds r25,(variable)+1
 422 0196 892F          mov r24,r25
 423 0198 9927          clr r25

which could also be written as

 lds r24,(variable)+1
 clr r25

Is there a way to force this code without using inline asm?


You didn't say what type "variable" was before this operation.....

Eric




reply via email to

[Prev in Thread] Current Thread [Next in Thread]