Re: optimization gcc

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

 



On Mon, 25 Aug 2003 15:15:35 +0200, Albert Pala <a.Pala@xxxxxxxxxxxxxxxx>  said:

> Which flags should I set in gcc to get best optimized code in C ( for speed )?
> Currently I use:
> gcc -Wall -O2 march=athlon -funroll-all-loops -fomit-frame-pointer -c xyz.c
> How can i get the fastest code?

-O3 will enable some more optimizations.  Note that there is reason to believe
that -fomit-frame-pointer may generate *slower* code in some cases - not having
the frame pointer forces a register reload for memory accesses, so your code
ends up bigger and slower.  Also, look into inlining options for small
functions that are performance critical.

Contrary to popular myth, -On for n > 3 doesn't do anything extra in modern gcc.

And remember to benchmark, benchmark, benchmark.  Quite often, the results are
non-intuitive.  I've seen code that turned on aggressive inlining run slower
because the resulting code was bigger and ended up causing L1 I-cache
thrashing.

And keep in mind that at -O2, gcc is already doing almost as much as it can to
optimize. Don't expect to get more than another 4-5% performance *at best* by
tweaking the compiler flags.  If you need more than that, you *REALLY* need to
go back and recode your application - start looking for places where you're
using a linked list where maybe a hash table should be used, etc Use the -pg
flags to gcc to profile your code.  Figure out why it's spending the time where
it is.  Concentrate on those parts of the code.

Attachment: pgp00024.pgp
Description: PGP signature


[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux