bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

fenv-exceptions-tracking-c99: Fix fetestexcept() override for AIX


From: Bruno Haible
Subject: fenv-exceptions-tracking-c99: Fix fetestexcept() override for AIX
Date: Sat, 04 Nov 2023 15:36:45 +0100

On AIX, when I force the inclusion of the fetestexcept() override, through
an added
  REPLACE_FETESTEXCEPT=1
in the *.m4 files, and use a gcc-compatible compiler, I see unit test failures:

  ../../gltests/test-fenv-except-state-3.c:56: assertion 'fetestexcept 
(FE_INVALID) == FE_INVALID' failed
  FAIL test-fenv-except-state-3 (exit status: 134)

  ../../gltests/test-fenv-except-state-1.c:47: assertion 'fetestexcept 
(FE_INVALID) == FE_INVALID' failed
  FAIL test-fenv-except-state-1 (exit status: 134)

  ../../gltests/test-fenv-except-tracking-1.c:41: assertion 'fetestexcept 
(FE_ALL_EXCEPT) == FE_ALL_EXCEPT || fetestexcept (FE_ALL_EXCEPT) == 
(FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)' failed
  FAIL test-fenv-except-tracking-1 (exit status: 134)

This patch fixes it.  Although this code is not used by default, it's worth
having the correct code committed, rather than a buggy one.


2023-11-04  Bruno Haible  <bruno@clisp.org>

        fenv-exceptions-tracking-c99: Fix fetestexcept() override for AIX.
        * lib/fenv-except-tracking-test.c (fetestexcept): On AIX, use
        fp_read_flag() rather than the fpscr register.

diff --git a/lib/fenv-except-tracking-test.c b/lib/fenv-except-tracking-test.c
index efb9baa9ae..5f6bd7d8b2 100644
--- a/lib/fenv-except-tracking-test.c
+++ b/lib/fenv-except-tracking-test.c
@@ -24,7 +24,26 @@
 
 #include "fenv-private.h"
 
-#if defined __GNUC__ || defined __clang__ || defined _MSC_VER
+#if defined _AIX && defined __powerpc__ /* AIX */
+
+/* On AIX, the register fpscr is augmented with a 32-bit word named fpscrx
+   in thread-local storage.  Instead of accessing fpscr, we must access the
+   combination.  The function fp_read_flag() does this.  */
+
+# include <float.h>
+# include <fpxcp.h>
+
+/* Documentation:
+   
<https://www.ibm.com/docs/en/aix/7.3?topic=f-fp-clr-flag-fp-set-flag-fp-read-flag-fp-swap-flag-subroutine>
  */
+
+int
+fetestexcept (int exceptions)
+{
+  fpflag_t flags = fp_read_flag ();
+  return fpflag_to_exceptions (flags) & FE_ALL_EXCEPT & exceptions;
+}
+
+#elif defined __GNUC__ || defined __clang__ || defined _MSC_VER
 
 # if (defined __x86_64__ || defined _M_X64) || (defined __i386 || defined 
_M_IX86)
 
@@ -230,21 +249,6 @@ fetestexcept (int exceptions)
   return flags & FE_ALL_EXCEPT & exceptions;
 }
 
-# elif defined _AIX && defined __powerpc__ /* AIX */
-
-#  include <float.h>
-#  include <fpxcp.h>
-
-/* Documentation:
-   
<https://www.ibm.com/docs/en/aix/7.3?topic=f-fp-clr-flag-fp-set-flag-fp-read-flag-fp-swap-flag-subroutine>
  */
-
-int
-fetestexcept (int exceptions)
-{
-  fpflag_t flags = fp_read_flag ();
-  return fpflag_to_exceptions (flags) & FE_ALL_EXCEPT & exceptions;
-}
-
 # else
 
 #  define NEED_FALLBACK 1






reply via email to

[Prev in Thread] Current Thread [Next in Thread]