[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Inconsisten behaviour of switch statement
From: |
Joerg Wunsch |
Subject: |
Re: [avr-gcc-list] Inconsisten behaviour of switch statement |
Date: |
Tue, 27 Mar 2007 09:50:55 +0200 |
User-agent: |
Mutt/1.5.11 |
As Schwichtenberg, Knut wrote:
> Is compiled to:
>
> .LM2:
> lds r24,minute
> clr r25
> cpi r24,15
> cpc r25,__zero_reg__
> breq .L6
> .LM3:
> cpi r24,16
> cpc r25,__zero_reg__
> brge .L10
> or r24,r25
> breq .L6
> rjmp .L2
> .L10:
> cpi r24,30
> cpc r25,__zero_reg__
> breq .L6
> sbiw r24,45
> brne .L2
> .L6:
Yes, but this is technically OK. The volatile variable is read
exactly once, and then the decision is based on the value cached in
register rr24/25. This is different from the behaviour you've been
describing in the initial posting (which I'd really consider erroneous
but could not reproduce so far).
> BTW: casting of the constant, the variable or both does not convince
> gcc to use a byte compare.
This is the "missed optimization" Eric was talking about. Anyway,
GCC 4.1.1 gets you:
.global decide
.type decide, @function
decide:
/* prologue: frame size=0 */
/* prologue end (size=0) */
lds r24,minute
cpi r24,lo8(15)
breq .L3
cpi r24,lo8(16)
brsh .L4
tst r24
breq .L3
ret
.L4:
cpi r24,lo8(30)
breq .L3
cpi r24,lo8(45)
brne .L5
.L3:
rcall dosomething
.L5:
ret
So it properly detects the high byte doesn't need to be taken care of.
--
cheers, J"org .-.-. --... ...-- -.. . DL8DTL
http://www.sax.de/~joerg/ NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)
- [avr-gcc-list] Inconsisten behaviour of switch statement, Schwichtenberg, Knut, 2007/03/26
- Re: [avr-gcc-list] Inconsisten behaviour of switch statement, Preston Wilson, 2007/03/26
- RE: [avr-gcc-list] Inconsisten behaviour of switch statement, Eric Weddington, 2007/03/26
- RE: [avr-gcc-list] Inconsisten behaviour of switch statement, Schwichtenberg, Knut, 2007/03/26
- RE: [avr-gcc-list] Inconsisten behaviour of switch statement, Eric Weddington, 2007/03/26
- RE: [avr-gcc-list] Inconsisten behaviour of switch statement, Dave Hansen, 2007/03/26
- RE: [avr-gcc-list] Inconsisten behaviour of switch statement, Eric Weddington, 2007/03/26
- RE: [avr-gcc-list] Inconsisten behaviour of switch statement, Paulo Marques, 2007/03/26
- Re: [avr-gcc-list] Inconsisten behaviour of switch statement, Joerg Wunsch, 2007/03/27
- RE: [avr-gcc-list] Inconsisten behaviour of switch statement, Schwichtenberg, Knut, 2007/03/27
- Re: [avr-gcc-list] Inconsisten behaviour of switch statement,
Joerg Wunsch <=
- RE: [avr-gcc-list] Inconsisten behaviour of switch statement, Schwichtenberg, Knut, 2007/03/27
- RE: [avr-gcc-list] Inconsisten behaviour of switch statement, Eric Weddington, 2007/03/27