[Gmp-commit] /home/hgfiles/gmp: Rework logic for mpn_sqr_basecase size limit.

mercurial at gmplib.org mercurial at gmplib.org
Sun Dec 6 15:01:41 CET 2009


details:   /home/hgfiles/gmp/rev/c5943f0df94f
changeset: 12996:c5943f0df94f
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Sun Dec 06 15:01:37 2009 +0100
description:
Rework logic for mpn_sqr_basecase size limit.

diffstat:

 ChangeLog              |  10 ++++++----
 mpn/generic/powm_sec.c |  29 +++++++++++++++++++++--------
 2 files changed, 27 insertions(+), 12 deletions(-)

diffs (99 lines):

diff -r 894d77269797 -r c5943f0df94f ChangeLog
--- a/ChangeLog	Sun Dec 06 11:13:22 2009 +0100
+++ b/ChangeLog	Sun Dec 06 15:01:37 2009 +0100
@@ -1,5 +1,7 @@
 2009-12-06  Torbjorn Granlund  <tege at gmplib.org>
 
+	* mpn/generic/powm_sec.c: Rework logic for mpn_sqr_basecase size limit.
+
 	* gmp-impl.h (mpn_redc_1_sec): Declare.
 	* configure.in (gmp_mpn_functions): Add redc_1_sec.
 
@@ -186,8 +188,8 @@
 
 2009-11-28  Marco Bodrato <bodrato at mail.dm.unipi.it>
 
-	* mpn/generic/mulmod_bnm1.c: Basecases made simpler,
-	  this also corrects a bug affecting previous version.
+	* mpn/generic/mulmod_bnm1.c: Basecases made simpler, this also corrects
+	a bug affecting previous version.
 
 2009-11-28  Torbjorn Granlund  <tege at gmplib.org>
 
@@ -274,7 +276,7 @@
 2009-11-21  Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* mpn/generic/mullow_n.c: Disable Mulders' trick for small operands,
-        use fft for bigger ones.
+	use fft for bigger ones.
 	* tests/mpn/t-mullo.c: New test file.
 
 2009-11-22  Torbjorn Granlund  <tege at gmplib.org>
@@ -414,7 +416,7 @@
 	* mpn/x86_64/x86_64-defs.m4 (CPUVEC_FUNCS_LIST): New, copied from
 	mpn/x86/x86-defs.m4.
 	* configure.in: Move down x86 fat setup code until after ABI has been
-	determined; generalize to handle x86_64.
+	determined; generalise to handle x86_64.
 
 2009-11-09  Torbjorn Granlund  <tege at gmplib.org>
 
diff -r 894d77269797 -r c5943f0df94f mpn/generic/powm_sec.c
--- a/mpn/generic/powm_sec.c	Sun Dec 06 11:13:22 2009 +0100
+++ b/mpn/generic/powm_sec.c	Sun Dec 06 15:01:37 2009 +0100
@@ -1,5 +1,11 @@
-/* mpn_powm_sec -- Compute R = U^E mod M.  Sacure variant, side-channel silent
-   under the assupmtion that the multiply instruction is side channel silent.
+/* mpn_powm_sec -- Compute R = U^E mod M.  Secure variant, side-channel silent
+   under the assumption that the multiply instruction is side channel silent.
+
+   Contributed to the GNU project by Torbjorn Granlund.
+
+   THE FUNCTIONS IN THIS FILE ARE INTERNAL WITH MUTABLE INTERFACES.  IT IS ONLY
+   SAFE TO REACH THEM THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
+   GUARANTEED THAT THEY WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
 
 Copyright 2007, 2008, 2009 Free Software Foundation, Inc.
 
@@ -72,12 +78,19 @@
   } while (0)
 #endif
 
-#if HAVE_NATIVE_mpn_sqr_basecase
-#define BASECASE_LIMIT TUNE_SQR_TOOM2_MAX
-#else
-#define BASECASE_LIMIT SQR_TOOM2_THRESHOLD
+
+#if ! HAVE_NATIVE_mpn_sqr_basecase
+/* The limit of the generic code is SQR_TOOM2_THRESHOLD.  */
+#define SQR_TOOM2_THRESHOLD_MAX SQR_TOOM2_THRESHOLD
 #endif
 
+#ifndef SQR_TOOM2_THRESHOLD_MAX
+/* If SQR_TOOM2_THRESHOLD_MAX is not defined, use mpn_sqr_basecase for any
+   operand size.  */
+#define mpn_local_sqr_n mpn_sqr_basecase
+#else
+/* Define our own squaring function, which uses mpn_sqr_basecase for its
+   allowed sizes, but its own code for larger sizes.  */
 static void
 mpn_local_sqr_n (mp_ptr rp, mp_srcptr up, mp_size_t n)
 {
@@ -86,7 +99,7 @@
   ASSERT (n >= 1);
   ASSERT (! MPN_OVERLAP_P (rp, 2*n, up, n));
 
-  if (n < BASECASE_LIMIT)
+  if (n < SQR_TOOM2_THRESHOLD_MAX)
     {
       mpn_sqr_basecase (rp, up, n);
       return;
@@ -131,7 +144,7 @@
       TMP_FREE;
     }
 }
-
+#endif
 
 #define getbit(p,bi) \
   ((p[(bi - 1) / GMP_LIMB_BITS] >> (bi - 1) % GMP_LIMB_BITS) & 1)


More information about the gmp-commit mailing list