Live data from Hacker News

Someone’s Been Messing with My Subnormals

moyix.blogspot.com

51–60 of 132 posts

Re: Someone’s Been Messing with My Subnormals

#51
post #41

Earlier quoted context omitted.

It's not a successor, it's a derivative. And yes, if you're only targeting specific known hardware than you can and probably should optimize for it, but most distributions fully intend to be usable on very nearly any x86(_64) hardware so they can't do that.

It's also a bit less relevant when everything is so fast. I used Gentoo on a cheap-for-the-time Pentium 133MHz. Gentoo was basically the difference between a modestly pleasant system and an unusably slow system if I tried to run a standard still-compiled-for-386 distro on it. I've long since stopped worrying about it because on the systems I run, which are not top-of-the-line but aren't RPis either, it's not worth wo…

Yeah, I don't know the breakdown between better hardware and better compiler optimizations (even in the default settings) and less differentiation between processors, but I've done some minor not-very-scientific tests of compiling packages with O3/march=mtune=native and in my limited experience it wasn't particularly useful. Like, not just small benefits, but zero or below the noise floor benefits in my benchmarks. Obviously this is super dependent on your workload and maybe hardware; it's an area where if you care, you have to do your own testing.

Re: Someone’s Been Messing with My Subnormals

#52
post #29
post #21

-Ofast isn't a good name for the option, but in GCC's defense the manual is pretty clear about all this, and there's no excuse for blindly turning on compiler options - they literally change the semantics of your code.

It's a quirk of language, that for compiler writers and other algorithmic people "fast" often means "ballpark, but damn quick". It's hard to come up with a similar name that isn't long.

> It's hard to come up with a similar name that isn't long.

The suggestion given elsewhere in these comments to call it "unsafe math" instead of "fast math" sounds good. It's nearly as short, and properly conveys the "you must know what you're doing" aspect of these flags. It's even better if you're used to Rust.

Re: Someone’s Been Messing with My Subnormals

#53
post #48
post #26

Earlier quoted context omitted.

I wholeheartedly disagree. -Ofast Disregard strict standards compliance. ... There's strict standards compliance and then there's the crazy grab bag of code changes that is `-ffast-math`. Further, I'd say gevent can defensibly say that -ffast-math is okay for them given what the manual says: -ffast-math ... it can result in incorrect output for programs that depend on an exact implementation of IEEE or ISO rules/spec…

Well, how would you improve the docs? Both documentation entries seem reasonable to me. That said, I don't see why the -Ofast option even needs to exist, except backwards compatibility, as -ffast-math and the others can (and should IMO) be specified explicitly.

The fact that -ffast-math makes no mention that it will poison any other code executing in your process space is a huge missing point of info. Docs as written, anyone not doing scientific math should have that flag, but the reality is that most people have some code somewhere in their process that expects fairly sane floating point math behavior, even if it's just displaying progress bars or something.

Re: Someone’s Been Messing with My Subnormals

#54
post #48
post #26

Earlier quoted context omitted.

I wholeheartedly disagree. -Ofast Disregard strict standards compliance. ... There's strict standards compliance and then there's the crazy grab bag of code changes that is `-ffast-math`. Further, I'd say gevent can defensibly say that -ffast-math is okay for them given what the manual says: -ffast-math ... it can result in incorrect output for programs that depend on an exact implementation of IEEE or ISO rules/spec…

Well, how would you improve the docs? Both documentation entries seem reasonable to me. That said, I don't see why the -Ofast option even needs to exist, except backwards compatibility, as -ffast-math and the others can (and should IMO) be specified explicitly.

Consider the documentation for the similar compiler flag in the OpenCL specification:

> -cl-unsafe-math-optimizations

> Allow optimizations for floating-point arithmetic that (a) assume that arguments and results are valid, (b) may violate IEEE 754 standard and (c) may violate the OpenCL numerical compliance requirements as defined in section 7.4 for single-precision floating-point, section 9.3.9 for double-precision floating-point, and edge case behavior in section 7.5. This option includes the -cl-no-signed-zeros and -cl-mad-enable options.

While it stops short of saying "this will likely break your code" (maybe because it doesn't have the nonlocal effects of -ffast-math), it makes it much more clear that this flag is generally unsafe and fragile, except under rather specific circumstances. Also, it is reasonably exact about what those circumstances are. I'm not sure -ffast-math is documented with enough precision for a programmer to even know whether it will break their code. Best you can do is try and see if the program still works.

Re: Someone’s Been Messing with My Subnormals

#56
Wow, I am surprised that -ffast-math triggers a mode switch in the FPU in part due to the author's library problem, but also because the documentation for clang at least[1] does not say it impacts behaviour of denormals and in fact has a separate mode switch for that, which is not explicitly called out as being implied by -ffast-math.

[1] https://clang.llvm.org/docs/UsersManual.html#cmdoption-ffast...

Re: Someone’s Been Messing with My Subnormals

#57
post #49
post #43

Earlier quoted context omitted.

What's missing is that it also affects linking, and results in this strange action-at-a-distance. Maybe disabling the linker part with -shared would be a reasonable compromise.

You're wrong, both the doc entry for -Ofast and the one for -ffast-math say that they can result in incorrect programs . Programs are produced by linking, so I don't see what other way to interpret this is possible.

Why not simply replace all FP math with a constant zero? That’d be really fast and an equally valid strict interpretation of “can result in incorrect programs.”

Re: Someone’s Been Messing with My Subnormals

#58
post #32

At a previous company I worked at, we had an issue with our software (Windows-based, written in a proprietary language) randomly crashing. After some debugging, we found that this happened whenever the user made some specific actions, but only if, in that session, the user had previously printed something or opened a file picker. The culprit was either a printer driver or a shell extension which, when loaded, changed…

Had to deal with this same issue when I had a program supporting plugins, DLLs compiled with Delphi would turn on all the floating point traps. Took a while to track down what was causing FP faults in comctl32.dll. It got so bad that I had to put in a popup dialog that would name and shame the offending DLL so the authors would fix their broken plugins. It's an ABI violation in Windows since the ABI specifically defi…

Yep, I've encountered floating point flag incompatibilities when dynamically loading Borland-compiled libraries into Visual Studio compiled applications, as well as when using C++ code via Java Native Interface.

It is nice that diverse vendor-specific calling conventions and ABIs are less common these days.

Re: Someone’s Been Messing with My Subnormals

#59
post #48
post #26

Earlier quoted context omitted.

I wholeheartedly disagree. -Ofast Disregard strict standards compliance. ... There's strict standards compliance and then there's the crazy grab bag of code changes that is `-ffast-math`. Further, I'd say gevent can defensibly say that -ffast-math is okay for them given what the manual says: -ffast-math ... it can result in incorrect output for programs that depend on an exact implementation of IEEE or ISO rules/spec…

Well, how would you improve the docs? Both documentation entries seem reasonable to me. That said, I don't see why the -Ofast option even needs to exist, except backwards compatibility, as -ffast-math and the others can (and should IMO) be specified explicitly.

Yes, exactly: I'd deprecate it entirely. It shouldn't be a single flag.

Re: Someone’s Been Messing with My Subnormals

#60
post #32

At a previous company I worked at, we had an issue with our software (Windows-based, written in a proprietary language) randomly crashing. After some debugging, we found that this happened whenever the user made some specific actions, but only if, in that session, the user had previously printed something or opened a file picker. The culprit was either a printer driver or a shell extension which, when loaded, changed…

Had to deal with this same issue when I had a program supporting plugins, DLLs compiled with Delphi would turn on all the floating point traps. Took a while to track down what was causing FP faults in comctl32.dll. It got so bad that I had to put in a popup dialog that would name and shame the offending DLL so the authors would fix their broken plugins. It's an ABI violation in Windows since the ABI specifically defi…

I was interested in the last point about AVX instructions, and found https://john-h-k.github.io/VexTransitionPenalties.html which discusses the problem.
Post reply on HN