]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
factor: remove wide_int
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 1 Jun 2025 22:51:26 +0000 (15:51 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 10 Jul 2025 00:12:39 +0000 (17:12 -0700)
* src/factor.c (wide_int): Remove, since it gets in the
way of using mp_limb_t for words.  All uses removed.
(submod2, HIGHBIT_TO_MASK, divexact_21):
Rewrite without using wide_int.
This shouldn't change the machine code these days,
as compilers are pretty smart about isolating the
top bit of an unsigned int.

src/factor.c

index cb0df9e0962d0edd9c25128a3dcf8d08b6a23058..8fec474c0eb20138c5230e8432abdabf96b2e03e 100644 (file)
    use the widest hardware-supported type.  */
 #if USE_INT128
 typedef unsigned __int128 wide_uint;
-typedef __int128 wide_int;
 # define W_TYPE_SIZE 128
 #else
 typedef uintmax_t wide_uint;
-typedef intmax_t wide_int;
 # define W_TYPE_SIZE UINTMAX_WIDTH
 #endif
 #define WIDE_UINT_MAX ((wide_uint) -1)
@@ -390,15 +388,11 @@ static void factor (wide_uint, wide_uint, struct factors *);
 #define submod2(r1, r0, a1, a0, b1, b0, n1, n0)                         \
   do {                                                                  \
     sub_ddmmss ((r1), (r0), (a1), (a0), (b1), (b0));                    \
-    if ((wide_int) (r1) < 0)                                            \
+    if ((r1) >> (W_TYPE_SIZE - 1) != 0)                                        \
       add_ssaaaa ((r1), (r0), (r1), (r0), (n1), (n0));                  \
   } while (0)
 
-#define HIGHBIT_TO_MASK(x)                                              \
-  (((wide_int)-1 >> 1) < 0                                              \
-   ? (wide_uint)((wide_int)(x) >> (W_TYPE_SIZE - 1))                    \
-   : ((x) & ((wide_uint) 1 << (W_TYPE_SIZE - 1))                        \
-      ? WIDE_UINT_MAX : (wide_uint) 0))
+#define HIGHBIT_TO_MASK(x) (- ((wide_uint) (x) >> (W_TYPE_SIZE - 1)))
 
 /* Return r = a mod d, where a = <a1,a0>, d = <d1,d0>.
    Requires that d1 != 0.  */
@@ -910,7 +904,7 @@ static const unsigned char  binvert_table[128] =
     if ((u1) >= (d))                                                    \
       {                                                                 \
         wide_uint _p1;                                                  \
-        MAYBE_UNUSED wide_int _p0;                                      \
+        MAYBE_UNUSED wide_uint _p0;                                    \
         umul_ppmm (_p1, _p0, _q0, d);                                   \
         (q1) = ((u1) - _p1) * _di;                                      \
         (q0) = _q0;                                                     \