3 ms·
OK, I might have a lead on the GCC versus Clang gap. At the least, this obscure command line option closes the gap: gcc-8 -fno-math-errno -O3 bodies.c -msse
by nkurz 7y ago
OK, I might have a lead on the GCC versus Clang gap. At the least, this obscure command line option closes the gap:
gcc-8 -fno-math-errno -O3 bodies.c -msse3 -Wall -lm -o bodies_gcc_O3_sse3_c
perf stat bodies_gcc_O3_sse3_c 5000000
1,398,805,282 cycles # 3.691 GHz
3,181,041,562 instructions # 2.27 insns per cycle
I haven't thought about it much, but more info here: https://stackoverflow.com/questions/37117809/why-cant-gcc-optimize-out-stdsqrt https://stackoverflow.com/questions/37117809/why-cant-gcc-op.... While the question is about C++, it hints that the spec might require sqrt() to set errno if given a negative number. Clang special cases this by adding a never taken branch, but gcc does not (unless told it doesn't need to care).