avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Inconsisten behaviour of switch statement


From: Schwichtenberg, Knut
Subject: [avr-gcc-list] Inconsisten behaviour of switch statement
Date: Mon, 26 Mar 2007 08:38:34 +0200

Hi,

while the size of my programm shrunk after adding some cases I looked to the 
list file. I saw that a switch was converted from a structured if-then-else to 
a table jump (compiled with -Os). That's okay. A detailed analyses points to a 
gcc problem: I use a volatile variable. If a samll number cases are used, the 
value is reloaded for every compare. If the switch is implemented by a table 
jump, the value is loaded once and moved into 2 register pairs. One the first 
glance both implementations are correct, but under special conditions based on 
the number of case the dynamic behaviour can change!

I don't know which behaviour is correct, but it should not change by the number 
of cases. Attached you will find an example showing both behaviours. It is 
reduced and therefore became stupid.

BTW: Is there any reason why the compares within the switch are at least 16 bit 
and not type dependent for 8 bit types? If you program this as a normal if, 8 
bit compares are generated.

If this is a bug I will write a bug report after a short comment here.

Best Regards

Knut
Ps: Compile

$ make test.o

Compiling C: test.c
avr-gcc -c -mmcu=atmega32 -I. -gstabs -DF_CPU=3686400UL -DDEB=1 -DBUILD=371 -Os 
-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall 
-Wstrict-prototypes -Wundef -Wa,-adhlns=./test.lst -Isteuerung -std=gnu99 
-Wundef -MMD -MP -MF .dep/test.o.d test.c -o test.o
.....
$ avr-gcc --version
avr-gcc.exe (GCC) 3.4.6
Copyright (C) 2006 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. 

----------------------------------------------------------------------
Knut Schwichtenberg                        Siemens AG 
Tel. : +49-531-2265756                     TS RA MT PB
Fax. : +49-531-2264198                     D-38106 Braunschweig
Mobil: +49 173 5325504                     Germany
Email: address@hidden 

Siemens Aktiengesellschaft: Vorsitzender des Aufsichtsrats: Heinrich v. Pierer; 
Vorstand: Klaus Kleinfeld, Vorsitzender; Johannes Feldmayer, Joe Kaeser, 
Rudi Lamprecht, Eduardo Montes, Jürgen Radomski, Erich R. Reinhardt, 
Hermann Requardt, Uriel J. Sharef, Klaus Wucherer       
Sitz der Gesellschaft: Berlin und München
Registergericht: Berlin Charlottenburg, HRB 12300, München, HRB 6684
WEEE-Reg.-Nr. DE 23691322

----------------------------------------------------------------------
This mail is made from 100% recycled electrons. 

Attachment: test.c
Description: test.c


reply via email to

[Prev in Thread] Current Thread [Next in Thread]