[Gmp-commit] /var/hg/gmp-5.0: Rewrite code for limiting mpn_sqr_basecase use.

mercurial at gmplib.org mercurial at gmplib.org
Tue Jan 31 16:27:38 CET 2012


details:   /var/hg/gmp-5.0/rev/8ea77456e066
changeset: 13532:8ea77456e066
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Tue Jan 31 16:27:34 2012 +0100
description:
Rewrite code for limiting mpn_sqr_basecase use.

diffstat:

 ChangeLog              |   8 ++++++--
 mpn/generic/powm_sec.c |  19 +++++++++----------
 2 files changed, 15 insertions(+), 12 deletions(-)

diffs (66 lines):

diff -r 5860df7ea802 -r 8ea77456e066 ChangeLog
--- a/ChangeLog	Tue Jan 31 11:21:22 2012 +0100
+++ b/ChangeLog	Tue Jan 31 16:27:34 2012 +0100
@@ -1,7 +1,11 @@
 2012-01-31  Torbjorn Granlund  <tege at gmplib.org>
 
-	* mpn/generic/powm_sec.c (SQR_BASECASE_MAX): Set safely from
-	SQR_TOOM2_THRESHOLD.
+	* mpn/generic/powm_sec.c (SQR_BASECASE_LIM): New name for
+	SQR_BASECASE_MAX.
+	(SQR_BASECASE_LIM, fat varint): Define to read __gmpn_cpuvec.
+	(SQR_BASECASE_LIM, native variant): Define to SQR_TOOM2_THRESHOLD
+	straight, without arithmetic.
+	(mpn_local_sqr): Use BELOW_THRESHOLD as per Marco's suggestion.
 
 2012-01-30  Torbjorn Granlund  <tege at gmplib.org>
 
diff -r 5860df7ea802 -r 8ea77456e066 mpn/generic/powm_sec.c
--- a/mpn/generic/powm_sec.c	Tue Jan 31 11:21:22 2012 +0100
+++ b/mpn/generic/powm_sec.c	Tue Jan 31 16:27:34 2012 +0100
@@ -82,7 +82,7 @@
 
 #if ! HAVE_NATIVE_mpn_sqr_basecase
 /* The limit of the generic code is SQR_TOOM2_THRESHOLD.  */
-#define SQR_BASECASE_MAX  (SQR_TOOM2_THRESHOLD - 1)
+#define SQR_BASECASE_LIM  SQR_TOOM2_THRESHOLD
 #endif
 
 #if HAVE_NATIVE_mpn_sqr_basecase
@@ -91,20 +91,19 @@
    mpn_sqr_basecase, it comes from SQR_TOOM2_THRESHOLD_MAX in the assembly
    file.  An assembly mpn_sqr_basecase that does not define it, should allow
    any size.  */
-#define SQR_BASECASE_MAX  (SQR_TOOM2_THRESHOLD - 1)
+#define SQR_BASECASE_LIM  SQR_TOOM2_THRESHOLD
 #endif
 #endif
 
 #ifdef WANT_FAT_BINARY
-/* For fat builds, we would need to quantify over all mpn_sqr_basecase limit
-   that may appear in __gmpn_cpuvec.  This asks for some configure.in hacking.
-   For now, define a safe limit which all mpn_sqr_basecase will handle.
-   FIXME!  */
-#define SQR_BASECASE_MAX 32
+/* For fat builds, we use SQR_TOOM2_THRESHOLD which will expand to a read from
+   __gmpn_cpuvec.  Perhaps any possible sqr_basecase.asm allow any size, and we
+   limit the use unnecessarily.  We cannot tell, so play it safe.  FIXME.  */
+#define SQR_BASECASE_LIM  SQR_TOOM2_THRESHOLD
 #endif
 
-#ifndef SQR_BASECASE_MAX
-/* If SQR_BASECASE_MAX is now not defined, use mpn_sqr_basecase for any operand
+#ifndef SQR_BASECASE_LIM
+/* If SQR_BASECASE_LIM is now not defined, use mpn_sqr_basecase for any operand
    size.  */
 #define mpn_local_sqr(rp,up,n,tp) mpn_sqr_basecase(rp,up,n)
 #else
@@ -118,7 +117,7 @@
   ASSERT (n >= 1);
   ASSERT (! MPN_OVERLAP_P (rp, 2*n, up, n));
 
-  if (n <= SQR_BASECASE_MAX)
+  if (BELOW_THRESHOLD (n, SQR_BASECASE_LIM))
     {
       mpn_sqr_basecase (rp, up, n);
       return;


More information about the gmp-commit mailing list