[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] code optimisation

From: Bruce D. Lightner
Subject: Re: [avr-gcc-list] code optimisation
Date: Wed, 18 Aug 2004 10:39:43 -0700
User-agent: Mozilla Thunderbird 0.5 (Windows/20040207)

Trevor White wrote:

Many thanks for all your comments. I have been working on my first full blown project with an AVR and GCC. Before this project I have worked in assembler. C gives many great benefits and I have enjoyed using it. The code I write is readable and my brain is not taken up with assembler coding techniques. The structure of C seems to just allow me to get on with writing code.

The cost of this is that my code seems large and I dont really know how long the code will take. I have to measure it on a scope and toggle port pins. I have used 8k already and now seem to spend time optimizing so I can carry on writing code. This is where I have found that re-writing certain lines seems to help. For example...

   temp = ~temp;
   temp += 1024
I have not tried this but am using it off the top of my head to show abstract ( to me ) code optimization.

   temp = (~(temp) + 1024);

I seem to find things like this above sometimes make better code. Sometimes a switch..case flow control works better than If statements, sometimes it is the other way round. So I was really wondering if there were golden rules and if there were any specific to gcc for avr.

If you haven't done this already, try re-compiling everything with the "gcc" switch "-mcall-prologues" and then re-link. If you have a lot of subroutines, this can save a surprising amount of code-space, and you don't have to change any C-code.

Best regards,


 Bruce D. Lightner
 Lightner Engineering
 La Jolla, California
 Voice: +1-858-551-4011
 FAX: +1-858-551-0777
 Email: address@hidden
 URL: http://www.lightner.net/lightner/bruce/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]