zlacker

[parent] [thread] 8 comments
1. camblo+(OP)[view] [source] 2024-01-16 14:17:19
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

replies(1): >>frozen+Ka
2. frozen+Ka[view] [source] 2024-01-16 15:13:44
>>camblo+(OP)
Try switching to -Ofast it produces different ASM
replies(1): >>klodol+bd
◧◩
3. klodol+bd[view] [source] [discussion] 2024-01-16 15:25:38
>>frozen+Ka
-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.

replies(3): >>Sharli+1i >>Wander+iC >>gpdere+q41
◧◩◪
4. Sharli+1i[view] [source] [discussion] 2024-01-16 15:43:57
>>klodol+bd
finite-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.
replies(2): >>klodol+Fn >>Maulin+Ws1
◧◩◪◨
5. klodol+Fn[view] [source] [discussion] 2024-01-16 16:07:28
>>Sharli+1i
If that’s a foot gun, then -Ofast is an autocannon.

I like to think that the flag should be renamed “-Ofuck-my-shit-up”.

◧◩◪
6. Wander+iC[view] [source] [discussion] 2024-01-16 17:16:50
>>klodol+bd
Is that changing of global processor flags a x86 feature or does it hold for arm as well?
replies(1): >>accoun+cY2
◧◩◪
7. gpdere+q41[view] [source] [discussion] 2024-01-16 19:14:41
>>klodol+bd
IIRC the changing global flags "feature" was removed recently from GCC and now you have to separately ask for it.
◧◩◪◨
8. Maulin+Ws1[view] [source] [discussion] 2024-01-16 21:03:16
>>Sharli+1i
As 1 of ∞ examples of UB land, I once had to debug JS objects being misinterpreted as numbers when https://duktape.org/ was miscompiled with a fast-math equivalent (references to objects were encoded as NaNs.)
◧◩◪◨
9. accoun+cY2[view] [source] [discussion] 2024-01-17 08:24:37
>>Wander+iC
https://github.com/gcc-mirror/gcc/blob/master/libgcc/config/...

So, yes when targeting VFP math. NEON already always works in this mode though.

[go to top]