zlacker

[parent] [thread] 8 comments
1. planed+(OP)[view] [source] 2024-01-16 15:24:50
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.
replies(2): >>london+c3 >>dahart+N5
2. london+c3[view] [source] 2024-01-16 15:37:15
>>planed+(OP)
you're gonna hive to give us a concrete real world example to convince most of us...
3. dahart+N5[view] [source] 2024-01-16 15:46:14
>>planed+(OP)
> 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?

replies(2): >>mort96+g7 >>jcranm+Sb
◧◩
4. mort96+g7[view] [source] [discussion] 2024-01-16 15:53:07
>>dahart+N5
> 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.

replies(1): >>dahart+S7
◧◩◪
5. dahart+S7[view] [source] [discussion] 2024-01-16 15:55:06
>>mort96+g7
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?
replies(1): >>mort96+x9
◧◩◪◨
6. mort96+x9[view] [source] [discussion] 2024-01-16 16:02:17
>>dahart+S7
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.

◧◩
7. jcranm+Sb[view] [source] [discussion] 2024-01-16 16:12:20
>>dahart+N5
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!

replies(1): >>accoun+OY2
◧◩◪
8. accoun+OY2[view] [source] [discussion] 2024-01-17 10:02:51
>>jcranm+Sb
That's only one small part of -ffast-math/-Ofast though and not a very scary one at that.
replies(1): >>mort96+8s5
◧◩◪◨
9. mort96+8s5[view] [source] [discussion] 2024-01-17 23:39:43
>>accoun+OY2
But it's an example of -ffast-math affecting separately compiled libraries.
[go to top]