X-Reportbug-Version: 3.18 X-Debbugs-Cc: [EMAIL PROTECTED] Package: gcc-avr Version: 1:4.1.0-1 Severity: important
This piece of code gets compiled incorrectly. SIGNAL(SIG_INTERRUPT0) { if (PIND & _BV(PD2)) { low_period=TCNT1; } else { high_period=TCNT1; } } The Makefile looks like: MCU:=atmega168 CC:=avr-gcc OBJCOPY:=avr-objcopy CFLAGS:=-g -mmcu=$(MCU) -Wall -Wstrict-prototypes -Os -mcall-prologues -I/usr/avr/include -funroll-loops LDFLAGS:=-g -lc all: $(TARGET) %.hex: %.out $(OBJCOPY) -R .eeprom -O ihex $< $@ %.out: %.o $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< -Wl,-Map,$(basename $<).map %.s: %.c $(CC) $(CFLAGS) -Os -S $< %.o: %.s $(CC) $(CFLAGS) -Os -c $< The result is: SIGNAL(SIG_INTERRUPT0) { 294: 1f 92 push r1 296: 0f 92 push r0 298: 0f b6 in r0, 0x3f ; 63 29a: 0f 92 push r0 29c: 11 24 eor r1, r1 29e: 2f 93 push r18 2a0: 8f 93 push r24 2a2: 9f 93 push r25 if (PIND & _BV(PD2)) 2a4: 4a 9b sbis 0x09, 2 ; 9 2a6: 09 c0 rjmp .+18 ; 0x2ba <__vector_1+0x26> { // now H high_period=TCNT1; 2a8: 80 91 84 00 lds r24, 0x0084 2ac: 90 91 85 00 lds r25, 0x0085 2b0: 90 93 0c 01 sts 0x010C, r25 2b4: 80 93 0b 01 sts 0x010B, r24 2b8: 08 c0 rjmp .+16 ; 0x2ca <__vector_1+0x36> } else { low_period=TCNT1; 2ba: 20 91 84 00 lds r18, 0x0084 2be: 30 91 85 00 lds r19, 0x0085 2c2: 30 93 0e 01 sts 0x010E, r19 2c6: 20 93 0d 01 sts 0x010D, r18 2ca: 9f 91 pop r25 2cc: 8f 91 pop r24 2ce: 2f 91 pop r18 2d0: 0f 90 pop r0 2d2: 0f be out 0x3f, r0 ; 63 2d4: 0f 90 pop r0 2d6: 1f 90 pop r1 2d8: 18 95 reti - r0, r1 are pushed/popped, r1 is zeroed. If 0x3f really needs to be saved, it could be done by another register, which has to be used anyway. (or instead of (r18, r19, r24, r25) (r0,r1) should be used.) - r19 is modified, but not saved - this whole construct could be optimized very much better. - -Os, as already used, is much better than without. -O7 or -O2 give the same result as -Os. -- System Information: Debian Release: testing/unstable APT prefers testing APT policy: (850, 'testing'), (600, 'unstable'), (1, 'experimental') Architecture: i386 (i686) Shell: /bin/sh linked to /bin/dash Kernel: Linux 2.6.15-1-k7 Locale: LANG=de_AT, LC_CTYPE=de_AT (charmap=ISO-8859-1) Versions of packages gcc-avr depends on: ii binutils-avr 2.16.1-1 Binary utilities that support Atme ii libc6 2.3.6-7 GNU C Library: Shared libraries gcc-avr recommends no packages. -- no debconf information -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]