[PATCH] Inline assembly division needs __volatile__

Ximin Luo infinity0 at pwned.gg
Wed Oct 25 12:11:00 UTC 2017

Ximin Luo:
> 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.)

Looks like I missed a few spots, here is an updated patch that should hopefully cover all the division assembly instructions.


GPG: ed25519/56034877E1F87C35
GPG: rsa4096/1318EFAC5FBBDBCE
-------------- next part --------------
A non-text attachment was scrubbed...
Name: longlong.h.patch
Type: text/x-patch
Size: 6510 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-bugs/attachments/20171025/df52dce5/attachment.bin>

More information about the gmp-bugs mailing list