zlacker

[parent] [thread] 6 comments
1. dahart+(OP)[view] [source] 2024-01-16 15:46:14
> 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+t1 >>jcranm+56
2. mort96+t1[view] [source] 2024-01-16 15:53:07
>>dahart+(OP)
> 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+52
◧◩
3. dahart+52[view] [source] [discussion] 2024-01-16 15:55:06
>>mort96+t1
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+K3
◧◩◪
4. mort96+K3[view] [source] [discussion] 2024-01-16 16:02:17
>>dahart+52
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.

5. jcranm+56[view] [source] 2024-01-16 16:12:20
>>dahart+(OP)
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+1T2
◧◩
6. accoun+1T2[view] [source] [discussion] 2024-01-17 10:02:51
>>jcranm+56
That's only one small part of -ffast-math/-Ofast though and not a very scary one at that.
replies(1): >>mort96+lm5
◧◩◪
7. mort96+lm5[view] [source] [discussion] 2024-01-17 23:39:43
>>accoun+1T2
But it's an example of -ffast-math affecting separately compiled libraries.
[go to top]