4 ms·
> gcc -O1 -o fft-test fft-test.c fft-portable.c -lm -O1 instructs the compiler to leave some optimizations on the table. If you want the fastest code the comp
by jlebar 10y ago
> gcc -O1 -o fft-test fft-test.c fft-portable.c -lm
-O1 instructs the compiler to leave some optimizations on the table. If you want the fastest code the compiler can generate, you want -O2 or -O3.
This is true for clang and gcc.
- user5994461 10y agoAnd I believe he should also give flags to target the specific hardware and instruction set that he has. In extreme cases, GCC/Intel/MSVC are able to optimize pure C code with auto-vectorization and SSE/AVX instructions, possibly better than hand crafted ASM... but the compiler will never do that if not given the flags to allow it.
- astrange 10y agoAutovectorization is okay but not that good. Its advantage is just that it can transform any part of the program, when your limited dev time won't touch it all. But it can't focus on the hot loops or know about cache efficiency etc. even if you use PGO. And it's sensitive and unstable wrt code changes which is never good.
- aarongolliver 10y agoYeah, and when autovectorization fails it can be really hard to tell why. The diagnostic messages aren't the best (or, at least, they weren't when I was doing this ~4 years ago) EG: ICC has a AVX version of atan2(), which you can use through intrinsics[0]. But it refused to vectorize even the simplest loop with the function call in it. Even with every possible fast-math flag or every #pragma(please vectorize), it wouldn't do it. I assume due to reduced precision? Nothing I could find online had the answer (again, 4 years ago) [0] https://software.intel.com/en-us/node/524364 https://software.intel.com/en-us/node/524364
- benchaney 10y agoTo be honest, this oversight makes the rest of his analysis somewhat suspect.
- dagss 10y agoI would assume it meant that it made things slower, after all this was a hand-tuned numerical core. Optimizations is for what a human did not already optimize.
- benchaney 10y agoIf by this you mean higher levels of optimization made things slower, than I must disagree. He says "Compiling C code with optimizations enabled is obviously a good idea" he would have mentioned it here if -O2 or -O3 were slower. Also, the optimizer doesn't optimize hand written assembly. Only c code. What I actually think happened is he didn't understand that there were higher optimization levels that -O1, which gives his code an advantage when compared to the c code implementation.