Re:Std: Clamp generates less efficient assembly than std:min...
by planede on Tuesday January 16, 2024 @10:24AM
(#39014261)
You can't fully disable fast-math per-library, moreover a library compiled with fast-math might also introduce inaccuracies in a seemingly unrelated library or application code in the same executable. The reason is that fast-math enables some dynamic initialization of the library that changes the floating point environment in some ways.
[ Parent
| on HN ]
Re:Std: Clamp generates less efficient assembly than std:min...
by dahart on Tuesday January 16, 2024 @10:46AM
(#39014620)
> You can’t fully disable fast-math per library
Can you elaborate? What fast-math can sneak into a library that disabled fast-math at compile time?
> fast-math enables some dynamic initialization of the library that changes the floating point environment in some ways.
I wasn’t aware of this, I would love to see some documentation discussing exactly what happens, can you send a link?
Re:Std: Clamp generates less efficient assembly than std:min...
by jcranmer on Tuesday January 16, 2024 @11:12AM
(#39014997)
https://github.com/llvm/llvm-project/issues/57589
Turn on fast-math, it flips the FTZ/DAZ bit for the entire application. Even if you turned it on for just a shared library!
Re:Std: Clamp generates less efficient assembly than std:min...
by account42 on Wednesday January 17, 2024 @05:02AM
(#39025719)
That's only one small part of -ffast-math/-Ofast though and not a very scary one at that.
Re:Std: Clamp generates less efficient assembly than std:min...
by mort96 on Wednesday January 17, 2024 @06:39PM
(#39035225)
But it's an example of -ffast-math affecting separately compiled libraries.
Re:Std: Clamp generates less efficient assembly than std:min...
by mort96 on Tuesday January 16, 2024 @10:53AM
(#39014711)
> Can you elaborate? What fast-math can sneak into a library that disabled fast-math at compile time?
A lot of library code is in headers (especially in C++!). The code in headers is compiled by your compiler using your compile options.
Re:Std: Clamp generates less efficient assembly than std:min...
by dahart on Tuesday January 16, 2024 @10:55AM
(#39014749)
Ah, of course, very good point. A header-only library doesn’t have separate compile options. This is a great reason for a float-sensitive library to not be header-only, right?
Re:Std: Clamp generates less efficient assembly than std:min...
by mort96 on Tuesday January 16, 2024 @11:02AM
(#39014852)
It's not just about being header-only, lots of libraries which aren't header-only still have code in headers. The library may choose to put certain functions in headers for performance reasons (to let compiler inline them), or, in C++, function templates and class templates generally have to be in headers.
But yeah, it's probably a good idea to not put code which breaks under -ffast-math in headers if possible.
Re:Std: Clamp generates less efficient assembly than std:min...
by londons_explore on Tuesday January 16, 2024 @10:37AM
(#39014459)
you're gonna hive to give us a concrete real world example to convince most of us...