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

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

RE: [avr-gcc-list] Bug or bad optimization?


From: Klaas K.
Subject: RE: [avr-gcc-list] Bug or bad optimization?
Date: Thu, 3 Mar 2005 08:08:45 +0200

Hi,

Had a similar problem. Try the following:
Change: avr-gcc -S -mmcu=atmega128 -I. -gstabs   -Os -funsigned-char
-funsigned-bitf
To: avr-gcc -S -mmcu=atmega128 -I. -gstabs   -O0 -funsigned-char
-funsigned-bitf
(Switch off optimization)

If you want to use optimization try this less elegant solution:

RD_CMD:
                if(command == NULL) {
                        goto RD_CMD;
                }
                        // wait for command in uart getchar

Regards,
Klaas korterink

-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of
Jim Davis
Sent: Wednesday, March 02, 2005 6:37 PM
To: Avr List Server
Subject: [avr-gcc-list] Bug or bad optimization?


The following code generation has a problem handling
the external variable "command":

1) I dont see the global variable "command" has been put into r16
2) The while loop never loads r16 with the global before the test.

What is the proper way to tell the compiler what to do here?

------------------------------------------- C source
extern unsigned char command;
char *get_command(void)
{
        int i = 0;
        while(1)
        {
                command = NULL;
                while(command == NULL);
                        // wait for command in uart getchar
                if (command == CR)
---------------------------------------------
m   -----------------------------
80:       char *get_command(void)
81:       {
+00000962:   92EF        PUSH    R14              Push register on stack
+00000963:   92FF        PUSH    R15              Push register on stack
+00000964:   930F        PUSH    R16              Push register on stack
+00000965:   931F        PUSH    R17              Push register on stack
+00000966:   93CF        PUSH    R28              Push register on stack
+00000967:   93DF        PUSH    R29              Push register on stack
82:             int i = 0;
+00000968:   E0C0        LDI     R28,0x00         Load immediate
+00000969:   E0D0        LDI     R29,0x00         Load immediate
+0000096A:   E38E        LDI     R24,0x3E         Load immediate
+0000096B:   2EE8        MOV     R14,R24          Copy register
+0000096C:   E183        LDI     R24,0x13         Load immediate
+0000096D:   2EF8        MOV     R15,R24          Copy register
85:                     command = NULL;
+0000096E:   9210150E    STS     0x150E,R1        Store direct to data
space
+00000970:   E000        LDI     R16,0x00         Load immediate
86:                     while(command == NULL);
+00000971:   2300        TST     R16              Test for Zero or Minus
+00000972:   F3F1        BREQ    PC-0x01          Branch if equal
88:                     if (command == CR)
+00000973:   300D        CPI     R16,0x0D         Compare with immediate
------------------------------------------------------------------------
----
---

avr-gcc -S -mmcu=atmega128 -I. -gstabs   -Os -funsigned-char
-funsigned-bitf
ields -fpack-struct -fshort-enums
-Wall -Wstrict-prototypes -Wa,-adhlns=toGui/main.lst
-Ic:/machinetalker/inc 
-Ic:/winavr/avr/include -
Ic:/winavr/avr/include/avr -std=gnu89
-Wp,-M,-MP,-MT,main.o,-MF,.dep/main.s.
d toGui/main.c -o toGui/main.s



_______________________________________________
AVR-GCC-list mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list





reply via email to

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