[Gmp-commit] /var/hg/gmp: mpn/generic/sqrtrem.c (mpn_sqrtrem): Inline mpn_sub...
mercurial at gmplib.org
mercurial at gmplib.org
Sat Jul 4 11:02:33 CEST 2026
details: /var/hg/gmp/rev/d4bbcd8fbd2b
changeset: 18552:d4bbcd8fbd2b
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Sat Jul 04 10:58:06 2026 +0200
description:
mpn/generic/sqrtrem.c (mpn_sqrtrem): Inline mpn_submul_1(x,y,1,*y).
diffstat:
mpn/generic/sqrtrem.c | 18 ++++++++++++++----
1 files changed, 14 insertions(+), 4 deletions(-)
diffs (35 lines):
diff -r 8d1d4f3b2d7e -r d4bbcd8fbd2b mpn/generic/sqrtrem.c
--- a/mpn/generic/sqrtrem.c Fri Jul 03 14:53:20 2026 +0200
+++ b/mpn/generic/sqrtrem.c Sat Jul 04 10:58:06 2026 +0200
@@ -501,7 +501,7 @@
TMP_MARK;
if (((nn & 1) | c) != 0)
{
- mp_limb_t s0[1], mask;
+ mp_limb_t s0, mask;
mp_ptr tp, scratch;
TMP_ALLOC_LIMBS_2 (tp, 2 * tn, scratch, (tn >> 1) + 1);
tp[0] = 0; /* needed only when 2*tn > nn, but saves a test */
@@ -514,9 +514,19 @@
rl = mpn_dc_sqrtrem (sp, tp, tn, (rp == NULL) ? mask - 1 : 0, scratch);
/* We have 2^(2k)*N = S^2 + R where k = c + (2tn-nn)*GMP_NUMB_BITS/2,
thus 2^(2k)*N = (S-s0)^2 + 2*S*s0 - s0^2 + R where s0=S mod 2^k */
- s0[0] = sp[0] & mask; /* S mod 2^k */
- rl += mpn_addmul_1 (tp, sp, tn, 2 * s0[0]); /* R = R + 2*s0*S */
- cc = mpn_submul_1 (tp, s0, 1, s0[0]);
+ s0 = sp[0] & mask; /* S mod 2^k */
+ rl += mpn_addmul_1 (tp, sp, tn, 2 * s0); /* R = R + 2*s0*S */
+#if 0
+ cc = mpn_submul_1 (tp, &s0, 1, s0);
+#else
+ {
+ mp_limb_t p0, t0 = *tp;
+ umul_ppmm (cc, p0, s0, s0);
+ p0 = t0 - p0;
+ cc += t0 < p0; /* Borrow turns into a carry */
+ *tp = p0;
+ }
+#endif
rl -= (tn > 1) ? mpn_sub_1 (tp + 1, tp + 1, tn - 1, cc) : cc;
mpn_rshift (sp, sp, tn, c);
tp[tn] = rl;
More information about the gmp-commit
mailing list