[Bug target/28894] Optimizaition on AVR target breaks code.
eweddington at cso dot atmel dot com
Wed Aug 30 15:06:00 GMT 2006
------- Comment #3 from eweddington at cso dot atmel dot com 2006-08-30 15:06 -------
The AVR does not have an Add Immediate instruction (addi), so this is normally
done using sbi with a negative number as Andrew correctly points out.
In Ralf's unoptimized output, it correctly shows a -2 (0xFE):
41e: 89 81 ldd r24, Y+1 ; 0x01
420: 8e 5f subi r24, 0xFE ; 254
The optimized output shows a -6 (0xFA)
264: 8a 5f subi r24, 0xFA ; 250
Why is this? Well, the optimizer aggressively optimizes loops that do nothing,
like the code is here:
while( i<245 );
Note that you only have 'i' declared as unsigned char.
The first FAQ entry in the avr-libc user manual talks about using the keyword
If you define 'i' as volatile unsigned char, then the optimizer will not
agressively optimize your "do-nothing" loop. In fact, if you are trying to
achieve a delay using a "do-nothing" loop, then you are strongly suggested to
use the <util/delay.h> header that comes with avr-libc, which are "busy-wait
Please close this bug as invalid.
More information about the Gcc-bugs