]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Replace count_leading_zeros with stdc_leading_zeros
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 28 Oct 2025 17:08:12 +0000 (14:08 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 29 Oct 2025 15:53:55 +0000 (12:53 -0300)
Checked on x86_64-linux-gnu and aarch64-linux-gnu.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Collin Funk <collin.funk1@gmail.com>
stdlib/divmod_1.c
stdlib/mod_1.c
stdlib/strtod_l.c
sysdeps/ieee754/dbl-64/dbl2mpn.c
sysdeps/ieee754/ldbl-128/ldbl2mpn.c
sysdeps/ieee754/ldbl-128ibm/ldbl2mpn.c
sysdeps/ieee754/ldbl-96/ldbl2mpn.c
sysdeps/wordsize-32/divdi3.c
sysdeps/x86/ldbl2mpn.c

index f5030420fc4c59f0bc92fa59792f0b12fe93f59e..b91ab9e5934812022205236e2969116352db9799 100644 (file)
@@ -25,6 +25,7 @@ along with the GNU MP Library; see the file COPYING.LIB.  If not, see
 <https://www.gnu.org/licenses/>.  */
 
 #include <gmp.h>
+#include <stdbit.h>
 #include "gmp-impl.h"
 #include "longlong.h"
 
@@ -62,9 +63,7 @@ mpn_divmod_1 (mp_ptr quot_ptr,
   if (UDIV_TIME > (2 * UMUL_TIME + 6)
       && (UDIV_TIME - (2 * UMUL_TIME + 6)) * dividend_size > UDIV_TIME)
     {
-      int normalization_steps;
-
-      count_leading_zeros (normalization_steps, divisor_limb);
+      int normalization_steps = stdc_leading_zeros (divisor_limb);
       if (normalization_steps != 0)
        {
          mp_limb_t divisor_limb_inverted;
@@ -144,9 +143,7 @@ mpn_divmod_1 (mp_ptr quot_ptr,
     {
       if (UDIV_NEEDS_NORMALIZATION)
        {
-         int normalization_steps;
-
-         count_leading_zeros (normalization_steps, divisor_limb);
+         int normalization_steps = stdc_leading_zeros (divisor_limb);
          if (normalization_steps != 0)
            {
              divisor_limb <<= normalization_steps;
index a4d81d4db0bb66e4c98afaff939662a6820968ef..74c1f6a5214b4f9522c56c6fd12ad053e2acf0c5 100644 (file)
@@ -22,6 +22,7 @@ along with the GNU MP Library; see the file COPYING.LIB.  If not, see
 <https://www.gnu.org/licenses/>.  */
 
 #include <gmp.h>
+#include <stdbit.h>
 #include "gmp-impl.h"
 #include "longlong.h"
 
@@ -58,9 +59,7 @@ mpn_mod_1 (mp_srcptr dividend_ptr, mp_size_t dividend_size,
   if (UDIV_TIME > (2 * UMUL_TIME + 6)
       && (UDIV_TIME - (2 * UMUL_TIME + 6)) * dividend_size > UDIV_TIME)
     {
-      int normalization_steps;
-
-      count_leading_zeros (normalization_steps, divisor_limb);
+      int normalization_steps = stdc_leading_zeros (divisor_limb);
       if (normalization_steps != 0)
        {
          mp_limb_t divisor_limb_inverted;
@@ -137,9 +136,7 @@ mpn_mod_1 (mp_srcptr dividend_ptr, mp_size_t dividend_size,
     {
       if (UDIV_NEEDS_NORMALIZATION)
        {
-         int normalization_steps;
-
-         count_leading_zeros (normalization_steps, divisor_limb);
+         int normalization_steps = stdc_leading_zeros (divisor_limb);
          if (normalization_steps != 0)
            {
              divisor_limb <<= normalization_steps;
index f9572b9ebfdad5a2fa1927551201f35ccf9422d9..5814475e4059e5559abd77db9435093d1c076cb8 100644 (file)
@@ -72,6 +72,7 @@ extern double ____strtod_l_internal (const char *, char **, int, locale_t);
 #include <stdint.h>
 #include <rounding-mode.h>
 #include <tininess.h>
+#include <stdbit.h>
 
 /* The gmp headers need some configuration frobs.  */
 #define HAVE_ALLOCA 1
@@ -1247,7 +1248,7 @@ ____STRTOF_INTERNAL (const STRING_TYPE *nptr, STRING_TYPE **endptr, int group,
        }
 
       /* Determine how many bits of the result we already have.  */
-      count_leading_zeros (bits, num[numsize - 1]);
+      bits = stdc_leading_zeros (num[numsize - 1]);
       bits = numsize * BITS_PER_MP_LIMB - bits;
 
       /* Now we know the exponent of the number in base two.
@@ -1465,7 +1466,8 @@ ____STRTOF_INTERNAL (const STRING_TYPE *nptr, STRING_TYPE **endptr, int group,
                                       |--- n ---|
      */
 
-    count_leading_zeros (cnt, den[densize - 1]);
+    cnt = stdc_leading_zeros (den[densize - 1]);
+
 
     if (cnt > 0)
       {
@@ -1504,11 +1506,7 @@ ____STRTOF_INTERNAL (const STRING_TYPE *nptr, STRING_TYPE **endptr, int group,
 #define got_limb                                                             \
              if (bits == 0)                                                  \
                {                                                             \
-                 int cnt;                                                    \
-                 if (quot == 0)                                              \
-                   cnt = BITS_PER_MP_LIMB;                                   \
-                 else                                                        \
-                   count_leading_zeros (cnt, quot);                          \
+                 int cnt = stdc_leading_zeros (quot);                        \
                  exponent -= cnt;                                            \
                  if (BITS_PER_MP_LIMB - cnt > MANT_DIG)                      \
                    {                                                         \
index af369cd38ac87d32d468eac57c43e0114a8d84b5..d69973419b7ba098a00cfefe76948261b9a61f4d 100644 (file)
@@ -21,6 +21,7 @@
 #include <ieee754.h>
 #include <float.h>
 #include <stdlib.h>
+#include <stdbit.h>
 
 /* Convert a `double' in IEEE754 standard double-precision format to a
    multi-precision integer representing the significand scaled up by its
@@ -68,7 +69,7 @@ __mpn_extract_double (mp_ptr res_ptr, mp_size_t size,
 
          if (res_ptr[N - 1] != 0)
            {
-             count_leading_zeros (cnt, res_ptr[N - 1]);
+             cnt = stdc_leading_zeros (res_ptr[N - 1]);
              cnt -= NUM_LEADING_ZEROS;
 #if N == 2
              res_ptr[N - 1] = res_ptr[1] << cnt
@@ -82,7 +83,7 @@ __mpn_extract_double (mp_ptr res_ptr, mp_size_t size,
            }
          else
            {
-             count_leading_zeros (cnt, res_ptr[0]);
+             cnt = stdc_leading_zeros (res_ptr[0]);
              if (cnt >= NUM_LEADING_ZEROS)
                {
                  res_ptr[N - 1] = res_ptr[0] << (cnt - NUM_LEADING_ZEROS);
index 1179b1cd23ff73e356f404b46dc43f507e934da5..d3f3476d569db92202045a6caaee2146764ba775 100644 (file)
@@ -23,6 +23,7 @@
 #include <math.h>
 #include <math_private.h>
 #include <stdlib.h>
+#include <stdbit.h>
 
 /* Convert a `long double' in IEEE854 quad-precision format to a
    multi-precision integer representing the significand scaled up by its
@@ -76,7 +77,7 @@ __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size,
 #if N == 2
          if (res_ptr[N - 1] != 0)
            {
-             count_leading_zeros (cnt, res_ptr[N - 1]);
+             cnt = stdc_leading_zeros (res_ptr[N - 1]);
              cnt -= NUM_LEADING_ZEROS;
              res_ptr[N - 1] = res_ptr[N - 1] << cnt
                               | (res_ptr[0] >> (BITS_PER_MP_LIMB - cnt));
@@ -85,7 +86,7 @@ __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size,
            }
          else
            {
-             count_leading_zeros (cnt, res_ptr[0]);
+             cnt = stdc_leading_zeros (res_ptr[0]);
              if (cnt >= NUM_LEADING_ZEROS)
                {
                  res_ptr[N - 1] = res_ptr[0] << (cnt - NUM_LEADING_ZEROS);
@@ -106,7 +107,7 @@ __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size,
            if (res_ptr[j] != 0)
              break;
 
-         count_leading_zeros (cnt, res_ptr[j]);
+         cnt = stdc_leading_zeros (res_ptr[j]);
          cnt -= NUM_LEADING_ZEROS;
          l = N - 1 - j;
          if (cnt < 0)
index 795d7b45987df8d7796de13596e76003ba0e934f..d91699c3d0495cf1c095a35646c1d785736361fa 100644 (file)
@@ -22,6 +22,7 @@
 #include <float.h>
 #include <math.h>
 #include <stdlib.h>
+#include <stdbit.h>
 
 /* Convert a `long double' in IBM extended format to a multi-precision
    integer representing the significand scaled up by its number of
@@ -133,7 +134,7 @@ __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size,
 #if N == 2
          if (res_ptr[N - 1] != 0)
            {
-             count_leading_zeros (cnt, res_ptr[N - 1]);
+             cnt = stdc_leading_zeros (res_ptr[N - 1]);
              cnt -= NUM_LEADING_ZEROS;
              res_ptr[N - 1] = res_ptr[N - 1] << cnt
                               | (res_ptr[0] >> (BITS_PER_MP_LIMB - cnt));
@@ -142,7 +143,7 @@ __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size,
            }
          else
            {
-             count_leading_zeros (cnt, res_ptr[0]);
+             cnt = stdc_leading_zeros (res_ptr[0]);
              if (cnt >= NUM_LEADING_ZEROS)
                {
                  res_ptr[N - 1] = res_ptr[0] << (cnt - NUM_LEADING_ZEROS);
@@ -163,7 +164,7 @@ __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size,
            if (res_ptr[j] != 0)
              break;
 
-         count_leading_zeros (cnt, res_ptr[j]);
+         cnt = stdc_leading_zeros (res_ptr[j]);
          cnt -= NUM_LEADING_ZEROS;
          l = N - 1 - j;
          if (cnt < 0)
index 07af9791f983b09a3e0f03e9d4904a1c8500130f..982f4273803f1a517ecd1824e828661c83ffa96d 100644 (file)
@@ -22,6 +22,7 @@
 #include <float.h>
 #include <math.h>
 #include <stdlib.h>
+#include <stdbit.h>
 
 /* Convert a `long double' in IEEE854 standard double-precision format to a
    multi-precision integer representing the significand scaled up by its
@@ -67,7 +68,7 @@ __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size,
 
          if (res_ptr[N - 1] != 0)
            {
-             count_leading_zeros (cnt, res_ptr[N - 1]);
+             cnt = stdc_leading_zeros (res_ptr[N - 1]);
              if (cnt != 0)
                {
 #if N == 2
@@ -82,7 +83,7 @@ __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size,
            }
          else
            {
-             count_leading_zeros (cnt, res_ptr[0]);
+             cnt = stdc_leading_zeros (res_ptr[0]);
              res_ptr[N - 1] = res_ptr[0] << cnt;
              res_ptr[0] = 0;
              *expt = LDBL_MIN_EXP - 1 - BITS_PER_MP_LIMB - cnt;
index 015494a14f32de9f697bae9183f1587943a9a40b..387022ab14116a06afc13f9b22c75c7db459326d 100644 (file)
@@ -19,6 +19,7 @@
 #include <endian.h>
 #include <stdlib.h>
 #include <bits/wordsize.h>
+#include <stdbit.h>
 
 #if __WORDSIZE != 32
 #error This is for 32-bit targets only
@@ -113,7 +114,7 @@ __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
        {
          /* 0q = nn / 0D */
 
-         count_leading_zeros (bm, d0);
+         bm = stdc_leading_zeros (d0);
 
          if (bm != 0)
            {
@@ -137,7 +138,7 @@ __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
          if (d0 == 0)
            d0 = 1 / d0;        /* Divide intentionally by zero.  */
 
-         count_leading_zeros (bm, d0);
+         bm = stdc_leading_zeros (d0);
 
          if (bm == 0)
            {
@@ -202,7 +203,7 @@ __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
        {
          /* 0q = NN / dd */
 
-         count_leading_zeros (bm, d1);
+         bm = stdc_leading_zeros (d1);
          if (bm == 0)
            {
              /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
index d1dabab9387488b766e9cd8103d8e33cf352479a..c41fb8da147a70a514be008ca99085647845efc3 100644 (file)
@@ -21,6 +21,7 @@
 #include <ieee754.h>
 #include <float.h>
 #include <stdlib.h>
+#include <stdbit.h>
 
 /* Convert a `long double' in IEEE854 standard double-precision format to a
    multi-precision integer representing the significand scaled up by its
@@ -73,7 +74,7 @@ __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size,
 
          if (res_ptr[N - 1] != 0)
            {
-             count_leading_zeros (cnt, res_ptr[N - 1]);
+             cnt = stdc_leading_zeros (res_ptr[N - 1]);
              if (cnt != 0)
                {
 #if N == 2
@@ -88,7 +89,7 @@ __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size,
            }
          else if (res_ptr[0] != 0)
            {
-             count_leading_zeros (cnt, res_ptr[0]);
+             cnt = stdc_leading_zeros (res_ptr[0]);
              res_ptr[N - 1] = res_ptr[0] << cnt;
              res_ptr[0] = 0;
              *expt = LDBL_MIN_EXP - 1 - BITS_PER_MP_LIMB - cnt;