[Gmp-commit] /var/hg/gmp: Amend last change, handling absence of mpn_sqr_diag...
mercurial at gmplib.org
mercurial at gmplib.org
Sun Apr 16 23:12:22 UTC 2017
details: /var/hg/gmp/rev/534363fb38fe
changeset: 17353:534363fb38fe
user: Torbjorn Granlund <tg at gmplib.org>
date: Mon Apr 17 01:12:16 2017 +0200
description:
Amend last change, handling absence of mpn_sqr_diag_addlsh1.
diffstat:
mpn/generic/sqr_basecase.c | 50 ++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 46 insertions(+), 4 deletions(-)
diffs (68 lines):
diff -r 830a47fb463f -r 534363fb38fe mpn/generic/sqr_basecase.c
--- a/mpn/generic/sqr_basecase.c Mon Apr 17 00:44:28 2017 +0200
+++ b/mpn/generic/sqr_basecase.c Mon Apr 17 01:12:16 2017 +0200
@@ -282,10 +282,10 @@
#endif
-#if ! defined (READY_WITH_mpn_sqr_basecase)
+#if ! defined (READY_WITH_mpn_sqr_basecase) && HAVE_NATIVE_mpn_sqr_diag_addlsh1
-/* Default mpn_sqr_basecase using mpn_addmul_1. */
-
+/* mpn_sqr_basecase using mpn_addmul_1 and mpn_sqr_diag_addlsh1, avoiding stack
+ allocation. */
void
mpn_sqr_basecase (mp_ptr rp, mp_srcptr up, mp_size_t n)
{
@@ -311,7 +311,49 @@
}
xp = rp - 2 * n + 3;
- MPN_SQR_DIAG_ADDLSH1 (xp, xp + 1, up - n + 2, n);
+ mpn_sqr_diag_addlsh1 (xp, xp + 1, up - n + 2, n);
}
}
#endif
+
+
+#if ! defined (READY_WITH_mpn_sqr_basecase)
+
+/* Default mpn_sqr_basecase using mpn_addmul_1. */
+void
+mpn_sqr_basecase (mp_ptr rp, mp_srcptr up, mp_size_t n)
+{
+ mp_size_t i;
+
+ ASSERT (n >= 1);
+ ASSERT (! MPN_OVERLAP_P (rp, 2*n, up, n));
+
+ if (n == 1)
+ {
+ mp_limb_t ul, lpl;
+ ul = up[0];
+ umul_ppmm (rp[1], lpl, ul, ul << GMP_NAIL_BITS);
+ rp[0] = lpl >> GMP_NAIL_BITS;
+ }
+ else
+ {
+ mp_limb_t tarr[2 * SQR_TOOM2_THRESHOLD];
+ mp_ptr tp = tarr;
+ mp_limb_t cy;
+
+ /* must fit 2*n limbs in tarr */
+ ASSERT (n <= SQR_TOOM2_THRESHOLD);
+
+ cy = mpn_mul_1 (tp, up + 1, n - 1, up[0]);
+ tp[n - 1] = cy;
+ for (i = 2; i < n; i++)
+ {
+ mp_limb_t cy;
+ cy = mpn_addmul_1 (tp + 2 * i - 2, up + i, n - i, up[i - 1]);
+ tp[n + i - 2] = cy;
+ }
+
+ MPN_SQR_DIAG_ADDLSH1 (rp, tp, up, n);
+ }
+}
+#endif
More information about the gmp-commit
mailing list