2

I found Ofast level opt in the doc of gcc on http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Optimize-Options. But when i compile my code using this level,gcc told me not recognize this flag. I'm using gcc 4.5.2 which is the most recently released gcc. So which version of gcc support this level? Tnanks.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
PDF1001
  • 173
  • 3
  • 13
  • For future reference, the documentation you were looking at is for the current development version. If you follow the "Manual" link from the homepage, you'll get to that through the current development section, way at the bottom. All the other manuals, by version number, are up at the top. You can figure out for yourself whether it should be in a given version. You should really get in the habit of using the documentation for the version you're using! – Cascabel Jan 24 '11 at 05:29
  • 2
    `-Ofast` turns on `-ffast-math`, which is dangerous. You should not use either unless you know what you are doing. – ignis Jan 19 '13 at 05:32
  • It can make a huge difference in processing time; in a microbenchmark calculating fibonacci and some additional simple calculations it performed twice as fast as "-O2". I would like to know about the risks of using "-Ofast". Compiling time included! –  Jun 29 '13 at 22:22

2 Answers2

6

The -Ofast flag is a new feature in GCC 4.6 -- see the list of changes here.


It turns on -ffast-math, so be careful if you need strict FP semantics.

The GCC manual documents what else it turns on, including -fallow-store-data-races and -fno-semantic-interposition.

(It doesn't enable instruction-set options like -march=native, you need to do that separately if you want to optimize as much as possible for your machine and make a binary that might not run on other CPUs.)

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Jeremiah Willcock
  • 30,161
  • 7
  • 76
  • 78
1

GCC's changelog seems to indicate that this will be available in the 4.6 release series (which does not yet have a stable release). Optionally, you could try building the development sources from their SVN repo or grabbing a pre-built snapshot from one of the mirrors.

eldarerathis
  • 35,455
  • 10
  • 90
  • 93