summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorbjorn Granlund <tege@gmplib.org>2009-01-21 22:07:13 +0100
committerTorbjorn Granlund <tege@gmplib.org>2009-01-21 22:07:13 +0100
commit31774fea4dc5ad0ce780588c5922aa602febcf13 (patch)
tree576ac380b819379aee3f02a1c7c6f19f6e7c4382
parent0835c7782e7333aba5f12e6963c2db9b1777fbb4 (diff)
downloadgmp-31774fea4dc5ad0ce780588c5922aa602febcf13.tar.gz
(redc): Remove.
(mpz_powm): Use mpn_redc_1 instead of redc.
-rw-r--r--mpz/powm.c48
1 files changed, 12 insertions, 36 deletions
diff --git a/mpz/powm.c b/mpz/powm.c
index 2059a00a0..8f3ce97cc 100644
--- a/mpz/powm.c
+++ b/mpz/powm.c
@@ -1,7 +1,9 @@
/* mpz_powm(res,base,exp,mod) -- Set RES to (base**exp) mod MOD.
-Copyright 1991, 1993, 1994, 1996, 1997, 2000, 2001, 2002, 2005 Free Software
-Foundation, Inc. Contributed by Paul Zimmermann.
+ Contributed by Paul Zimmermann.
+
+Copyright 1991, 1993, 1994, 1996, 1997, 2000, 2001, 2002, 2005, 2009
+Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -26,32 +28,6 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
#include "mp.h"
#endif
-
-/* Set cp[] <- tp[]/R^n mod mp[]. Clobber tp[].
- mp[] is n limbs; tp[] is 2n limbs. */
-#if ! WANT_REDC_GLOBAL
-static
-#endif
-void
-redc (mp_ptr cp, mp_srcptr mp, mp_size_t n, mp_limb_t Nprim, mp_ptr tp)
-{
- mp_limb_t cy;
- mp_limb_t q;
- mp_size_t j;
-
- ASSERT_MPN (tp, 2*n);
-
- for (j = 0; j < n; j++)
- {
- q = (tp[0] * Nprim) & GMP_NUMB_MASK;
- tp[0] = mpn_addmul_1 (tp, mp, n, q);
- tp++;
- }
- cy = mpn_add_n (cp, tp, tp - n, n);
- if (cy != 0)
- mpn_sub_n (cp, cp, mp, n);
-}
-
/* Compute t = a mod m, a is defined by (ap,an), m is defined by (mp,mn), and
t is defined by (tp,mn). */
static void
@@ -295,7 +271,7 @@ pow (mpz_srcptr b, mpz_srcptr e, mpz_srcptr m, mpz_ptr r)
xp = TMP_ALLOC_LIMBS (mn);
mpn_sqr_n (tp, gp, mn);
if (use_redc)
- redc (xp, mp, mn, invm, tp); /* xx = x^2*R^n */
+ mpn_redc_1 (xp, tp, mp, mn, invm); /* xx = x^2*R^n */
else
mpn_tdiv_qr (qp, xp, 0L, tp, 2 * mn, mp, mn);
this_gp = gp;
@@ -304,7 +280,7 @@ pow (mpz_srcptr b, mpz_srcptr e, mpz_srcptr m, mpz_ptr r)
mpn_mul_n (tp, this_gp, xp, mn);
this_gp += mn;
if (use_redc)
- redc (this_gp, mp, mn, invm, tp); /* g[i] = x^(2i+1)*R^n */
+ mpn_redc_1 (this_gp, tp, mp, mn, invm); /* g[i] = x^(2i+1)*R^n */
else
mpn_tdiv_qr (qp, this_gp, 0L, tp, 2 * mn, mp, mn);
}
@@ -336,7 +312,7 @@ pow (mpz_srcptr b, mpz_srcptr e, mpz_srcptr m, mpz_ptr r)
{
mpn_sqr_n (tp, xp, mn);
if (use_redc)
- redc (xp, mp, mn, invm, tp);
+ mpn_redc_1 (xp, tp, mp, mn, invm);
else
mpn_tdiv_qr (qp, xp, 0L, tp, 2 * mn, mp, mn);
}
@@ -370,7 +346,7 @@ pow (mpz_srcptr b, mpz_srcptr e, mpz_srcptr m, mpz_ptr r)
{
mpn_sqr_n (tp, xp, mn);
if (use_redc)
- redc (xp, mp, mn, invm, tp);
+ mpn_redc_1 (xp, tp, mp, mn, invm);
else
mpn_tdiv_qr (qp, xp, 0L, tp, 2 * mn, mp, mn);
if (sh != 0)
@@ -398,13 +374,13 @@ pow (mpz_srcptr b, mpz_srcptr e, mpz_srcptr m, mpz_ptr r)
{
mpn_sqr_n (tp, xp, mn);
if (use_redc)
- redc (xp, mp, mn, invm, tp);
+ mpn_redc_1 (xp, tp, mp, mn, invm);
else
mpn_tdiv_qr (qp, xp, 0L, tp, 2 * mn, mp, mn);
}
mpn_mul_n (tp, xp, gp + mn * (c >> 1), mn);
if (use_redc)
- redc (xp, mp, mn, invm, tp);
+ mpn_redc_1 (xp, tp, mp, mn, invm);
else
mpn_tdiv_qr (qp, xp, 0L, tp, 2 * mn, mp, mn);
}
@@ -414,7 +390,7 @@ pow (mpz_srcptr b, mpz_srcptr e, mpz_srcptr m, mpz_ptr r)
{
mpn_sqr_n (tp, xp, mn);
if (use_redc)
- redc (xp, mp, mn, invm, tp);
+ mpn_redc_1 (xp, tp, mp, mn, invm);
else
mpn_tdiv_qr (qp, xp, 0L, tp, 2 * mn, mp, mn);
}
@@ -425,7 +401,7 @@ pow (mpz_srcptr b, mpz_srcptr e, mpz_srcptr m, mpz_ptr r)
/* Convert back xx to xx/R^n. */
MPN_COPY (tp, xp, mn);
MPN_ZERO (tp + mn, mn);
- redc (xp, mp, mn, invm, tp);
+ mpn_redc_1 (xp, tp, mp, mn, invm);
if (mpn_cmp (xp, mp, mn) >= 0)
mpn_sub_n (xp, xp, mp, mn);
}