avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] code optimisation


From: Matthew MacClary
Subject: Re: [avr-gcc-list] code optimisation
Date: Tue, 17 Aug 2004 14:17:54 -0700
User-agent: Mutt/1.5.6i

On Tue, Aug 17, 2004 at 02:39:04PM +0100, Trevor White wrote:
> I am looking to find out how to write code that gcc prefers w.r.t.
> optimisation. Where can I find out information on what gcc prefers
> to what it does not?

    Trev, here are my thoughts on this issue, others probably think
differently!  The first major question to answer is whether you are
optimizing for time or space.  Space optimization can be directed by
the programmer by using space efficient algorithms and declaring the
smallest data type possible.
    GCC can do so many optimizations for time that catering to one
optimization would probably just cost you time from another
optimization.  It is probably best to just write clear, modular code
that can be easily maintained.  I would minimize use of the "register"
hint, and pointer arithmetic because the compiler can usually pick
better register variables (for example) unless you put in the
necessary analysis work up front.  If you can figure out a way to do
necessary operations with bitwise operators in an inner loop, then
this could be worthwhile to increase speed.
    To decide where to spend your optimization time, you first need to
know your time and space constraints for the project.  Next, write the
program, compile it with optimization, then see if you meet the
constraints.  If you meet all of the constraints, then you are done!
If you are really far off of the project requirements, and some one
else has double checked your code for algorithmic efficiency then you
probably need to start looking at 1) features to cut 2) extra RAM or
3) a faster part.
    If your preliminary testing shows that you are in the right
ball park with regard to time and space constraints, and you have
enough time before the deadline, you can start writing critical
portions of code in assembly.  Before you start writing assembly, I
would check the generated assembly code compiled with optimization to
make sure that it isn't doing the right thing already.


-Matt

---------------------------------
Where did the universe come from?


reply via email to

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