[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] refactoring to reduce code size
From: |
Alex Shepherd |
Subject: |
Re: [avr-gcc-list] refactoring to reduce code size |
Date: |
Thu, 30 Jan 2003 12:09:44 +1300 |
Thanks to those who posted suggestions, here is a composite reply:
Eric wrote:
> Along with the other suggestions posted, I would also suggest you
> take a hard look at any switch statements and the assembly it
> produces. AFAIU, it depends on how many cases you have in the swtich
> how GCC will implement it. Sometimes it may be optimal, other times
> not.
>
> If the cases are sequential values, it *might* be more prudent to
> implement it as a table. Other times, if there are not many cases, a
> simple if-elseif structure will be more efficient on space. You'll
> probably have to experiment with the C code and see what assembly it
> produces.
I have avoided using switch statments for that very reason because I read
somewhere that they can bloat the code with jump tables and have coded "if,
else if, else" sequences.
Yann Ramin Wrote:
> Some simple things to check for:
>
> I assume you're using -Os?
Yes
> Use char for most number types, int and especially long is
> expensive ram and codewise.
I am using uint8 or unsigned char where possible and have a few unsigned
shorts as well, no longs yet.
> Are you using any libraries?
I am using a few C library functions but explicitly not using malloc or
printf family, they burn too much FLASH!
> Avoid dealing with floating point numbers.
Not using floats.
J"org Wunsch wrote:
> I always wonder why people are so keen to get all these list
> files. ;-) I think they are pretty useless.
>
> avr-nm --size-sort -S <ELF file name>
>
> is your friend.
I would agree about list files - they are a real mess, but that is all I
knew about until your suggestion.
I will try avr-nm
Volkmar Dierkes wrote:
> Try a look at avr-sizex. This tool provides you an option to
> list the n biggest functions. Maybe this helps you to get a
> faster overview. You find this tool on the avrfreaks web site:
> http://www.avrfreaks.com/phorum/download.php?f=2&file=avr-sizex-03.zip
>
> As I remember, if you look at the % of used flash, it uses
> the application flash with biggest bootloader section. To get
> it to the whole flash range, you have to set the desired option.
I will try this also.
Hopefully between avr-nm and avr-sizex I will locate some good places to
start refactoring!
Cheers
Alex Shepherd
avr-gcc-list at http://avr1.org