Make default libc_feholdsetround_noex_ctx use __feholdexcept (bug 22702) [committed]

Message ID alpine.DEB.2.20.1801111819070.9389@digraph.polyomino.org.uk
State New
Headers show
Series
  • Make default libc_feholdsetround_noex_ctx use __feholdexcept (bug 22702) [committed]
Related show

Commit Message

Joseph Myers Jan. 11, 2018, 6:19 p.m.
For soft-float powerpc, the math/test-nearbyint-except-2 test fails
because nearbyintl traps when traps on "inexact" are enabled on entry
(and an "inexact" exception is generated internally, though cleared
for the final return).

The problem is the default implementation of
libc_feholdsetround_noex_ctx, which does not disable exception traps.
There is some ambiguity about whether the *noex* interfaces are
required to do so or only permitted to do so.  But given that we
support fe* interfaces to enable and disable traps (on architectures
with that functionality), functions that must not raise an exception
(must not leave the flag set on exit if not set on entry) should also
not trap on it when traps on that exception are enabled.  So it is
appropriate to define these interfaces to have the feholdexcept effect
of disabling exception traps; this patch updates the default
implementation and comments accordingly.

At least some architecture versions already disable traps; there are
few uses of the *noex* interfaces at all, and while it's possible
there are bugs on any architecture versions failing to disable traps
that appear in the exp2 and remainder implementations, there are
currently no tests, other than this one for nearbyintl (where only the
ldbl-128ibm implementation uses SET_RESTORE_ROUND_NOEX), that would
fail as a result of such a bug.  (Hard-float powerpc does disable
traps here, hence the nearbyintl failure not appearing there.)

Tested for powerpc (soft-float).  This brings that configuration to
clean math/ test results, provided you build with GCC 8 to get the fix
for GCC bug 64811.  Committed.

2018-01-11  Joseph Myers  <joseph@codesourcery.com>

	[BZ #22702]
	* sysdeps/generic/math_private.h (libc_feresetround_noex): Update
	comment to say exceptions are discarded.
	(libc_feholdsetround_noex_ctx): Use __feholdexcept instead of
	__fegetenv.
	(SET_RESTORE_ROUND_NOEX): Update comment to say non-stop mode must
	be enabled.

Patch

diff --git a/sysdeps/generic/math_private.h b/sysdeps/generic/math_private.h
index f29898c..e4b9d86 100644
--- a/sysdeps/generic/math_private.h
+++ b/sysdeps/generic/math_private.h
@@ -498,7 +498,7 @@  default_libc_feupdateenv_test (fenv_t *e, int ex)
 # define libc_feresetroundl libc_feupdateenvl
 #endif
 
-/* ... and a version that may also discard exceptions.  */
+/* ... and a version that also discards exceptions.  */
 
 #ifndef libc_feresetround_noex
 # define libc_feresetround_noex  libc_fesetenv
@@ -572,8 +572,9 @@  libc_feresetround_ctx (struct rm_ctx *ctx)
 static __always_inline void
 libc_feholdsetround_noex_ctx (struct rm_ctx *ctx, int round)
 {
-  /* Save exception flags and rounding mode.  */
-  __fegetenv (&ctx->env);
+  /* Save exception flags and rounding mode, and disable exception
+     traps.  */
+  __feholdexcept (&ctx->env);
 
   /* Update rounding mode only if different.  */
   if (__glibc_unlikely (round != get_rounding_mode ()))
@@ -626,7 +627,7 @@  libc_feresetround_noex_ctx (struct rm_ctx *ctx)
    the value at the start of the block.  The exception mode must be preserved.
    Exceptions raised within the block must be discarded, and exception flags
    are restored to the value at the start of the block.
-   Non-stop mode may be enabled inside the block.  */
+   Non-stop mode must be enabled inside the block.  */
 
 #define SET_RESTORE_ROUND_NOEX(RM) \
   SET_RESTORE_ROUND_GENERIC (RM, libc_feholdsetround_noex, \