[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] Avr-gcc Produces Incorrect Code with -Os
From: |
Thomas D. Dean |
Subject: |
[avr-gcc-list] Avr-gcc Produces Incorrect Code with -Os |
Date: |
Thu, 15 May 2008 08:12:41 -0700 (PDT) |
I have a code segment which
1. sets a bit in PORTA.
2. calls atan2.
3. clears the same bit in PORTA.
The compiler produces code that
1. sets the bit in PORTA.
2. clears the same bit in PORT.
3. calls atan2.
With -O0, the code is correct.
# uname -a
FreeBSD dv6000.tddhome 7.0-STABLE FreeBSD 7.0-STABLE #0: Sun May 4 07:58:25
PDT 2008 address@hidden:/usr/src/sys/GENERIC i386
# avr-gcc --version
avr-gcc (GCC) 4.2.2
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
The code fragment,
...
dtostrf(cos_rad,6,3,&line4[14]);
line3[20] = ' ';
line4[20] = ' ';
TRACE_ON(TRACE4); // portb |= _bv(04)
atan_rad = atan2(cos_rad,sin_rad);
TRACE_OFF(TRACE4); // portb &= ~_bv(04)
dtostrf(atan_rad,6,3,&line4[26]);
...
# gmake ATMEGA16=1 TRACE=1 8_BIT=1 clean all
rm -f *.o *.elf *.s19 *.b *.a *.map *.hex
avr-gcc -mmcu=atmega16 -Wall -Wmissing-prototypes -Os -DTRACE -DLCD_8_BIT
-I. -c -o main.o main.c
avr-gcc -mmcu=atmega16 -Wall -Wmissing-prototypes -Os -DTRACE -DLCD_8_BIT
-I. -c -o timer.o ../common/timer.c
avr-gcc -mmcu=atmega16 -Wall -Wmissing-prototypes -Os -DTRACE -DLCD_8_BIT
-I. -c -o lcd-8-bit.o ../common/lcd-8-bit.c
avr-gcc -o main.elf main.o timer.o lcd-8-bit.o -mmcu=atmega16
-L../../../asus-avr-1.0/config/stk500 -L../../../asus-avr-1.0/lib
-L/usr/local/avr/lib/ -lasus -lc -lm -lprintf_flt -lscanf_flt
avr-objcopy -j .text -j .data -O ihex main.elf main.hex
# avr-objdump -D main.elf | grep 'call.*atan2' -B12 -A10
398: 0e 94 71 03 call 0x6e2 ; 0x6e2 <dtostrf>
39c: 80 e2 ldi r24, 0x20 ; 32
39e: f1 01 movw r30, r2
3a0: 84 8b std Z+20, r24 ; 0x14
3a2: f2 01 movw r30, r4
3a4: 84 8b std Z+20, r24 ; 0x14
3a6: dc 9a sbi 0x1b, 4 ; 27
3a8: dc 98 cbi 0x1b, 4 ; 27
3aa: a5 01 movw r20, r10
3ac: 94 01 movw r18, r8
3ae: c7 01 movw r24, r14
3b0: b6 01 movw r22, r12
3b2: 0e 94 0f 06 call 0xc1e ; 0xc1e <atan2>
3b6: cf 54 subi r28, 0x4F ; 79
3b8: df 4f sbci r29, 0xFF ; 255
3ba: 08 81 ld r16, Y
3bc: 19 81 ldd r17, Y+1 ; 0x01
3be: c1 5b subi r28, 0xB1 ; 177
3c0: d0 40 sbci r29, 0x00 ; 0
3c2: 23 e0 ldi r18, 0x03 ; 3
3c4: 46 e0 ldi r20, 0x06 ; 6
3c6: 0e 94 71 03 call 0x6e2 ; 0x6e2 <dtostrf>
3ca: b1 01 movw r22, r2
- [avr-gcc-list] Avr-gcc Produces Incorrect Code with -Os,
Thomas D. Dean <=
- Re: [avr-gcc-list] Avr-gcc Produces Incorrect Code with -Os, Dave N6NZ, 2008/05/15
- Re: [avr-gcc-list] Avr-gcc Produces Incorrect Code with -Os, Thomas D. Dean, 2008/05/15
- Re: [avr-gcc-list] Avr-gcc Produces Incorrect Code with -Os, David Brown, 2008/05/16
- RE: [avr-gcc-list] Avr-gcc Produces Incorrect Code with -Os, Loveny Design, 2008/05/16
- Re: [avr-gcc-list] Avr-gcc Produces Incorrect Code with -Os, Alex Wenger, 2008/05/16
- Re: [avr-gcc-list] Avr-gcc Produces Incorrect Code with -Os, Paulo Marques, 2008/05/16
- Re: [avr-gcc-list] Avr-gcc Produces Incorrect Code with -Os, Mark Litwack, 2008/05/16
- RE: [avr-gcc-list] Avr-gcc Produces Incorrect Code with -Os, Weddington, Eric, 2008/05/16
- Re: [avr-gcc-list] Avr-gcc Produces Incorrect Code with -Os, Mark Litwack, 2008/05/16
- RE: [avr-gcc-list] Avr-gcc Produces Incorrect Code with -Os, Weddington, Eric, 2008/05/16