[Gmp-commit] /var/hg/gmp: 3 new changesets
mercurial at gmplib.org
mercurial at gmplib.org
Fri Mar 23 15:47:28 UTC 2018
details: /var/hg/gmp/rev/a6967ea18b2f
changeset: 17586:a6967ea18b2f
user: Torbjorn Granlund <tg at gmplib.org>
date: Fri Mar 23 16:41:03 2018 +0100
description:
Simplify code for choosing between redc_1 and redc_2.
details: /var/hg/gmp/rev/289ab13bc3fe
changeset: 17587:289ab13bc3fe
user: Torbjorn Granlund <tg at gmplib.org>
date: Fri Mar 23 16:46:29 2018 +0100
description:
Compute power table with squaring for even powers.
details: /var/hg/gmp/rev/2c60d7137ef8
changeset: 17588:2c60d7137ef8
user: Torbjorn Granlund <tg at gmplib.org>
date: Fri Mar 23 16:47:06 2018 +0100
description:
ChangeLog
diffstat:
ChangeLog | 6 ++++
mpn/generic/sec_powm.c | 67 ++++++++++++++++++++++++++-----------------------
2 files changed, 41 insertions(+), 32 deletions(-)
diffs (155 lines):
diff -r 186ea964d61f -r 2c60d7137ef8 ChangeLog
--- a/ChangeLog Fri Mar 23 15:01:49 2018 +0100
+++ b/ChangeLog Fri Mar 23 16:47:06 2018 +0100
@@ -1,3 +1,9 @@
+2018-03-23 Torbjörn Granlund <tg at gmplib.org>
+
+ * mpn/generic/sec_powm.c: Remove unused macros.
+ Simplify code for choosing between redc_1 and redc_2.
+ Compute power table with squaring for even powers.
+
2018-02-28 Marco Bodrato <bodrato at mail.dm.unipi.it>
* gmpxx.h (__gmp_binary_plus): Special case for mpq + 1.
diff -r 186ea964d61f -r 2c60d7137ef8 mpn/generic/sec_powm.c
--- a/mpn/generic/sec_powm.c Fri Mar 23 15:01:49 2018 +0100
+++ b/mpn/generic/sec_powm.c Fri Mar 23 16:47:06 2018 +0100
@@ -3,7 +3,7 @@
Contributed to the GNU project by Torbjörn Granlund.
-Copyright 2007-2009, 2011-2014 Free Software Foundation, Inc.
+Copyright 2007-2009, 2011-2014, 2018 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -70,6 +70,7 @@
mpn_cnd_sub_n (cy, rp, rp, mp, n); \
} while (0)
+#if HAVE_NATIVE_mpn_addmul_2 || HAVE_NATIVE_mpn_redc_2
#undef MPN_REDC_2_SEC
#define MPN_REDC_2_SEC(rp, up, mp, n, mip) \
do { \
@@ -77,9 +78,10 @@
cy = mpn_redc_2 (rp, up, mp, n, mip); \
mpn_cnd_sub_n (cy, rp, rp, mp, n); \
} while (0)
-
-#if HAVE_NATIVE_mpn_addmul_2 || HAVE_NATIVE_mpn_redc_2
-#define WANT_REDC_2 1
+#else
+#define MPN_REDC_2_SEC(rp, up, mp, n, mip) /* empty */
+#undef REDC_1_TO_REDC_2_THRESHOLD
+#define REDC_1_TO_REDC_2_THRESHOLD MP_SIZE_T_MAX
#endif
/* Define our own mpn squaring function. We do this since we cannot use a
@@ -206,7 +208,7 @@
mp_limb_t ip[2], *mip;
int windowsize, this_windowsize;
mp_limb_t expbits;
- mp_ptr pp, this_pp;
+ mp_ptr pp, this_pp, ps;
long i;
int cnd;
@@ -219,7 +221,6 @@
windowsize = win_size (enb);
-#if WANT_REDC_2
if (BELOW_THRESHOLD (n, REDC_1_TO_REDC_2_THRESHOLD))
{
mip = ip;
@@ -232,11 +233,6 @@
mpn_binvert (mip, mp, 2, tp);
mip[0] = -mip[0]; mip[1] = ~mip[1];
}
-#else
- mip = ip;
- binvert_limb (mip[0], mp[0]);
- mip[0] = -mip[0];
-#endif
pp = tp;
tp += (n << windowsize); /* put tp after power table */
@@ -259,18 +255,34 @@
/* Precompute powers of b and put them in the temporary area at pp. */
/* scratch: | n | n | ... | | 2n | */
/* | pp[0] | pp[1] | ... | pp[2^windowsize-1] | product | */
- for (i = (1 << windowsize) - 2; i > 0; i--)
+ ps = pp + n; /* initially B^1 */
+ if (BELOW_THRESHOLD (n, REDC_1_TO_REDC_2_THRESHOLD))
{
- mpn_mul_basecase (tp, this_pp, n, pp + n, n);
- this_pp += n;
-#if WANT_REDC_2
- if (BELOW_THRESHOLD (n, REDC_1_TO_REDC_2_THRESHOLD))
- MPN_REDC_1_SEC (this_pp, tp, mp, n, mip[0]);
- else
- MPN_REDC_2_SEC (this_pp, tp, mp, n, mip);
-#else
- MPN_REDC_1_SEC (this_pp, tp, mp, n, mip[0]);
-#endif
+ for (i = (1 << windowsize) - 2; i > 0; i -= 2)
+ {
+ mpn_sqr_basecase (tp, ps, n); /* FIXME: use mpn_local_sqr */
+ ps += n;
+ this_pp += n;
+ MPN_REDC_1_SEC (this_pp, tp, mp, n, mip[0]);
+
+ mpn_mul_basecase (tp, this_pp, n, pp + n, n);
+ this_pp += n;
+ MPN_REDC_1_SEC (this_pp, tp, mp, n, mip[0]);
+ }
+ }
+ else
+ {
+ for (i = (1 << windowsize) - 2; i > 0; i -= 2)
+ {
+ mpn_sqr_basecase (tp, ps, n); /* FIXME: use mpn_local_sqr */
+ ps += n;
+ this_pp += n;
+ MPN_REDC_2_SEC (this_pp, tp, mp, n, mip);
+
+ mpn_mul_basecase (tp, this_pp, n, pp + n, n);
+ this_pp += n;
+ MPN_REDC_2_SEC (this_pp, tp, mp, n, mip);
+ }
}
expbits = getbits (ep, enb, windowsize);
@@ -310,7 +322,6 @@
MPN_REDUCE (rp, tp, mp, n, mip); \
}
-#if WANT_REDC_2
if (BELOW_THRESHOLD (n, REDC_1_TO_REDC_2_THRESHOLD))
{
#undef MPN_REDUCE
@@ -323,23 +334,15 @@
#define MPN_REDUCE(rp,tp,mp,n,mip) MPN_REDC_2_SEC (rp, tp, mp, n, mip)
INNERLOOP;
}
-#else
-#undef MPN_REDUCE
-#define MPN_REDUCE(rp,tp,mp,n,mip) MPN_REDC_1_SEC (rp, tp, mp, n, mip[0])
- INNERLOOP;
-#endif
MPN_COPY (tp, rp, n);
MPN_ZERO (tp + n, n);
-#if WANT_REDC_2
if (BELOW_THRESHOLD (n, REDC_1_TO_REDC_2_THRESHOLD))
MPN_REDC_1_SEC (rp, tp, mp, n, mip[0]);
else
MPN_REDC_2_SEC (rp, tp, mp, n, mip);
-#else
- MPN_REDC_1_SEC (rp, tp, mp, n, mip[0]);
-#endif
+
cnd = mpn_sub_n (tp, rp, mp, n); /* we need just retval */
mpn_cnd_sub_n (!cnd, rp, rp, mp, n);
}
More information about the gmp-commit
mailing list