avr-libc-dev
[Top][All Lists]
Advanced

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

[avr-libc-dev] if-statement is optimized wrong


From: Michael Kristensen
Subject: [avr-libc-dev] if-statement is optimized wrong
Date: Sat, 3 May 2003 16:38:59 +0200
User-agent: KMail/1.5

Hi,

I'm having trouble compiling the code snippet below. If I use anything above 
-O0 the if-statement it won't work.

Michael

$ avr-gcc -v
Reading specs from /usr//bin/../lib/gcc-lib/avr/3.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man 
--infodir=/usr/share/info --enable-languages=c,c++ --disable-nls --target=avr 
i386-redhat-linux
Thread model: single
gcc version 3.3 20030428 (prerelease)



/*
avr-gcc  -S -g -O2 -Wall -mmcu=atmega128  gcc-fail.c
gcc optimizes badly above -O0 :
it thinks that the if always go one way.
*/

#include <inttypes.h>
#include <avr/io.h>

uint8_t example(void) {
 static uint8_t prev_input;
 uint8_t input, dinput, ret;

 input = PINE;
 dinput = prev_input ^ input;
 prev_input = input;

 if (dinput & 0x01)
   ret = 1;
 else
   ret = 0;

 return ret;
}




reply via email to

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