On all MIPS machines that I had tested Gnulib on, the nan-mips.m4 configure
test reported:

  checking whether the NaN float encoding is IEEE 754-2008 compliant... no
  checking whether the NaN double encoding is IEEE 754-2008 compliant... no
  checking whether the NaN long double encoding is IEEE 754-2008 compliant... no

On the OpenBSD/mips machine of the GCC compilefarm, however, it reports:

  checking whether the NaN float encoding is IEEE 754-2008 compliant... no
  checking whether the NaN double encoding is IEEE 754-2008 compliant... no
  checking whether the NaN long double encoding is IEEE 754-2008 compliant... 
yes

Which means that the "NaN is signalling" bit on 'long double' values is like
on most other CPU types. And the code that inverts that bit, conditionalized
with 'defined __mips__', causes test failures on this machine.

This set of patches fixes it.


2024-04-18  Bruno Haible  <br...@clisp.org>

        setpayloadsig*: Support newer MIPS CPUs.
        * lib/setpayloadsig.c (setpayloadsig): On MIPS CPUs with 
MIPS_NAN2008_DOUBLE,
        reject a zero payload.
        * lib/setpayloadsigf.c (setpayloadsigf): On MIPS CPUs with 
MIPS_NAN2008_FLOAT,
        reject a zero payload.
        * lib/setpayloadsigl.c (setpayloadsigl): On MIPS CPUs with
        MIPS_NAN2008_LONG_DOUBLE, reject a zero payload.

2024-04-18  Bruno Haible  <br...@clisp.org>

        setpayload*: Support newer MIPS CPUs.
        * lib/setpayload.c (setpayload): On MIPS CPUs with MIPS_NAN2008_DOUBLE,
        accept a zero payload.
        * lib/setpayloadf.c (setpayloadf): On MIPS CPUs with MIPS_NAN2008_FLOAT,
        accept a zero payload.
        * lib/setpayloadl.c (setpayloadl): On MIPS CPUs with
        MIPS_NAN2008_LONG_DOUBLE, accept a zero payload.
        * m4/setpayload.m4 (gl_FUNC_SETPAYLOADF, gl_FUNC_SETPAYLOAD,
        gl_FUNC_SETPAYLOADL): Invoke gl_NAN_MIPS.
        * modules/setpayload (Files): Add m4/nan-mips.m4.
        * modules/setpayloadf (Files): Likewise.
        * modules/setpayloadl (Files): Likewise.

2024-04-18  Bruno Haible  <br...@clisp.org>

        totalorder*: Support newer MIPS CPUs.
        * lib/totalorder.c (totalorder): On MIPS CPUs with MIPS_NAN2008_DOUBLE,
        don't invert the most significant bit of the mantissa field.
        * lib/totalorderf.c (totalorderf): On MIPS CPUs with MIPS_NAN2008_FLOAT,
        don't invert the most significant bit of the mantissa field.
        * lib/totalorderl.c (totalorderl): On MIPS CPUs with
        MIPS_NAN2008_LONG_DOUBLE, don't invert the most significant bit of the
        mantissa field.
        * m4/totalorder.m4 (gl_FUNC_TOTALORDERF, gl_FUNC_TOTALORDER,
        gl_FUNC_TOTALORDERL): Invoke gl_NAN_MIPS.
        * modules/totalorder (Files): Add m4/nan-mips.m4.
        * modules/totalorderf (Files): Likewise.
        * modules/totalorderl (Files): Likewise.

>From a42a02ac22aa41ff9222e9e46ede25f8cf43b823 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Fri, 19 Apr 2024 02:14:37 +0200
Subject: [PATCH 1/3] totalorder*: Support newer MIPS CPUs.

* lib/totalorder.c (totalorder): On MIPS CPUs with MIPS_NAN2008_DOUBLE,
don't invert the most significant bit of the mantissa field.
* lib/totalorderf.c (totalorderf): On MIPS CPUs with MIPS_NAN2008_FLOAT,
don't invert the most significant bit of the mantissa field.
* lib/totalorderl.c (totalorderl): On MIPS CPUs with
MIPS_NAN2008_LONG_DOUBLE, don't invert the most significant bit of the
mantissa field.
* m4/totalorder.m4 (gl_FUNC_TOTALORDERF, gl_FUNC_TOTALORDER,
gl_FUNC_TOTALORDERL): Invoke gl_NAN_MIPS.
* modules/totalorder (Files): Add m4/nan-mips.m4.
* modules/totalorderf (Files): Likewise.
* modules/totalorderl (Files): Likewise.
---
 ChangeLog           | 16 ++++++++++++++++
 lib/totalorder.c    |  2 +-
 lib/totalorderf.c   |  2 +-
 lib/totalorderl.c   |  2 +-
 m4/totalorder.m4    |  7 ++++++-
 modules/totalorder  |  1 +
 modules/totalorderf |  1 +
 modules/totalorderl |  1 +
 8 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3fe1847897..825968df32 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2024-04-18  Bruno Haible  <br...@clisp.org>
+
+	totalorder*: Support newer MIPS CPUs.
+	* lib/totalorder.c (totalorder): On MIPS CPUs with MIPS_NAN2008_DOUBLE,
+	don't invert the most significant bit of the mantissa field.
+	* lib/totalorderf.c (totalorderf): On MIPS CPUs with MIPS_NAN2008_FLOAT,
+	don't invert the most significant bit of the mantissa field.
+	* lib/totalorderl.c (totalorderl): On MIPS CPUs with
+	MIPS_NAN2008_LONG_DOUBLE, don't invert the most significant bit of the
+	mantissa field.
+	* m4/totalorder.m4 (gl_FUNC_TOTALORDERF, gl_FUNC_TOTALORDER,
+	gl_FUNC_TOTALORDERL): Invoke gl_NAN_MIPS.
+	* modules/totalorder (Files): Add m4/nan-mips.m4.
+	* modules/totalorderf (Files): Likewise.
+	* modules/totalorderl (Files): Likewise.
+
 2024-04-18  Bruno Haible  <br...@clisp.org>
 
 	snan: Add support for m68k.
diff --git a/lib/totalorder.c b/lib/totalorder.c
index 445b8f84d6..6d1b2c4444 100644
--- a/lib/totalorder.c
+++ b/lib/totalorder.c
@@ -48,7 +48,7 @@ totalorder (double const *x, double const *y)
   /* At this point, *X and *Y are NaNs with the same sign bit.  */
 
   unsigned long long extended_sign = -!!xs;
-#if defined __hppa || defined __mips__ || defined __sh__
+#if defined __hppa || (defined __mips__ && !MIPS_NAN2008_DOUBLE) || defined __sh__
   /* Invert the most significant bit of the mantissa field.  Cf. snan.h.  */
   extended_sign ^= (1ULL << 51);
 #endif
diff --git a/lib/totalorderf.c b/lib/totalorderf.c
index 70bc02cd90..f8af4b0241 100644
--- a/lib/totalorderf.c
+++ b/lib/totalorderf.c
@@ -48,7 +48,7 @@ totalorderf (float const *x, float const *y)
   /* At this point, *X and *Y are NaNs with the same sign bit.  */
 
   unsigned int extended_sign = -!!xs;
-#if defined __hppa || defined __mips__ || defined __sh__
+#if defined __hppa || (defined __mips__ && !MIPS_NAN2008_FLOAT) || defined __sh__
   /* Invert the most significant bit of the mantissa field.  Cf. snan.h.  */
   extended_sign ^= (1U << 22);
 #endif
diff --git a/lib/totalorderl.c b/lib/totalorderl.c
index 4ccb7e7e23..21669f4af8 100644
--- a/lib/totalorderl.c
+++ b/lib/totalorderl.c
@@ -63,7 +63,7 @@ totalorderl (long double const *x, long double const *y)
 
   unsigned long long extended_sign = -!!xs;
   unsigned long long extended_sign_hi = extended_sign;
-# if defined __hppa || defined __mips__ || defined __sh__
+# if defined __hppa || (defined __mips__ && !MIPS_NAN2008_LONG_DOUBLE) || defined __sh__
   /* Invert the most significant bit of the mantissa field.  Cf. snan.h.  */
   extended_sign_hi ^=
     (1ULL << (LDBL_MANT_DIG == 106
diff --git a/m4/totalorder.m4 b/m4/totalorder.m4
index 51012b8503..72921d6357 100644
--- a/m4/totalorder.m4
+++ b/m4/totalorder.m4
@@ -1,5 +1,5 @@
 # totalorder.m4
-# serial 2
+# serial 3
 dnl Copyright 2023-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -39,6 +39,8 @@ AC_DEFUN([gl_FUNC_TOTALORDERF]
   fi
   if test $HAVE_TOTALORDERF = 0 || test $REPLACE_TOTALORDERF = 1; then
     TOTALORDERF_LIBM='$(ISNANF_LIBM)'
+    dnl Prerequisite of lib/totalorderf.c.
+    gl_NAN_MIPS
   fi
   AC_SUBST([TOTALORDERF_LIBM])
 ])
@@ -77,6 +79,8 @@ AC_DEFUN([gl_FUNC_TOTALORDER]
   fi
   if test $HAVE_TOTALORDER = 0 || test $REPLACE_TOTALORDER = 1; then
     TOTALORDER_LIBM='$(ISNAND_LIBM)'
+    dnl Prerequisite of lib/totalorder.c.
+    gl_NAN_MIPS
   fi
   AC_SUBST([TOTALORDER_LIBM])
 ])
@@ -125,6 +129,7 @@ AC_DEFUN([gl_FUNC_TOTALORDERL]
     fi
     dnl Prerequisite of lib/totalorderl.c.
     gl_LONG_DOUBLE_SIGN_LOCATION
+    gl_NAN_MIPS
   fi
   AC_SUBST([TOTALORDERL_LIBM])
 ])
diff --git a/modules/totalorder b/modules/totalorder
index 00f190c42e..d21708e44e 100644
--- a/modules/totalorder
+++ b/modules/totalorder
@@ -5,6 +5,7 @@ Files:
 lib/totalorder.c
 m4/mathfunc.m4
 m4/totalorder.m4
+m4/nan-mips.m4
 
 Depends-on:
 math
diff --git a/modules/totalorderf b/modules/totalorderf
index ab1569c9cc..7125c8a57c 100644
--- a/modules/totalorderf
+++ b/modules/totalorderf
@@ -5,6 +5,7 @@ Files:
 lib/totalorderf.c
 m4/mathfunc.m4
 m4/totalorder.m4
+m4/nan-mips.m4
 
 Depends-on:
 math
diff --git a/modules/totalorderl b/modules/totalorderl
index d153f4c8cc..46452842af 100644
--- a/modules/totalorderl
+++ b/modules/totalorderl
@@ -5,6 +5,7 @@ Files:
 lib/totalorderl.c
 m4/mathfunc.m4
 m4/totalorder.m4
+m4/nan-mips.m4
 m4/signbit.m4
 
 Depends-on:
-- 
2.34.1

>From dbc692b76b57f7441261cf702709380349455175 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Fri, 19 Apr 2024 02:14:41 +0200
Subject: [PATCH 2/3] setpayload*: Support newer MIPS CPUs.

* lib/setpayload.c (setpayload): On MIPS CPUs with MIPS_NAN2008_DOUBLE,
accept a zero payload.
* lib/setpayloadf.c (setpayloadf): On MIPS CPUs with MIPS_NAN2008_FLOAT,
accept a zero payload.
* lib/setpayloadl.c (setpayloadl): On MIPS CPUs with
MIPS_NAN2008_LONG_DOUBLE, accept a zero payload.
* m4/setpayload.m4 (gl_FUNC_SETPAYLOADF, gl_FUNC_SETPAYLOAD,
gl_FUNC_SETPAYLOADL): Invoke gl_NAN_MIPS.
* modules/setpayload (Files): Add m4/nan-mips.m4.
* modules/setpayloadf (Files): Likewise.
* modules/setpayloadl (Files): Likewise.
---
 ChangeLog           | 15 +++++++++++++++
 lib/setpayload.c    |  2 +-
 lib/setpayloadf.c   |  2 +-
 lib/setpayloadl.c   |  2 +-
 m4/setpayload.m4    |  7 ++++++-
 modules/setpayload  |  1 +
 modules/setpayloadf |  1 +
 modules/setpayloadl |  1 +
 8 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 825968df32..b3c806d91c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2024-04-18  Bruno Haible  <br...@clisp.org>
+
+	setpayload*: Support newer MIPS CPUs.
+	* lib/setpayload.c (setpayload): On MIPS CPUs with MIPS_NAN2008_DOUBLE,
+	accept a zero payload.
+	* lib/setpayloadf.c (setpayloadf): On MIPS CPUs with MIPS_NAN2008_FLOAT,
+	accept a zero payload.
+	* lib/setpayloadl.c (setpayloadl): On MIPS CPUs with
+	MIPS_NAN2008_LONG_DOUBLE, accept a zero payload.
+	* m4/setpayload.m4 (gl_FUNC_SETPAYLOADF, gl_FUNC_SETPAYLOAD,
+	gl_FUNC_SETPAYLOADL): Invoke gl_NAN_MIPS.
+	* modules/setpayload (Files): Add m4/nan-mips.m4.
+	* modules/setpayloadf (Files): Likewise.
+	* modules/setpayloadl (Files): Likewise.
+
 2024-04-18  Bruno Haible  <br...@clisp.org>
 
 	totalorder*: Support newer MIPS CPUs.
diff --git a/lib/setpayload.c b/lib/setpayload.c
index fa5c7ad866..d4744ee827 100644
--- a/lib/setpayload.c
+++ b/lib/setpayload.c
@@ -31,7 +31,7 @@ setpayload (double *result, double payload)
 {
 #if DBL_MANT_DIG == 53
   if (
-# if defined __hppa || defined __mips__ || defined __sh__
+# if defined __hppa || (defined __mips__ && !MIPS_NAN2008_DOUBLE) || defined __sh__
       /* A zero payload is not allowed, because that would denote Infinity.
          Cf. snan.h.  */
       payload > 0.0
diff --git a/lib/setpayloadf.c b/lib/setpayloadf.c
index 1f02bc4593..40b66dfa9b 100644
--- a/lib/setpayloadf.c
+++ b/lib/setpayloadf.c
@@ -31,7 +31,7 @@ setpayloadf (float *result, float payload)
 {
 #if FLT_MANT_DIG == 24
   if (
-# if defined __hppa || defined __mips__ || defined __sh__
+# if defined __hppa || (defined __mips__ && !MIPS_NAN2008_FLOAT) || defined __sh__
       /* A zero payload is not allowed, because that would denote Infinity.
          Cf. snan.h.  */
       payload > 0.0f
diff --git a/lib/setpayloadl.c b/lib/setpayloadl.c
index 6b5a1e24df..d7d0469e38 100644
--- a/lib/setpayloadl.c
+++ b/lib/setpayloadl.c
@@ -50,7 +50,7 @@ setpayloadl (long double *result, long double payload)
 # if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 106 || LDBL_MANT_DIG == 113) \
      && defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT
   if (
-#  if defined __hppa || defined __mips__ || defined __sh__
+#  if defined __hppa || (defined __mips__ && !MIPS_NAN2008_LONG_DOUBLE) || defined __sh__
       /* A zero payload is not allowed, because that would denote Infinity.
          Cf. snan.h.  */
       payload > 0.0L
diff --git a/m4/setpayload.m4 b/m4/setpayload.m4
index 5238dd0de5..c1d6ec9244 100644
--- a/m4/setpayload.m4
+++ b/m4/setpayload.m4
@@ -1,5 +1,5 @@
 # setpayload.m4
-# serial 1
+# serial 2
 dnl Copyright 2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -17,6 +17,8 @@ AC_DEFUN([gl_FUNC_SETPAYLOADF]
   fi
   if test $HAVE_SETPAYLOADF = 0; then
     SETPAYLOADF_LIBM=
+    dnl Prerequisite of lib/setpayloadf.c.
+    gl_NAN_MIPS
   fi
   AC_SUBST([SETPAYLOADF_LIBM])
 ])
@@ -33,6 +35,8 @@ AC_DEFUN_ONCE([gl_FUNC_SETPAYLOAD]
   fi
   if test $HAVE_SETPAYLOAD = 0; then
     SETPAYLOAD_LIBM=
+    dnl Prerequisite of lib/setpayload.c.
+    gl_NAN_MIPS
   fi
   AC_SUBST([SETPAYLOAD_LIBM])
 ])
@@ -58,6 +62,7 @@ AC_DEFUN([gl_FUNC_SETPAYLOADL]
     fi
     dnl Prerequisite of lib/setpayloadl.c.
     gl_LONG_DOUBLE_EXPONENT_LOCATION
+    gl_NAN_MIPS
   fi
   AC_SUBST([SETPAYLOADL_LIBM])
 ])
diff --git a/modules/setpayload b/modules/setpayload
index 677335a3ae..0a5cda2eb8 100644
--- a/modules/setpayload
+++ b/modules/setpayload
@@ -5,6 +5,7 @@ Files:
 lib/setpayload.c
 m4/mathfunc.m4
 m4/setpayload.m4
+m4/nan-mips.m4
 
 Depends-on:
 math
diff --git a/modules/setpayloadf b/modules/setpayloadf
index 05856e62da..e26f1f8be2 100644
--- a/modules/setpayloadf
+++ b/modules/setpayloadf
@@ -5,6 +5,7 @@ Files:
 lib/setpayloadf.c
 m4/mathfunc.m4
 m4/setpayload.m4
+m4/nan-mips.m4
 
 Depends-on:
 math
diff --git a/modules/setpayloadl b/modules/setpayloadl
index 0a94431d5d..2d058f672b 100644
--- a/modules/setpayloadl
+++ b/modules/setpayloadl
@@ -6,6 +6,7 @@ lib/setpayloadl.c
 m4/mathfunc.m4
 m4/setpayload.m4
 m4/exponentl.m4
+m4/nan-mips.m4
 
 Depends-on:
 math
-- 
2.34.1

>From 8178a7d30b7a560f1196a2628d2ec2e01178e1a7 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Fri, 19 Apr 2024 02:14:45 +0200
Subject: [PATCH 3/3] setpayloadsig*: Support newer MIPS CPUs.

* lib/setpayloadsig.c (setpayloadsig): On MIPS CPUs with MIPS_NAN2008_DOUBLE,
reject a zero payload.
* lib/setpayloadsigf.c (setpayloadsigf): On MIPS CPUs with MIPS_NAN2008_FLOAT,
reject a zero payload.
* lib/setpayloadsigl.c (setpayloadsigl): On MIPS CPUs with
MIPS_NAN2008_LONG_DOUBLE, reject a zero payload.
---
 ChangeLog            | 10 ++++++++++
 lib/setpayloadsig.c  |  2 +-
 lib/setpayloadsigf.c |  2 +-
 lib/setpayloadsigl.c |  2 +-
 4 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b3c806d91c..8c90a81e0a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-04-18  Bruno Haible  <br...@clisp.org>
+
+	setpayloadsig*: Support newer MIPS CPUs.
+	* lib/setpayloadsig.c (setpayloadsig): On MIPS CPUs with MIPS_NAN2008_DOUBLE,
+	reject a zero payload.
+	* lib/setpayloadsigf.c (setpayloadsigf): On MIPS CPUs with MIPS_NAN2008_FLOAT,
+	reject a zero payload.
+	* lib/setpayloadsigl.c (setpayloadsigl): On MIPS CPUs with
+	MIPS_NAN2008_LONG_DOUBLE, reject a zero payload.
+
 2024-04-18  Bruno Haible  <br...@clisp.org>
 
 	setpayload*: Support newer MIPS CPUs.
diff --git a/lib/setpayloadsig.c b/lib/setpayloadsig.c
index c336f08c80..e9036dab86 100644
--- a/lib/setpayloadsig.c
+++ b/lib/setpayloadsig.c
@@ -32,7 +32,7 @@ setpayloadsig (double *result, double payload)
 {
 #if DBL_MANT_DIG == 53
   if (
-# if defined __hppa || defined __mips__ || defined __sh__
+# if defined __hppa || (defined __mips__ && !MIPS_NAN2008_DOUBLE) || defined __sh__
       payload >= 0.0
 # else
       /* A zero payload is not allowed, because that would denote Infinity.
diff --git a/lib/setpayloadsigf.c b/lib/setpayloadsigf.c
index 0f41f9f3df..aa92afa495 100644
--- a/lib/setpayloadsigf.c
+++ b/lib/setpayloadsigf.c
@@ -32,7 +32,7 @@ setpayloadsigf (float *result, float payload)
 {
 #if FLT_MANT_DIG == 24
   if (
-# if defined __hppa || defined __mips__ || defined __sh__
+# if defined __hppa || (defined __mips__ && !MIPS_NAN2008_FLOAT) || defined __sh__
       payload >= 0.0f
 # else
       /* A zero payload is not allowed, because that would denote Infinity.
diff --git a/lib/setpayloadsigl.c b/lib/setpayloadsigl.c
index 5cfe3cb783..752d158401 100644
--- a/lib/setpayloadsigl.c
+++ b/lib/setpayloadsigl.c
@@ -49,7 +49,7 @@ setpayloadsigl (long double *result, long double payload)
 # if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 106 || LDBL_MANT_DIG == 113) \
      && defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT
   if (
-#  if defined __hppa || defined __mips__ || defined __sh__
+#  if defined __hppa || (defined __mips__ && !MIPS_NAN2008_LONG_DOUBLE) || defined __sh__
       payload >= 0.0L
 #  else
       /* A zero payload is not allowed, because that would denote Infinity.
-- 
2.34.1

Reply via email to