math: Remove clz_uint64/ctz_uint64 and use stdbit.h

Checked on aarch64-linux-gnu and x86_64-linux-gnu
Reviewed-by: Collin Funk <collin.funk1@gmail.com>
This commit is contained in:
Adhemerval Zanella 2025-09-11 14:13:22 -03:00
parent bd7b04ec7c
commit cde86de627
2 changed files with 5 additions and 22 deletions

View 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;

View 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. */
@ -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;