[cctbxbb] Trapping NaN or not trapping NaN

Luc Bourhis luc_j_bourhis at mac.com
Sat Apr 9 16:38:08 PDT 2016

Richard and I have been hammering at our build system and code to try to solve several crashes on OS X with Xcode 7.3. Several of them came from the fact that we trap NaN whereas Xcode 7.3 aggressive optimisations produce code that may create a NaN but still deliver the correct final result. A trivial example came from cctbx/xray/conversions.h. We have

if (f_sq > 0) f = std::sqrt(f_sq);
else f = 0;

With the version of clang shipping with Xcode 7.3, both branches are evaluated in parallel before selecting the result based on the test f_sq > 0. This is done so as not to stall the pipeline and this can result in much faster code indeed. But that means that every time f_sq < 0, a NaN will be produced, and in the context of our tests, this means we crash.

Richard and I avoided the elephant in the room, stop to trap NaN, and as a result came with uglier and uglier fixes. Moreover, we are now at the mercy of the compiler applying such an optimisation to another file at the next update of Xcode, which would then force us to fix the compilation of said file in the relevant SConscript. It’s a loosing game.

Thus I reckon that at least on OS X, we should stop trapping NaN.

That will leave us with the true clang regression for which I will try to submit reduced cases to the clang bugzilla.

Best wishes,


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://phenix-online.org/pipermail/cctbxbb/attachments/20160410/df040497/attachment.htm>

More information about the cctbxbb mailing list