4 ms·
I'm not sure I understand your argument. The optimizations here are: >"-Ofast" same as "-O3 -ffast-math" -ffast-math makes the compiler violate IEEE, it would
by simias 6y ago
I'm not sure I understand your argument. The optimizations here are:
>"-Ofast" same as "-O3 -ffast-math"
-ffast-math makes the compiler violate IEEE, it would make a very bad default.
-O3 used to be potentially buggy and somewhat experimental, although I doubt that it's much of a practical problem these days. It still makes the code harder to debug though. Most build systems I'm aware of default to debug builds, so GCC is not really unique in that regard.
>"-flto" enable link time optimizations
Those optimizations are typically quite expensive and can backfire in some scenarios. Link time optimizations are relatively novel, at least within the timeframe of GCC. I'm sure they'll be enabled by default some day, but GCC has to be conservative.
>"-mfpmath=sse" enables use of XMM registers in floating point instructions (instead of stack in x87 mode)
So that means that you tell the compiler to assume that SSE is available on the target. By default GCC outputs code that's compatible with the baseline, which is perfectly reasonable IMO. Same reason why -march=native is also not the default, it is assumed that you may want to ship your binaries to other computers.
>"-funroll-loops" enables loop unrolling
From GCC's own docs:
"This option makes code larger, and may or may not make it run faster."
Loop unrolling is tricky, because it gets rid of branches but also increases the size of the code and therefore the pressure on the icache. In some scenarios it's possible that the looping code run faster than the linear version if it saves on cache misses.
Given that there are tradeoffs involved, it's also reasonable to let the user decide to enable this optim.
I work with C a lot and IMO the only default in GCC that's truly bad is that it doesn't have -Wall by default.
- jcranmer 6y ago> So that means that you tell the compiler to assume that SSE is available on the target. By default GCC outputs code that's compatible with the baseline, which is perfectly reasonable IMO. Same reason why -march=native is also not the default, it is assumed that you may want to ship your binaries to other computers. If your x86 computer was made after the US invaded Iraq, it supports SSE2 instructions.
- simias 6y agoAnd I'm currently writing code for a 32bit CPU that was first introduced in 2000. It's not x86 so SSE is irrelevant, but my point is that GCC is routinely used to build millions if not billions of lines of code, they can't just YOLO-deprecate things as if it were a javascript framework.
- cozzyd 6y agoIt's also possible someone may prefer the 80-bit intermediate precision of the x87 registers. I guess.
- jcranmer 6y agolong double in either x87 or SSE mode will force the use of 80-bit fp values.
- ilaksh 6y agoSo maybe it can't be default bit like I said should be mentioned in the help under the optimization option along with some of those other things.
- gnufx 6y ago> >"-Ofast" same as "-O3 -ffast-math" That depends on the language and the GCC version. > -ffast-math makes the compiler violate IEEE, it would make a very bad default. Yes, but unfortunately it's the Intel default, which contributes to some of the compiler mythology. Regarding unrolling, you usually do want it in numeric loops, and -O3 unrolls (and jams) as -fopt-info shows.
- simias 6y ago>That depends on the language and the GCC version. I was quoting TFA verbatim. I actually never use -Ofast myself, beyond -O3 I tend to use the individual flags manually, checking wit benchmarks that it makes a difference. >Yes, but unfortunately it's the Intel default, which contributes to some of the compiler mythology. I didn't know that. I guess Intel is extremely performance-oriented and doesn't really care for portability so it makes some sense for them to do that. >Regarding unrolling, you usually do want it in numeric loops, and -O3 unrolls (and jams) as -fopt-info shows. Sure but that's to my point: the default optims for -O3 are fairly aggressive already. Unless you're writing code where performance is absolutely critical you'll probably be do just fine just remembering to pass "-Wall -O3" to GCC and that's it. Actually for most of my code where I want good performance but I'm not counting individual clock cycles I tend to default to -O2 which gives you most of the performance benefits with more conservative and easier to debug optimizations. And for cases where you need to go beyond -O3 you'll probably have to write some benchmarking code before you can decide which additional option to use. At least, in my experience.