[PATCH] Inline assembly division needs __volatile__
nisse at lysator.liu.se
Wed Oct 25 18:19:10 UTC 2017
Ximin Luo <infinity0 at pwned.gg> writes:
> 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.
Ouch, that's subtle. If I may summarize: If we have code like
if (d != 0)
gcc might generate code which unconditionally evaluates the __asm__
expression, followed by code to ignore the outputs if the condition is
false. E.g., using conditional move instructions.
And that breaks if the __asm__ might raise a divide-by-zero exceptions
if the condition is false.
Adding a volatile declaration to the asm expression seems to be the
documented way to tell gcc it shouldn't do that.
Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677.
Internet email is subject to wholesale government surveillance.
More information about the gmp-bugs