[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] not optimal code generation (avr-gcc 3.4.3 -Os)
From: |
Christof Krueger |
Subject: |
[avr-gcc-list] not optimal code generation (avr-gcc 3.4.3 -Os) |
Date: |
Wed, 23 Feb 2005 14:06:19 +0100 |
User-agent: |
Mozilla Thunderbird 1.0 (X11/20050116) |
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?
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?
Thank you,
Christof Krueger
$ avr-gcc -v
Reading specs from /usr/lib/gcc/avr/3.4.3/specs
Configured with: ./configure -v --enable-languages=c,c++ --prefix=/usr
--infodir=/usr/share/info --mandir=/usr/share/man --enable-shared
--with-system-zlib --enable-long-long --enable-nls
--without-included-gettext --disable-checking --build=i386-linux
--host=i386-linux --target=avr
Thread model: single
gcc version 3.4.3
- [avr-gcc-list] not optimal code generation (avr-gcc 3.4.3 -Os),
Christof Krueger <=