Powered by RedCircle

WG21 October mailing (cont.), fast math

Mailing - 80 papers, 41 new!


New papers


Fast math flag in libraries

Brendan Dolan-Gavitt wrote an article called Someone’s Been Messing With My Subnormals!, in which he describes an intrusive nature of the GCC/Clang compiler switch -ffast-math.

TL;DR: After noticing an annoying warning, I went on an absurd yak shave, and discovered that because of a tiny handful of Python packages built with an appealing-sounding but dangerous compiler option, more than 2,500 Python packages—some with more than a million downloads per month—could end up causing any program that uses them to compute incorrect numerical results.

The discovery:

It turns out (somewhat insanely) that when -ffast-math is enabled, the compiler will link in a constructor that sets the FTZ/DAZ flags whenever the library is loaded — even on shared libraries, which means that any application that loads that library will have its floating point behavior changed for the whole process. And -Ofast, which sounds appealingly like a “make my program go fast” flag, automatically enables -ffast-math, so some projects may unwittingly turn it on without realizing the implications.

Also, apparently, if you use -Ofast, -fno-fast-math does NOT disable the auto-enabled -ffast-math! WHAAAAT

The author wrote a Python script (Gist) to check if a library was compiled with -ffast-math.

Pretty crazy. Be careful with your math compiler options.

Twitter: new tech vs. veteran

DM of Engineering:

New to tech: This will totally work.

Tech veteran: There’s no way that works.

DM of Engineering:

New to tech: I’m proud that my code worked on the first try.

Tech Veteran: I’m suspicious because my code worked on the first try.

DM of Engineering:

New to tech: This code has been running for 2 years, we should rewrite it.

Tech Veteran: This code has been running for 20 years, I’m starting to feel like maybe we’ve got the bugs out.

DM of Engineering:

New to tech: I am a magician. I create things from pure thought.

Tech Veteran: I am a plumber.