]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
math: Remove clz_uint64/ctz_uint64 and use stdbit.h
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 11 Sep 2025 17:13:22 +0000 (14:13 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 11 Sep 2025 17:47:25 +0000 (14:47 -0300)
Checked on aarch64-linux-gnu and x86_64-linux-gnu
Reviewed-by: Collin Funk <collin.funk1@gmail.com>
sysdeps/ieee754/dbl-64/e_fmod.c
sysdeps/ieee754/dbl-64/math_config.h

index 1b5453609e8267f5dc97ed2599340bfd1876de0a..9c81f83c8065847984a25e89ea25853d9027a0b0 100644 (file)
@@ -98,7 +98,7 @@ __fmod (double x, double y)
 
       if (__glibc_unlikely (mx == 0))
        return asdouble (sx);
-      int shift = clz_uint64 (mx);
+      int shift = stdc_leading_zeros (mx);
       ex -= shift + 1;
       mx <<= shift;
       mx = sx | (mx >> EXPONENT_WIDTH);
@@ -131,10 +131,10 @@ __fmod (double x, double y)
       my = hy;
       ey = 0;
       exp_diff--;
-      lead_zeros_my = clz_uint64 (my);
+      lead_zeros_my = stdc_leading_zeros (my);
     }
 
-  int tail_zeros_my = ctz_uint64 (my);
+  int tail_zeros_my = stdc_trailing_zeros (my);
   int sides_zeroes = lead_zeros_my + tail_zeros_my;
 
   int right_shift = exp_diff < tail_zeros_my ? exp_diff : tail_zeros_my;
index d9288c4fb391aec3bb70409439ab268f38519fe6..99a9e8e7d36bd23c637b91ad1fc5e9fdd2f4c985 100644 (file)
@@ -23,6 +23,7 @@
 #include <math_private.h>
 #include <nan-high-order-bit.h>
 #include <stdint.h>
+#include <stdbit.h>
 
 #ifndef WANT_ROUNDING
 /* Correct special case results in non-nearest rounding modes.  */
 # define TOINT_INTRINSICS 0
 #endif
 
-static inline int
-clz_uint64 (uint64_t x)
-{
-  if (sizeof (uint64_t) == sizeof (unsigned long))
-    return __builtin_clzl (x);
-  else
-    return __builtin_clzll (x);
-}
-
-static inline int
-ctz_uint64 (uint64_t x)
-{
-  if (sizeof (uint64_t) == sizeof (unsigned long))
-    return __builtin_ctzl (x);
-  else
-    return __builtin_ctzll (x);
-}
-
 #if TOINT_INTRINSICS
 /* Round x to nearest int in all rounding modes, ties have to be rounded
    consistently with converttoint so the results match.  If the result
@@ -148,7 +131,7 @@ get_exponent (uint64_t x)
 static inline double
 make_double (uint64_t x, int64_t ep, uint64_t s)
 {
-  int lz = clz_uint64 (x) - EXPONENT_WIDTH;
+  int lz = stdc_leading_zeros (x) - EXPONENT_WIDTH;
   x <<= lz;
   ep -= lz;