x86: Do not raises floating-point exception traps on fesetexceptflag (BZ 30990)
authorBruno Haible <bruno@clisp.org>
Tue, 24 Oct 2023 11:37:16 +0000 (08:37 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 19 Dec 2023 18:12:38 +0000 (15:12 -0300)
commit787282dede7f134fdb22155cee0c35172e3e28f3
treeef7d2a333bd0cf9118f1afd3183186db07ed0513
parent47a9eeb9ba72fd30766bdf4faa7d46b8ca33a7fd
x86: Do not raises floating-point exception traps on fesetexceptflag (BZ 30990)

According to ISO C23 (7.6.4.4), fesetexcept is supposed to set
floating-point exception flags without raising a trap (unlike
feraiseexcept, which is supposed to raise a trap if feenableexcept
was called with the appropriate argument).

The flags can be set in the 387 unit or in the SSE unit.  When we need
to clear a flag, we need to do so in both units, due to the way
fetestexcept is implemented.

When we need to set a flag, it is sufficient to do it in the SSE unit,
because that is guaranteed to not trap.  However, on i386 CPUs that have
only a 387 unit, set the flags in the 387, as long as this cannot trap.

Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
math/test-fexcept-traps.c
sysdeps/i386/fpu/fsetexcptflg.c
sysdeps/x86_64/fpu/fsetexcptflg.c