[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] [Bug] Initialization for _delay_loop_2 OptimizedOut
From: |
Bjarne Laursen |
Subject: |
[avr-gcc-list] [Bug] Initialization for _delay_loop_2 OptimizedOut |
Date: |
Thu, 11 Sep 2003 10:16:07 +0200 |
I have seen this problem too. The intialization of the counter register is
not present when using the original code:
/* 16-bit count, 4 cycles/loop */
static inline void
_delay_loop_2(unsigned int __count)
{
asm volatile (
"1: sbiw %0,1" "\n\t"
"brne 1b"
: "=w" (__count)
: "0" (__count)
);
}
However, if you change the function to:
/* 16-bit count, 4 cycles/loop */
static inline void
Mydelay_loop_2(unsigned int __count)
{
asm volatile (
"1: sbiw %0,1" "\n\t"
"brne 1b"
:
: "w" (__count)
: "0"
);
}
it seems to work.
I don't know why the original doesn't work. But maybe, since the out is not
used, the compiler thinks it does not need to supply the input. Funny that
the loop haven't been optimized away too. (But that is be cause of the
'volatile' I think)
The later code does not generate an output but destroys the input registers.
Unfortunely it doesnt work. I now tested this code:
for (d=0; d<100; d++) Mydelay_loop_2(617); //delay 100ms
bcc: 80 e0 ldi r24, 0x00 ; 0
bce: e9 e6 ldi r30, 0x69 ; 105
bd0: f2 e0 ldi r31, 0x02 ; 2
bd2: 31 97 sbiw r30, 0x01 ; 1
bd4: f1 f7 brne .-4 ; 0xbd2
bd6: 8f 5f subi r24, 0xFF ; 255
bd8: 84 36 cpi r24, 0x64 ; 100
bda: d8 f3 brcs .-10 ; 0xbd2
The compiler thinks that the inline function doesnt change the input
registers, so they get initialized only once outside the for-loop.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [avr-gcc-list] [Bug] Initialization for _delay_loop_2 OptimizedOut,
Bjarne Laursen <=