[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-libc-dev] Missed optimizations
From: |
Raul Sanchez |
Subject: |
[avr-libc-dev] Missed optimizations |
Date: |
Sun, 16 Apr 2017 17:30:43 +0000 (UTC) |
Just wanted to report the following observations in generated code.
Target: __AVR_ATtiny85__Version: AVR gcc 4.6.4Optimization level: -Os
-------- C source ---------- uint16_t sum_adc; uint16_t analog; uint16_t
adc_buffer[64]; uint8_t adc_index;... sum_adc += ADC; sum_adc -=
adc_buffer[adc_index]; analog = (uint16_t) (sum_adc >> 3);...------- end C
source ------------
------- assembly code (with corresponding C statements) --------// sum_adc +=
ADC; lds r18,sum_adc lds r19,sum_adc+1 in r24,36-0x20
in r25,36+1-0x20 add r24,r18 adc r25,r19 sts
sum_adc+1,r25 sts sum_adc,r24// sum_adc -= adc_buffer[adc_index];
lds r18,sum_adc ; why not "mov r18,r24" "mov r19,r25" ? lds
r19,sum_adc+1 lds r30,adc_index ldi r31,lo8(0)
;why not "clr r31"? ldi r24,lo8(adc_buffer) ldi
r25,hi8(adc_buffer) lsl r30 rol r31 add r30,r24 adc
r31,r25 ld r20,Z ldd r21,Z+1 sub r18,r20 sbc
r19,r21 sts sum_adc+1,r19 sts sum_adc,r18// analog =
(uint16_t) (sum_adc >> 3); lds r18,sum_adc ; loading into
r18, r19 the same values they alredy hold! lds r19,sum_adc+1 lsr
r19 ror r18 lsr r19 ror r18 lsr r19 ror r18
sts analog+1,r19 sts analog,r18
- [avr-libc-dev] Missed optimizations,
Raul Sanchez <=