]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
factor: redo ge2 in terms of lt2
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 6 Jul 2025 05:12:22 +0000 (22:12 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 10 Jul 2025 00:12:40 +0000 (17:12 -0700)
lt2 a bit more natural, given the current implementation.
* src/factor.c (lt2): New function.
(ge2): Rewrite in terms of lt2.
(gt2): Remove.  All callers changed to use lt2.

src/factor.c

index 96ef8e828766320851f52897e6e8e936cbe2a68d..850e32a59db7c9322c56b647c98ceda76d5d8be6 100644 (file)
@@ -390,24 +390,21 @@ static mp_limb_t __ll_highpart (mp_limb_t t) { return t >> (W_TYPE_SIZE / 2); }
     (rl) = (al) << (cnt);                                               \
   } while (0)
 
-/* (ah,hl) >= (bh,bl)?  */
+/* (ah,hl) < (bh,bl)?  */
 static bool
-ge2 (mp_limb_t ah, mp_limb_t al, mp_limb_t bh, mp_limb_t bl)
+lt2 (mp_limb_t ah, mp_limb_t al, mp_limb_t bh, mp_limb_t bl)
 {
   mp_limb_t dh, dl;
   bool vh = ckd_sub (&dh, ah, bh);
   mp_limb_t vl = ckd_sub (&dl, al, bl);
-  return ! (vh | ckd_sub (&dh, dh, vl));
+  return vh | ckd_sub (&dh, dh, vl);
 }
 
-/* (ah,hl) > (bh,bl)?  */
+/* (ah,hl) >= (bh,bl)?  */
 static bool
-gt2 (mp_limb_t ah, mp_limb_t al, mp_limb_t bh, mp_limb_t bl)
+ge2 (mp_limb_t ah, mp_limb_t al, mp_limb_t bh, mp_limb_t bl)
 {
-  mp_limb_t dh, dl;
-  bool vh = ckd_sub (&dh, bh, ah);
-  mp_limb_t vl = ckd_sub (&dl, bl, al);
-  return vh | ckd_sub (&dh, dh, vl);
+  return !lt2 (ah, al, bh, bl);
 }
 
 /* Set (rh,rl) = (ah,al) - (bh,bl).  Overflow wraps around.  */
@@ -531,7 +528,7 @@ gcd2_odd (mp_limb_t a1, mp_limb_t a0, mp_limb_t b1, mp_limb_t b0)
       if ((b1 | a1) == 0)
         return make_uuint (0, gcd_odd (b0, a0));
 
-      if (gt2 (a1, a0, b1, b0))
+      if (lt2 (b1, b0, a1, a0))
         {
           sub_ddmmss (a1, a0, a1, a0, b1, b0);
           if (!a0)