In <https://lists.gnu.org/archive/html/bug-gnulib/2023-10/msg00060.html>
I noted that with CC="gcc -mfpmath=387" on x86_64, similar signalling
NaN problems occur as on i386. Although probably few people use this
command-line option (since it slows down the code by mixing access to
the two floating-point units), it can be worked around:


2023-10-14  Bruno Haible  <br...@clisp.org>

        snan: Avoid test failures with CC="gcc -mfpmath=387".
        * tests/test-snan-1.c (main): Treat x86_64 CPU with
        __FLT_EVAL_METHOD__ == 2 like i386 CPU. Update comments.
        * tests/test-snan-2.c (main): Likewise.

diff --git a/tests/test-snan-1.c b/tests/test-snan-1.c
index fc8fc99e31..911d20bd70 100644
--- a/tests/test-snan-1.c
+++ b/tests/test-snan-1.c
@@ -61,15 +61,13 @@ main ()
   long double volatile nanl = SNaNl ();
 
   /* Check that the values are really signalling.  */
-  /* These tests do not work on 32-bit x86 processors, although the
-     "Intel 64 and IA-32 Architectures Software Developer's Manual" and
-     "IA-32 Intel Architecture Software Developer's Manual", each in
-     sections
-       4.8.3.4 NaNs
-       4.8.3.5 Operating on SNaNs and QNaNs
-       4.8.3.6 Using SNaNs and QNaNs in Applications
-     claim that it should work.  */
-  #if !(defined __i386 || defined _M_IX86)
+  /* These tests do not work on 32-bit x86 processors, as well as
+     on x86_64 processors with CC="gcc -mfpmath=387", because loading SNaNf()
+     or SNaNd() into a 387 FPU register already converted it to a quiet NaN.
+     See <https://lists.gnu.org/archive/html/bug-gnulib/2023-10/msg00060.html>
+     for details.  */
+  #if !((defined __i386 || defined _M_IX86) \
+        || ((defined __x86_64__ || defined _M_X64) && __FLT_EVAL_METHOD__ == 
2))
   /* This test does not work on AIX 7.1 with the xlc compiler, even with
      the compiler options -qfloat=fenv -qfloat=nans -qfloat=spnans.  */
   #if !(defined _AIX && defined __xlC__)
diff --git a/tests/test-snan-2.c b/tests/test-snan-2.c
index 42927d6077..4ddd3ac9b1 100644
--- a/tests/test-snan-2.c
+++ b/tests/test-snan-2.c
@@ -65,15 +65,13 @@ main (int argc, char *argv[])
     switch (argv[1][0])
       {
       case 'f':
-        /* This test does not work on 32-bit x86 processors, although the
-           "Intel 64 and IA-32 Architectures Software Developer's Manual" and
-           "IA-32 Intel Architecture Software Developer's Manual", each in
-           sections
-             4.8.3.4 NaNs
-             4.8.3.5 Operating on SNaNs and QNaNs
-             4.8.3.6 Using SNaNs and QNaNs in Applications
-           claim that it should work.  */
-        #if !(defined __i386 || defined _M_IX86)
+        /* This test does not work on 32-bit x86 processors, as well as
+           on x86_64 processors with CC="gcc -mfpmath=387", because loading
+           SNaNf() into a 387 FPU register already converted it to a quiet NaN.
+           See 
<https://lists.gnu.org/archive/html/bug-gnulib/2023-10/msg00060.html>
+           for details.  */
+        #if !((defined __i386 || defined _M_IX86) \
+              || ((defined __x86_64__ || defined _M_X64) && 
__FLT_EVAL_METHOD__ == 2))
         /* This test does not work on AIX 7.1 with the xlc compiler, even with
            the compiler options -qfloat=fenv -qfloat=nans -qfloat=spnans.  */
         #if !(defined _AIX && defined __xlC__)
@@ -89,15 +87,13 @@ main (int argc, char *argv[])
         break;
 
       case 'd':
-        /* This test does not work on 32-bit x86 processors, although the
-           "Intel 64 and IA-32 Architectures Software Developer's Manual" and
-           "IA-32 Intel Architecture Software Developer's Manual", each in
-           sections
-             4.8.3.4 NaNs
-             4.8.3.5 Operating on SNaNs and QNaNs
-             4.8.3.6 Using SNaNs and QNaNs in Applications
-           claim that it should work.  */
-        #if !(defined __i386 || defined _M_IX86)
+        /* This test does not work on 32-bit x86 processors, as well as
+           on x86_64 processors with CC="gcc -mfpmath=387", because loading
+           SNaNd() into a 387 FPU register already converted it to a quiet NaN.
+           See 
<https://lists.gnu.org/archive/html/bug-gnulib/2023-10/msg00060.html>
+           for details.  */
+        #if !((defined __i386 || defined _M_IX86) \
+              || ((defined __x86_64__ || defined _M_X64) && 
__FLT_EVAL_METHOD__ == 2))
         resultd = nand + 42.0;
         #else
         fputs ("Skipping test: known failure on this platform\n", stderr);
@@ -125,7 +121,9 @@ main (int argc, char *argv[])
                    || ((defined __FreeBSD__ || defined __NetBSD__ || defined 
__OpenBSD__) && (defined __aarch64__ || defined __sparc__))) \
                   && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE) \
               || (defined __CYGWIN__ && defined __i386) \
-              || ((defined __i386 || defined _M_IX86) && 
HAVE_SAME_LONG_DOUBLE_AS_DOUBLE))
+              || (((defined __i386 || defined _M_IX86) \
+                   || ((defined __x86_64__ || defined _M_X64) && 
__FLT_EVAL_METHOD__ == 2)) \
+                  && HAVE_SAME_LONG_DOUBLE_AS_DOUBLE))
         resultl = nanl + 42.0L;
         #else
         fputs ("Skipping test: known failure on this platform\n", stderr);




Reply via email to