[PATCH] Inline assembly division needs __volatile__

Ximin Luo infinity0 at pwned.gg
Mon Nov 6 10:53:00 UTC 2017


Niels Möller:
> 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)
>     __asm__ (...);
> 
> 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.
> 

Yes that's correct, as far as I understood of the situation anyway.

Any chance my patch could be tested and merged? I did not ask other projects' opinions on this yet, since they seemed to have copied the code from GMP. Could you confirm that GMP is the original source?

X

-- 
GPG: ed25519/56034877E1F87C35
GPG: rsa4096/1318EFAC5FBBDBCE
https://github.com/infinity0/pubkeys.git


More information about the gmp-bugs mailing list