[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Question about code size
From: |
Dave Hylands |
Subject: |
Re: [avr-gcc-list] Question about code size |
Date: |
Fri, 16 Mar 2007 21:42:48 -0800 |
Hi Eric (and Erik and Paulo),
Can you determine where that difference is? Like you did with the inlined
code.
I wrote the following C function:
unsigned char getch(void);
void getNch(unigned char count)
{
unsigned char i;
for(i=0;i<count;i++)
getch();
}
3.4.4 avr-gcc -Os -mshort-calls -mmcu=atmega168
00000000 <getNch>:
0: cf 93 push r28
2: 88 23 and r24, r24
4: 21 f0 breq .+8 ; 0xe <getNch+0xe>
6: c8 2f mov r28, r24
8: 00 d0 rcall .+0 ; 0xa <getNch+0xa>
a: c1 50 subi r28, 0x01 ; 1
c: e9 f7 brne .-6 ; 0x8 <getNch+0x8>
e: cf 91 pop r28
10: 08 95 ret
4.2.0 produced:
00000000 <getNch>:
0: 0f 93 push r16
2: 1f 93 push r17
4: 08 2f mov r16, r24
6: 10 e0 ldi r17, 0x00 ; 0
8: 00 c0 rjmp .+0 ; 0xa <getNch+0xa>
a: 00 d0 rcall .+0 ; 0xc <getNch+0xc>
c: 1f 5f subi r17, 0xFF ; 255
e: 10 17 cp r17, r16
10: 01 f4 brne .+0 ; 0x12 <getNch+0x12>
12: 1f 91 pop r17
14: 0f 91 pop r16
16: 08 95 ret
I also did a comparison of the following optimization flags:
-O0 -O1 -O2 -O3 -Os
3.4.4 60 26 18 18 18
4.2.0 60 26 26 26 24
The numbers are the size in bytes of the .text section for the
function above. It appears that the compiler is promoting the unsigned
char's to ints.
If the integer promotion is removed, then you'd loose, a push, a pop,
a load of zero and the cp instruction, resulting in a 2 byte smaller
function - that would be nice :)
Aside: I've just moved my development platform from Windows to linux.
Where would I go to get the latest patches for gcc/binutils/et al.?
I'm currently using Marc Bodmer's build_avr_toolchain.sh script which
is the latest version I've found so far. It's using gcc-4.2-20060819
--
Dave Hylands
Vancouver, BC, Canada
http://www.DaveHylands.com/
- [avr-gcc-list] Question about code size, Dave Hylands, 2007/03/16
- RE: [avr-gcc-list] Question about code size, Eric Weddington, 2007/03/16
- Re: [avr-gcc-list] Question about code size,
Dave Hylands <=
- Re: [avr-gcc-list] Question about code size, Joerg Wunsch, 2007/03/17
- Re: [avr-gcc-list] Question about code size, Dave Hylands, 2007/03/17
- Re: [avr-gcc-list] Question about code size, Joerg Wunsch, 2007/03/17
- Re: [avr-gcc-list] Question about code size, David Brown, 2007/03/19
- Re: [avr-gcc-list] Question about code size, Joerg Wunsch, 2007/03/21
- RE: [avr-gcc-list] Question about code size, Eric Weddington, 2007/03/17
- Re: [avr-gcc-list] Question about code size, Joerg Wunsch, 2007/03/18
- RE: [avr-gcc-list] Question about code size, Eric Weddington, 2007/03/18
- Re: [avr-gcc-list] Question about code size, Dave Hylands, 2007/03/18