bug-gnulib
[Top][All Lists]
Advanced

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

totalorderl: Optimize


From: Bruno Haible
Subject: totalorderl: Optimize
Date: Wed, 04 Oct 2023 13:21:01 +0200

The variable 'bigendian' denotes whether the sign bit is in the first or
second 64-bit word of the 'long double'. But in the usual case (namely,
when not cross-compiling), the 'signbit' module already has determined at
configure time the location of the sign bit. With this knowledge, it is
possible to optimize the code somewhat.


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

        totalorderl: Optimize.
        * modules/totalorderl (Files): Add m4/signbit.m4.
        * m4/totalorder.m4 (gl_FUNC_TOTALORDERL): Invoke
        gl_LONG_DOUBLE_SIGN_LOCATION.
        * lib/totalorderl.c (totalorderl): If LDBL_SIGNBIT_WORD is known,
        use it, so that 'bigendian' becomes a constant.

diff --git a/lib/totalorderl.c b/lib/totalorderl.c
index 84fed3c4d1..cf7da088ac 100644
--- a/lib/totalorderl.c
+++ b/lib/totalorderl.c
@@ -73,8 +73,14 @@ totalorderl (long double const *x, long double const *y)
 
   /* Determine in which of the two 'unsigned long long' words the sign bit
      is located.  */
+  bool bigendian;
+#if defined LDBL_SIGNBIT_WORD
+  /* We have already determined the sign bit location at configure time.  */
+  bigendian = (LDBL_SIGNBIT_WORD < 2);
+#else
   zu.f = -zu.f;
-  bool bigendian = !!zu.i[0];
+  bigendian = !!zu.i[0];
+#endif
 
   unsigned long long
     xhi = xu.i[!bigendian] ^ extended_sign,
diff --git a/m4/totalorder.m4 b/m4/totalorder.m4
index 0bbd252675..95aab65f19 100644
--- a/m4/totalorder.m4
+++ b/m4/totalorder.m4
@@ -81,6 +81,9 @@ AC_DEFUN([gl_FUNC_TOTALORDERL]
      else
        REPLACE_TOTALORDERL=1
      fi
-     TOTALORDERL_LIBM='$(ISNANL_LIBM)'])
+     TOTALORDERL_LIBM='$(ISNANL_LIBM)'
+     dnl Prerequisite of lib/totalorderl.c.
+     gl_LONG_DOUBLE_SIGN_LOCATION
+    ])
   AC_SUBST([TOTALORDERL_LIBM])
 ])
diff --git a/modules/totalorderl b/modules/totalorderl
index d684c8c69c..ed6f801130 100644
--- a/modules/totalorderl
+++ b/modules/totalorderl
@@ -5,6 +5,7 @@ Files:
 lib/totalorderl.c
 m4/mathfunc.m4
 m4/totalorder.m4
+m4/signbit.m4
 
 Depends-on:
 math






reply via email to

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