Live data from Hacker News

Someone’s Been Messing with My Subnormals

moyix.blogspot.com

121–130 of 132 posts

Re: Someone’s Been Messing with My Subnormals

#121
post #16

Earlier quoted context omitted.

ChromeOS is sort of the successor to Gentoo. The images are built with profile-guided, link-time, and post-link optimization, and they are targeted to the specific CPU in a given Chromebook. Every other Linux leaves a large amount of performance on the table by targeting a common denominator CPU that's 20 years old and not having PGO.

Apple avoid this problem with their OS by having a separate architecture slice for modern x64 (Haswell+).

glibc also supports loading different libraries based on CPU capabilities and some binary distros make use of that.

Still, there are always (admittedly diminishing) returns if you can target the exact CPU you have - pretty sure no binary distro ever had variants for AMD's TBM instructions [0] but my Gentoo install made use of them (which was made absolutely clear when trying to run any of that on a Zen 2 machine lol).

[0] https://en.wikipedia.org/wiki/X86_Bit_manipulation_instructi...

Re: Someone’s Been Messing with My Subnormals

#122
post #70
post #64

Earlier quoted context omitted.

Wait, it doesn't? O.o

Nope. clang has "-Weverything", and gcc has "-Wextra", both of which go beyond "-Wall". https://stackoverflow.com/questions/11714827/how-can-i-turn-...

-Wextra is also in Clang and is definitely not everything in either compiler.

-Weverything is everything but that is only really useful to discover new warning flags (in combination with lots of -Wno...) for which you are better off reading GCC/Clang's release notes and/or documentation.

Re: Someone’s Been Messing with My Subnormals

#123

If you are willing to accept the various caveats that come with -ffast-math for your own library, then it looks like it's okay to use -ffast-math during compilation , but not during linking (because it links in crtfastmath.so, as the author points out). Your own compiled library functions will use the optimizations, but won't force the weird FPU register modes on the rest of the process.

Pay close attention to your build system though. Many will pass all compiler flags to the linker driver as that is needed to make sure that they affect LTO.

Re: Someone’s Been Messing with My Subnormals

#124
post #95
post #69

Earlier quoted context omitted.

> The fact that -ffast-math makes no mention that it will poison any other code executing in your process space Untrue. The doc entry for -ffast-math says "can result in incorrect output for programs that depend on an exact implementation of IEEE or ISO rules/specifications for math functions". Emphasis mine. So they clearly say that the entire program can turn invalid when -ffast-math is used. You and some other peo…

How many programs do you deal with daily that you don't anticipate to follow ISO/IEEE?

Most don't really care that much.

Re: Someone’s Been Messing with My Subnormals

#125
post #112

> Finally, I am legally obligated to inform you that I used GNU Parallel to scan all the wheels FWIW, this is tangential to this awesome article, but if the author is here or anyone else who cares: that statement isn’t true, you are not legally obligated to mention GNU Parallel. It is nice to do though! The link even says this explicitly, and also separately mentions the citation notice is only asking for scientific…

Just a small joke :)

Re: Someone’s Been Messing with My Subnormals

#126
post #79

Earlier quoted context omitted.

I've heard so many stories akin to this one that I just shake my head. It's a self-inflicted wound that people who prioritize performance above other considerations keep inflicting on everyone else . I hope we learned our lessons on this specific question in the design of Wasm. There are subnormals in Wasm and you can't turn them off for performance.

I think the problem is libraries implicitly affecting code outside the library. This time has been related to optimization of floating point operations, next time it will be other thing. Why bother having lexically scoped languages if the real behavior is dinamical? Debugging this kind of error is very hard

Agreed. Side-effects to global state is generally bad. It would have been not as bad to introduce the FTZ mode in a way that wasn't global state, but alas, the performance mode itself was the original sin. There is apparently zero overhead for subnormals on PPC and very little on arm. It's always been Intel pushing this crap because of their FPU designs' shortcomings.

Re: Someone’s Been Messing with My Subnormals

#127
post #50

Earlier quoted context omitted.

At least many of those are thread-local. But not C locale, it is truly horrible.

OTOH MXCSR being threadlocal means that automatically linking crtfastmath.o makes even less sense as it only affects the inital thread that loaded the object so you still need to set FTY/DAZ manually if you really want them. And implicit locales should just die. It's sad that even newer functionality like std::format relies on them. Sadder that if it didn't then you'd probably have compiler developers pulling shit li…

I thought that std::format avoided most of the implicit locale dependency. I know it has some for date formatting though.

Re: Someone’s Been Messing with My Subnormals

#128
post #73

Does this only affect pypi, or should I now worry about shared libraries shipped with my distro as well? Debian is not crazy enough to ship shared libs compiled with -ffast-math, right? RIGHT?

All right fine, I give in. In current amd64 Debian unstable (main, contrib, and non-free), 48 of the 69,112 packages include a shared library built with -ffast-math, a total of 485 .so files.

Actually it wasn't so bad :) All the current debs add up to a mere 113GB, and the .so files are just 46GB once extracted. Quick work. Here's the list:

https://moyix.net/~moyix/debian_unstable_amd64_ffast_results...

And here's a visualization of the reverse dependency graph:

https://moyix.net/~moyix/ffast_debian.pdf

Re: Someone’s Been Messing with My Subnormals

#129
post #98
post #93

In D you can opt into specific float algorithms locally rather than a compiler flag. Use of fast math can really really really bite you sometimes, so just being able to opt into using fma and nothing else is awesome.

I've measured it on real workload twice with LDC and each time "@fastMath" made things 1% slower. Of course this varies from backend to backend, but such woes would be avoided if the flag was named differently than "fast". It doesn't seem worth it to use it.

I got a good speed up in [insert work project here] but that was more of an experiment since it isn't really performance constrained in the first place.

Re: Someone’s Been Messing with My Subnormals

#130
post #73

Does this only affect pypi, or should I now worry about shared libraries shipped with my distro as well? Debian is not crazy enough to ship shared libs compiled with -ffast-math, right? RIGHT?

Various distributions have meddled with ffast-math over the years. At one stage early on, I think Clear Linux might have used it, which was part of the reason they kept demolishing distributions on benchmarks. I don't know any that still actively use it, but holy crap folks, please don't.
Post reply on HN