[PATCH] Inline assembly division needs __volatile__
infinity0 at pwned.gg
Wed Oct 25 11:39:00 UTC 2017
Because division assembly instructions can raise processor exceptions, these need __volatile__ annotations. Otherwise, this can result in unintended optimisations that cause spurious SIGFPEs, e.g.: https://github.com/fredrik-johansson/arb/issues/194
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82677 for details.
I've attached a tentative patch for longlong.h, but it needs review and testing! Since this code has been copied to many FOSS projects, I did not have time to test this everywhere. I only confirmed the fix works with the "divq" x86-64 instruction, on flint's copy of longlong.h, against the failing test in the github issue linked above.
However I hope that the explanation I provided on the GCC bug report makes sense, and that the fix makes sense to the GMP developers. Note in particular "Comment 9" which explains why explicit zero-checks in C code are not enough. I encourage those interested to run the attached test case as well, which is a standalone C file that needs no external libraries. (It copies the udiv_qrnnd macro from GMP, like many projects have.)
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 4127 bytes
Desc: not available
More information about the gmp-bugs