[PATCH 3/3] math: Remove clz_uint64/ctz_uint64 and use stdbit.h
Adhemerval Zanella
adhemerval.zanella@linaro.org
Thu Sep 11 17:13:22 GMT 2025
Checked on aarch64-linux-gnu and x86_64-linux-gnu
---
sysdeps/ieee754/dbl-64/e_fmod.c | 6 +++---
sysdeps/ieee754/dbl-64/math_config.h | 21 ++-------------------
2 files changed, 5 insertions(+), 22 deletions(-)
diff --git a/sysdeps/ieee754/dbl-64/e_fmod.c b/sysdeps/ieee754/dbl-64/e_fmod.c
index 1b5453609e..9c81f83c80 100644
--- a/sysdeps/ieee754/dbl-64/e_fmod.c
+++ b/sysdeps/ieee754/dbl-64/e_fmod.c
@@ -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;
diff --git a/sysdeps/ieee754/dbl-64/math_config.h b/sysdeps/ieee754/dbl-64/math_config.h
index d9288c4fb3..99a9e8e7d3 100644
--- a/sysdeps/ieee754/dbl-64/math_config.h
+++ b/sysdeps/ieee754/dbl-64/math_config.h
@@ -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. */
@@ -43,24 +44,6 @@
# 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;
--
2.43.0
More information about the Libc-alpha
mailing list