2025-04-14  Bruno Haible  <br...@clisp.org>

        isnanl, isfinite, snan: Improve cross-compilation guess.
        * m4/exponentl.m4 (gl_LONG_DOUBLE_EXPONENT_LOCATION): When
        cross-compiling, invoke gl_LONG_DOUBLE_VS_DOUBLE and
        gl_DOUBLE_EXPONENT_LOCATION, and guess the result depending on the CPU.
        * modules/getpayloadl (Depends-on): Add exponentd.m4, math_h.m4.
        * modules/isfinite (Depends-on): Likewise.
        * modules/isnanl (Depends-on): Likewise.
        * modules/setpayloadl (Depends-on): Likewise.
        * modules/setpayloadsigl (Depends-on): Likewise.
        * modules/isnanl-nolibm (Depends-on): Add exponentd.m4.

diff --git a/m4/exponentl.m4 b/m4/exponentl.m4
index 7e147eccee..a52e996b5e 100644
--- a/m4/exponentl.m4
+++ b/m4/exponentl.m4
@@ -1,5 +1,5 @@
 # exponentl.m4
-# serial 7
+# serial 8
 dnl Copyright (C) 2007-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -81,24 +81,94 @@ AC_DEFUN_ONCE([gl_LONG_DOUBLE_EXPONENT_LOCATION]
         [gl_cv_cc_long_double_expbit0="unknown"],
         [
           dnl When cross-compiling, in general we don't know. It depends on the
-          dnl ABI and compiler version. There are too many cases.
-          gl_cv_cc_long_double_expbit0="unknown"
-          case "$host_os" in
-            mingw* | windows*)
-              # On native Windows (little-endian), we know the result
-              # in two cases: mingw, MSVC.
-              AC_EGREP_CPP([Known], [
-#ifdef __MINGW32__
- Known
-#endif
-                ], [gl_cv_cc_long_double_expbit0="word 2 bit 0"])
-              AC_EGREP_CPP([Known], [
-#ifdef _MSC_VER
- Known
-#endif
-                ], [gl_cv_cc_long_double_expbit0="word 1 bit 20"])
-              ;;
-          esac
+          dnl ABI and compiler version. But we know the results for specific
+          dnl CPUs.
+          AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
+          if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
+            gl_DOUBLE_EXPONENT_LOCATION
+            gl_cv_cc_long_double_expbit0="$gl_cv_cc_double_expbit0"
+            if test "$gl_cv_cc_double_expbit0" = unknown; then
+              case "$host_cpu" in
+                arm*)
+                  # See the comments in exponentd.m4.
+                  ;;
+                aarch64 | sh4)
+                  # little-endian IEEE 754 double-precision
+                  gl_cv_cc_long_double_expbit0='word 1 bit 20'
+                  ;;
+                hppa*)
+                  # big-endian IEEE 754 double-precision
+                  gl_cv_cc_long_double_expbit0='word 0 bit 20'
+                  ;;
+                mips*)
+                  AC_COMPILE_IFELSE(
+                    [AC_LANG_PROGRAM([[
+                       #if defined _MIPSEB /* equivalent: __BYTE_ORDER__ == 
__ORDER_BIG_ENDIAN__ */
+                       int big;
+                       #else
+                       #error little
+                       #endif
+                       ]], [[]])
+                    ],
+                    [# big-endian IEEE 754 double-precision
+                     gl_cv_cc_long_double_expbit0='word 0 bit 20'
+                    ],
+                    [# little-endian IEEE 754 double-precision
+                     gl_cv_cc_long_double_expbit0='word 1 bit 20'
+                    ])
+                  ;;
+              esac
+            fi
+          else
+            case "$host_cpu" in
+changequote(,)dnl
+              i[34567]86 | x86_64 | ia64*)
+changequote([,])dnl
+                # 80-bits "extended precision"
+                gl_cv_cc_long_double_expbit0='word 2 bit 0'
+                ;;
+              m68k*)
+                # big-endian, 80-bits padded to 96 bits, non-IEEE exponent
+                gl_cv_cc_long_double_expbit0='word 0 bit 16'
+                ;;
+              alpha* | arm* | aarch64 | loongarch64 | riscv32 | riscv64 | sh4)
+                # little-endian IEEE 754 quadruple-precision
+                gl_cv_cc_long_double_expbit0='word 3 bit 16'
+                ;;
+              s390* | sparc | sparc64)
+                # big-endian IEEE 754 quadruple-precision
+                gl_cv_cc_long_double_expbit0='word 0 bit 16'
+                ;;
+              mips*)
+                AC_COMPILE_IFELSE(
+                  [AC_LANG_PROGRAM([[
+                     #if defined _MIPSEB /* equivalent: __BYTE_ORDER__ == 
__ORDER_BIG_ENDIAN__ */
+                     int big;
+                     #else
+                     #error little
+                     #endif
+                     ]], [[]])
+                  ],
+                  [# big-endian IEEE 754 quadruple-precision
+                   gl_cv_cc_long_double_expbit0='word 0 bit 16'
+                  ],
+                  [# little-endian IEEE 754 quadruple-precision
+                   gl_cv_cc_long_double_expbit0='word 3 bit 16'
+                  ])
+                ;;
+              powerpc64le)
+                # little-endian double-double
+                gl_cv_cc_long_double_expbit0='word 1 bit 20'
+                ;;
+              powerpc* | rs6000)
+                # big-endian double-double
+                gl_cv_cc_long_double_expbit0='word 0 bit 20'
+                ;;
+              *)
+                gl_cv_cc_long_double_expbit0="unknown"
+                ;;
+            esac
+          fi
         ])
       rm -f conftest.out
     ])
diff --git a/modules/getpayloadl b/modules/getpayloadl
index a9b93e5d8a..0274af0a52 100644
--- a/modules/getpayloadl
+++ b/modules/getpayloadl
@@ -6,6 +6,8 @@ lib/getpayloadl.c
 m4/mathfunc.m4
 m4/getpayload.m4
 m4/exponentl.m4
+m4/exponentd.m4
+m4/math_h.m4
 
 Depends-on:
 math-h
diff --git a/modules/isfinite b/modules/isfinite
index 3039a58802..68382e32a6 100644
--- a/modules/isfinite
+++ b/modules/isfinite
@@ -6,6 +6,8 @@ lib/isfinite.c
 m4/isfinite.m4
 m4/check-math-lib.m4
 m4/exponentl.m4
+m4/exponentd.m4
+m4/math_h.m4
 
 Depends-on:
 math-h
diff --git a/modules/isnanl b/modules/isnanl
index 9cee3534e2..4e0def2bb0 100644
--- a/modules/isnanl
+++ b/modules/isnanl
@@ -6,6 +6,8 @@ lib/isnanl.c
 lib/isnan.c
 lib/float+.h
 m4/exponentl.m4
+m4/exponentd.m4
+m4/math_h.m4
 m4/isnanl.m4
 
 Depends-on:
diff --git a/modules/isnanl-nolibm b/modules/isnanl-nolibm
index 2375d59318..91e23ca40b 100644
--- a/modules/isnanl-nolibm
+++ b/modules/isnanl-nolibm
@@ -7,6 +7,7 @@ lib/isnanl.c
 lib/isnan.c
 lib/float+.h
 m4/exponentl.m4
+m4/exponentd.m4
 m4/isnanl.m4
 m4/math_h.m4
 
diff --git a/modules/setpayloadl b/modules/setpayloadl
index 18dc1ee46c..f58d0f81ca 100644
--- a/modules/setpayloadl
+++ b/modules/setpayloadl
@@ -6,6 +6,8 @@ lib/setpayloadl.c
 m4/mathfunc.m4
 m4/setpayload.m4
 m4/exponentl.m4
+m4/exponentd.m4
+m4/math_h.m4
 m4/nan-mips.m4
 
 Depends-on:
diff --git a/modules/setpayloadsigl b/modules/setpayloadsigl
index 370b109fc8..1c1151a7cb 100644
--- a/modules/setpayloadsigl
+++ b/modules/setpayloadsigl
@@ -6,6 +6,8 @@ lib/setpayloadsigl.c
 m4/mathfunc.m4
 m4/setpayloadsig.m4
 m4/exponentl.m4
+m4/exponentd.m4
+m4/math_h.m4
 
 Depends-on:
 math-h




Reply via email to