[Gmp-commit] /var/hg/gmp: (redcify): Use passed scratch instead of locally al...

mercurial at gmplib.org mercurial at gmplib.org
Mon Dec 23 21:08:12 UTC 2013


details:   /var/hg/gmp/rev/b7219db5ac53
changeset: 16106:b7219db5ac53
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Mon Dec 23 22:08:09 2013 +0100
description:
(redcify): Use passed scratch instead of locally allocated.
(mpn_powm_sec_itch): Accommodate mpn_sb_div_r_sec's scratch needs.

diffstat:

 ChangeLog              |   6 ++++++
 mpn/generic/powm_sec.c |  30 ++++--------------------------
 2 files changed, 10 insertions(+), 26 deletions(-)

diffs (73 lines):

diff -r 6af90241df51 -r b7219db5ac53 ChangeLog
--- a/ChangeLog	Fri Dec 20 12:49:21 2013 +0100
+++ b/ChangeLog	Mon Dec 23 22:08:09 2013 +0100
@@ -1,3 +1,9 @@
+2013-12-23  Torbjorn Granlund  <tege at gmplib.org>
+
+	* mpn/generic/powm_sec.c (redcify): Use passed scratch instead of
+	locally allocated.
+	(mpn_powm_sec_itch): Accommodate mpn_sb_div_r_sec's scratch needs.
+
 2013-12-20  Mark Sofroniou  <marks at wolfram.com>
 
 	* mpn/generic/mul_fft.c: Major overhaul of types.
diff -r 6af90241df51 -r b7219db5ac53 mpn/generic/powm_sec.c
--- a/mpn/generic/powm_sec.c	Fri Dec 20 12:49:21 2013 +0100
+++ b/mpn/generic/powm_sec.c	Mon Dec 23 22:08:09 2013 +0100
@@ -42,13 +42,8 @@
      That will simplify the code using getbits.  (Perhaps make getbits' sibling
      getbit then have similar form, for symmetry.)
 
-   * Write an itch function.  Or perhaps get rid of tp parameter since the huge
-     pp area is allocated locally anyway?
-
    * Choose window size without looping.  (Superoptimize or think(tm).)
 
-   * Call side-channel silent division function for converting to REDC residue.
-
    * REDC_1_TO_REDC_2_THRESHOLD might actually represent the cutoff between
      redc_1 and redc_n.  On such systems, we will switch to redc_2 causing
      slowdown.
@@ -232,29 +227,11 @@
 static void
 redcify (mp_ptr rp, mp_srcptr up, mp_size_t un, mp_srcptr mp, mp_size_t n, mp_ptr tp)
 {
-#if 0
-  mp_ptr qp;
-
-  qp = tp + un + n;		/* un + n - n + 1 = un + 1 limbs */
-
   MPN_ZERO (tp, n);
   MPN_COPY (tp + n, up, un);
 
-  mpn_tdiv_qr (qp, rp, 0L, tp, un + n, mp, n);
-#else
-  /* FIXME: Use passed scratch space instead of allocating our own!  */
-  mp_ptr scratch;
-  TMP_DECL;
-  TMP_MARK;
-
-  MPN_ZERO (tp, n);
-  MPN_COPY (tp + n, up, un);
-
-  scratch = TMP_ALLOC_LIMBS ((un + n) + 2 * n + 2);
-  mpn_sb_div_r_sec (tp, un + n, mp, n, scratch);
+  mpn_sb_div_r_sec (tp, un + n, mp, n, tp + un + n);
   MPN_COPY (rp, tp, n);
-  TMP_FREE;
-#endif
 }
 
 /* rp[n-1..0] = bp[bn-1..0] ^ ep[en-1..0] mod mp[n-1..0]
@@ -435,8 +412,9 @@
   windowsize = win_size (en * GMP_NUMB_BITS); /* slight over-estimate of exp */
 
   /* The 2n term is due to pp[0] and pp[1] at the time of the 2nd redcify call,
-     the 2bn + n + 1 term is due to redcify's own usage.  */
-  redcify_itch = (2 * n) + (2 * bn + n + 1);
+     the (bn + n) term is due to redcify's own usage, and the rest is due to
+     mpn_sb_div_r_sec's usage when called from redcify.  */
+  redcify_itch = (2 * n) + (bn + n) + ((bn + n) + 2 * n + 2);
 
   /* The n * 2^windowsize term is due to the power table, the 4n term is due to
      scratch needs of squaring/multiplication in the exponentiation loop.  */


More information about the gmp-commit mailing list