[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: |
Schwichtenberg, Knut |
Subject: |
RE: [avr-gcc-list] Inconsisten behaviour of switch statement |
Date: |
Tue, 27 Mar 2007 08:39:52 +0200 |
Hi,
> -----Original Message-----
> From:
> address@hidden
> g
> [mailto:address@hidden
ongnu.org] On Behalf Of Joerg Wunsch
> Sent: Tuesday, March 27, 2007 7:10 AM
> To: address@hidden
> Subject: Re: [avr-gcc-list] Inconsisten behaviour of switch statement
> Knut, can you provide us an example that reproduces the problem?
Okay, attached to my first posting there was my exapmle. I strip it to
an overview:
volatile uint8_t minute;
switch (minute)
{
case 0:
case 15:
case 30:
case 45:
dosomething();
break;
default:
break;
}
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:
and a 0 to 24 switch example:
volatile uint8_t sec25;
switch (sec25) {
case 0: doa(); break;
case 1: doa(); break;
case 2: doa(); break;
case 3: doa(); break;
// Mostly all other elemets are in use
...
case 24: doa(); break;
default: break;
is compiled to:
lds r24,sec25
clr r25
clr r26
clr r27
movw r30,r24
sbiw r24,25
brsh .L11
subi r30,lo8(-(pm(.L37)))
sbci r31,hi8(-(pm(.L37)))
lsl r30
rol r31
lpm __tmp_reg__,Z+
lpm r31,Z
mov r30,__tmp_reg__
ijmp
.data
.section .progmem.gcc_sw_table, "a", @progbits
.p2align 1
.L37:
.word pm(.L12)
.word pm(.L16)
.word pm(.L33)
.word pm(.L24)
.word pm(.L33)
.word pm(.L34)
.word pm(.L33)
.word pm(.L22)
.word pm(.L33)
.word pm(.L24)
.word pm(.L33)
.word pm(.L34)
.word pm(.L33)
.word pm(.L11)
.word pm(.L33)
.word pm(.L29)
.word pm(.L33)
.word pm(.L34)
.word pm(.L33)
.word pm(.L11)
.word pm(.L33)
.word pm(.L34)
.word pm(.L11)
.word pm(.L11)
.word pm(.L35)
.text
Here are the examples.
Cheers
Knut
BTW: casting of the constant, the variable or both does not convince gcc
to use a byte compare.
- [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 <=
- 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, Eric Weddington, 2007/03/27