zlacker

[return to "Std: Clamp generates less efficient assembly than std:min(max,std:max(min,v))"]
1. celega+im[view] [source] 2024-01-16 13:50:05
>>x1f604+(OP)
On gcc 13, the difference in assembly between the min(max()) version and std::clamp is eliminated when I add the -ffast-math flag. I suspect that the two implementations handle one of the arguments being NaN a bit differently.

https://gcc.godbolt.org/z/fGaP6roe9

I see the same behavior on clang 17 as well

https://gcc.godbolt.org/z/6jvnoxWhb

◧◩
2. gumby+1n[view] [source] 2024-01-16 13:54:31
>>celega+im
You (celegans25) probably know this but here is a PSA that -ffast-math is really -finaccurate-math. The knowledgeable developer will know when to use it (almost never) while the naive user will have bugs.
◧◩◪
3. mort96+kA[view] [source] 2024-01-16 15:11:52
>>gumby+1n
What you really should enable is the fun and safe math optimizations, with -funsafe-math-optimizations.
◧◩◪◨
4. aqfamn+gN[view] [source] 2024-01-16 16:06:01
>>mort96+kA
I know almost nothing about compiler flags but I got a laugh out of this even though I still don't know if you're joking or not. Edit: Just read it again and now I understand the joke. Haha
◧◩◪◨⬒
5. dekhn+NO1[view] [source] 2024-01-16 20:41:58
>>aqfamn+gN
don't forget libiberty which is linked in using -liberty (and freedom for all)
[go to top]