Live data from Hacker News

Someone’s Been Messing with My Subnormals

moyix.blogspot.com

91–100 of 132 posts

Re: Someone’s Been Messing with My Subnormals

#91
For anyone (like me) not knowing what subnormal floats are, this StackOfverflow question and answer explain it quite nicely: https://stackoverflow.com/questions/15140847/denormalized-nu...

Though they use the term denormalized, which AFAICT is the a synonym for subnormal.

Edit: Thanks for this great blogpost :)

Re: Someone’s Been Messing with My Subnormals

#92

Earlier quoted context omitted.

Anyway, since there aren't any dependencies between a, b, c, and d, I would expect the two divisions to end up basically in parallel in the pipeline. So the critical path is a division and a multiplication either way. Of course that is just a guess.

That assumes you can do multiple divisions in parallel. Back in the good old days, a single division unit was the norm, and it still is on most microcontrollers (assuming they even have hardware floating-point division[1]). Anyone have any references on how the current state of affairs on modern AMD/Intels? [1]: ARM Cortex-M4 for example can have a hardware FPU, but where division and sqrt are optional, see https://d…

It appears that Agner Fog's website is down at the moment, so we must conclude that the universe does not want to share this knowledge.

Re: Someone’s Been Messing with My Subnormals

#94

Denormalized numbers is one reason why you really want to think carefully if you try to optimize code by rewriting expressions involving multiplication and division. For example, if you got "x = (a / b) * (c / d)" one might think that rewriting it as "x = (a * c) / (b * d)" will save you a division and gain you speed. It will and it might, respectively. However it will also potentially break an otherwise safe operati…

e*ln(x) = e*(ln(a) + ln(b) - ln(c) - ln(d)) would be nice to extend to zero/negative numbers.

Re: Someone’s Been Messing with My Subnormals

#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 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.

> 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?

Re: Someone’s Been Messing with My Subnormals

#96
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.

"-Wslightly-broken-but-swift"

Re: Someone’s Been Messing with My Subnormals

#97

Denormalized numbers is one reason why you really want to think carefully if you try to optimize code by rewriting expressions involving multiplication and division. For example, if you got "x = (a / b) * (c / d)" one might think that rewriting it as "x = (a * c) / (b * d)" will save you a division and gain you speed. It will and it might, respectively. However it will also potentially break an otherwise safe operati…

Here is a really cool automatic tool that rewrites floating point expressions to be more accurate: https://herbie.uwplse.org/

Re: Someone’s Been Messing with My Subnormals

#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.

Re: Someone’s Been Messing with My Subnormals

#99
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 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.

> 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…

Me: of course I want the FUN SAFE optimization.

They: Sir, that is dash F unsafe!

Re: Someone’s Been Messing with My Subnormals

#100
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.

Naming options (or methods or projects) "fast" or "faster" is dangerous; either they're broken, or some day they'll turn out to not be fast anymore. IIRC Swift changed -Ofast to -Ounchecked after I complained about it.

-ffast-death

-fcorrupt-quietly

Post reply on HN