21 ms·
I did a double take on this because I wrote a blog post about this topic a few months ago and came to a very different conclusion, that the results are effectiv
by camblomquist 3y ago
I did a double take on this because I wrote a blog post about this topic a few months ago and came to a very different conclusion, that the results are effectively identical on clang and gcc is just weird.
Then I realized that I was writing about compiling for ARM and this post is about x86. Which is extra weird! Why is the compiler better tuned for ARM than x86 in this case?
Never did figure out what gcc's problem was.
https://godbolt.org/z/Y75qnTGdr https://godbolt.org/z/Y75qnTGdr
- frozenport 3y agoTry switching to -Ofast it produces different ASM
- klodolph 3y ago-Ofast is one of those dangerous flags that you should probably be careful with. It is “contagious” and it can mess up code elsewhere in the program, because it changes processor flags. I would try a more specific flag like -ffinite-math-only.
- Sharlin 3y agofinite-math-only is a footgun as well as it allows the compiler assume that NaNs do not exist. Which means all `isnan()` calls are just reduced to `false` so it’s difficult to program defensively. And if a NaN in fact occurs it’s naturally a one-way ticket to UB land.
- klodolph 3y agoIf that’s a foot gun, then -Ofast is an autocannon. I like to think that the flag should be renamed “-Ofuck-my-shit-up”.
- MaulingMonkey 3y agoAs 1 of ∞ examples of UB land, I once had to debug JS objects being misinterpreted as numbers when https://duktape.org/ https://duktape.org/ was miscompiled with a fast-math equivalent (references to objects were encoded as NaNs.)
- WanderPanda 3y agoIs that changing of global processor flags a x86 feature or does it hold for arm as well?
- account42 3y agohttps://github.com/gcc-mirror/gcc/blob/master/libgcc/config/arm/crtfastmath.c https://github.com/gcc-mirror/gcc/blob/master/libgcc/config/... So, yes when targeting VFP math. NEON already always works in this mode though.
- gpderetta 3y agoIIRC the changing global flags "feature" was removed recently from GCC and now you have to separately ask for it.