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

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

Re: [avr-gcc-list] -O1 vs. -O3


From: Peter N Lewis
Subject: Re: [avr-gcc-list] -O1 vs. -O3
Date: Thu, 14 Jun 2001 10:05:05 +0800

At 11:30 -0600 13/6/01, Marlin Unruh wrote:
Excuse me, but my amateurishness is showing!  :)

What is the difference between -O1, -O2, -O3 ???

Optimization of course, but why not always as optimized as possible? Why not
always use -O1?

I had never change the setting till today, and my code size drop 112 bytes
using -O1 instead of -O3.

Everything has an equal and opposite reaction so, what's the trade-off?
Speed? Reliability?

Speed vs Size.

I normally use -Os which is optimize for size.

-O1 is optimize for speed, 2 and 3 are the same, but more optimizations (ie, -O3 should produce faster code than -O2 or -O1).

According to man_avr-gcc.pdf

<http://www.avrfreaks.net/AVRGCC/Download/man_avr-gcc.pdf>

-O or -O1
Optimize. Optimizing compilation takes somewhat more time, and a lot more memory for a large
function.

Without -O, the compiler's goal is to reduce the cost of compilation and to make debugging produce the expected results. Statements are independent: if you stop the program with a breakpoint between statements, you can then assign a new value to any variable or change the program counter to any other statement in the function and get exactly the results you would expect from the source code.

Without -O, the compiler only allocates variables declared register in registers. The resulting
compiled code is a little worse than produced by PCC without -O.

With -O, the compiler tries to reduce code size and execution time.

When you specify -O, the compiler turns on -fthread-jumps and -fdefer-pop p on all machines. The compiler turns on -fdelayed-branch on machines that have delay slots, and -fomit-frame-pointer on machines that can support debugging even without a frame pointer. On some machines the compiler
also turns on other flags.

-O2
Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. The compiler does not perform loop unrolling or function inlining when you specify -O2. As compared to -O, this option increases both compilation time and the performance of the
generated code.

-O2 turns on all optional optimizations except for loop unrolling, function inlining, and register renaming. It also turns on the -fforce-mem option on all machines and frame pointer elimination on
machines where doing so does not interfere with debugging.

-O3
Optimize yet more. -O3 turns on all optimizations specified by -O2 and also turns on the -finline-
functions and -frename-registers options.

-O0
Do not optimize.

-Os
Optimize for size. -Os enables all -O2 optimizations that do not typically increase code size. It also
performs further optimizations designed to reduce code size.

If you use multiple -O options, with or without level numbers, the last such option is the one that is
effective.

Options of the form -fflag specify machine-independent flags. Most flags have both positive and negative forms; the negative form of -ffoo would be -fno-foo. In the table below, only one of the forms is listed - the one which is not the default. You can figure out the other form by either removing no- or
adding it.

It then goes on to list all the different individual options.

Enjoy,
   Peter.

--
<http://www.interarchy.com/>  <ftp://ftp.interarchy.com/interarchy.hqx>



reply via email to

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