[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] optimization missed?
From: |
Douglas Hammond |
Subject: |
[avr-gcc-list] optimization missed? |
Date: |
Wed, 9 Jul 2008 17:55:55 -0400 |
I'm just curious,
I have a funtion that returns the element of a struct from and array of structs.. Hope that made sense.
Any way I found that doing
Code:
void test(uint8_t axis_index) {
return (_axis[axis_index].state);
}
produces
Code:
110: 90 e0 ldi r25, 0x00 ; 0
112: 9c 01 movw r18, r24
114: 22 0f add r18, r18
116: 33 1f adc r19, r19
118: 22 0f add r18, r18
11a: 33 1f adc r19, r19
11c: f9 01 movw r30, r18
11e: ee 0f add r30, r30
120: ff 1f adc r31, r31
122: ee 0f add r30, r30
124: ff 1f adc r31, r31
126: ee 0f add r30, r30
128: ff 1f adc r31, r31
12a: e2 1b sub r30, r18
12c: f3 0b sbc r31, r19
12e: e8 0f add r30, r24
130: f9 1f adc r31, r25
132: ec 58 subi r30, 0x8C ; 140
134: ff 4f sbci r31, 0xFF ; 255
136: 80 81 ld r24, Z
138: 83 70 andi r24, 0x03 ; 3
13a: 08 95 ret
while
Code:
void test(uint8_t axis_index) {
axis_control_s* axis = (axis_control_s*) &_axis[axis_index];
return (axis->state);
}
produces
Code:
110: 9d e1 ldi r25, 0x1D ; 29
112: 89 9f mul r24, r25
114: f0 01 movw r30, r0
116: 11 24 eor r1, r1
118: e2 59 subi r30, 0x92 ; 146
11a: ff 4f sbci r31, 0xFF ; 255
11c: 86 81 ldd r24, Z+6 ; 0x06
11e: 83 70 andi r24, 0x03 ; 3
120: 08 95 ret
Using winavr WinAVR-20080610 and -O2
A considerable differnce in size and speed.
Seems like the pointer get optimized but the array indexing does not.
- [avr-gcc-list] optimization missed?,
Douglas Hammond <=