GCC - Optimal Optimization

Oliver Fromme olli at lurza.secnetix.de
Fri Aug 18 18:01:08 UTC 2006


Sean M. <sigma_zk at yahoo.com> wrote:
 > With GCC 3.4.4, what are the best CFLAGS to use for an AMD Duron ~1000
 > MHz? By "best" I mean creating the fastest programs that exploit fully
 > all of the architecture's features, without creating a "noticible"
 > increase in size. To date I've been using
 > CFLAGS="-O3 -march=athlon-xp -mfp-math=sse -funroll-loops -pipe
 > -ffast-math"

I recommend staying with the default, i.e. not overriding
CFLAGS at all, unless you know exactly what you're doing,
for each single option.  From your options above I notice
that you don't know what you're doing.  :-)

The default is "-O2 -fno-strict-aliasing -pipe".  If you
specify any optimization level greater than -O (i.e. -O2
or -O3), you _must_ also include -fno-strict-aliasing,
otherwise you will get broken code for certain programs.

By the way, -funroll-loops can make programs slower,
because the central parts might not fit into the CPU
cache anymore.  In many cases, the loop overhead is
less significant than the overhead of having to access
main memory.  It depends on the program, of course --
there is no "one size fits all".  Different programs
will benefit from different optimizer flags.

In general, the differences are small enough that it's
not worth spending much time and efforts for benchmarking.
That's another reason to recommend to just go with the
default settings.

You said you don't want an increase in size.  But that's
exactly what -O3 (via inlining) and -funroll-loops do.
If you want not to increase size, use the default flags.
You could even use -Os, which instructs the compiler to
optimize for small size (it's somewhere between -O and
-O2).

Best regards
   Oliver

-- 
Oliver Fromme,  secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing
Dienstleistungen mit Schwerpunkt FreeBSD: http://www.secnetix.de/bsd
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.

"We, the unwilling, led by the unknowing,
are doing the impossible for the ungrateful.
We have done so much, for so long, with so little,
we are now qualified to do anything with nothing."
        -- Mother Teresa


More information about the freebsd-questions mailing list