[Gmp-commit] /var/hg/gmp: Improved mpn_mod_1 tuning

mercurial at gmplib.org mercurial at gmplib.org
Thu Mar 3 11:48:11 CET 2011


details:   /var/hg/gmp/rev/1b7872594f9b
changeset: 13988:1b7872594f9b
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Thu Mar 03 11:47:56 2011 +0100
description:
Improved mpn_mod_1 tuning

diffstat:

 ChangeLog           |  13 +++++++++++++
 gmp-impl.h          |   4 ++++
 mpn/generic/mod_1.c |  21 +++++++++++++++++++++
 tune/tuneup.c       |  48 +++++++++++++++++++++++++-----------------------
 4 files changed, 63 insertions(+), 23 deletions(-)

diffs (137 lines):

diff -r 16a9ccb257a7 -r 1b7872594f9b ChangeLog
--- a/ChangeLog	Thu Mar 03 09:29:02 2011 +0100
+++ b/ChangeLog	Thu Mar 03 11:47:56 2011 +0100
@@ -1,3 +1,16 @@
+2011-03-03  Niels Möller  <nisse at lysator.liu.se>
+
+	* tune/tuneup.c (tune_mod_1): Record result of MOD_1_1P_METHOD
+	measurement for use by mpn_mod_1_tune. And omit measurement if
+	mpn_mod_1_1p is native assebly code.
+
+	* mpn/generic/mod_1.c (mpn_mod_1_1p) [TUNE_PROGRAM_BUILD]: Macro
+	to check mod_1_1p_method and call the right function.
+	(mpn_mod_1_1p_cps) [TUNE_PROGRAM_BUILD]: Likewise.
+
+	* gmp-impl.h (MOD_1_1P_METHOD) [TUNE_PROGRAM_BUILD]: Define macro.
+	(mod_1_1p_method) [TUNE_PROGRAM_BUILD]: Declare variable.
+
 2011-03-03  Torbjorn Granlund  <tege at gmplib.org>
 
 	* gmp-impl.h (mpn_addlsh_nc, mpn_rsblsh_nc): Declare.
diff -r 16a9ccb257a7 -r 1b7872594f9b gmp-impl.h
--- a/gmp-impl.h	Thu Mar 03 09:29:02 2011 +0100
+++ b/gmp-impl.h	Thu Mar 03 11:47:56 2011 +0100
@@ -4552,6 +4552,10 @@
 #define MOD_1_UNNORM_THRESHOLD		mod_1_unnorm_threshold
 extern mp_size_t			mod_1_unnorm_threshold;
 
+#undef  MOD_1_1P_METHOD
+#define MOD_1_1P_METHOD			mod_1_1p_method
+extern int				mod_1_1p_method;
+
 #undef	MOD_1N_TO_MOD_1_1_THRESHOLD
 #define MOD_1N_TO_MOD_1_1_THRESHOLD	mod_1n_to_mod_1_1_threshold
 extern mp_size_t			mod_1n_to_mod_1_1_threshold;
diff -r 16a9ccb257a7 -r 1b7872594f9b mpn/generic/mod_1.c
--- a/mpn/generic/mod_1.c	Thu Mar 03 09:29:02 2011 +0100
+++ b/mpn/generic/mod_1.c	Thu Mar 03 11:47:56 2011 +0100
@@ -58,6 +58,27 @@
 #define MOD_1_2_TO_MOD_1_4_THRESHOLD  20
 #endif
 
+#if TUNE_PROGRAM_BUILD && !HAVE_NATIVE_mpn_mod_1_1p
+/* Duplicates declaratinos in tune/speed.h */
+mp_limb_t mpn_mod_1_1p_1 __GMP_PROTO ((mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t [4]));
+mp_limb_t mpn_mod_1_1p_2 __GMP_PROTO ((mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t [4]));
+
+void mpn_mod_1_1p_cps_1 __GMP_PROTO ((mp_limb_t [4], mp_limb_t));
+void mpn_mod_1_1p_cps_2 __GMP_PROTO ((mp_limb_t [4], mp_limb_t));
+
+#undef mpn_mod_1_1p
+#define mpn_mod_1_1p(ap, n, b, pre)			     \
+  (mod_1_1p_method == 1 ? mpn_mod_1_1p_1 (ap, n, b, pre)     \
+   : (mod_1_1p_method == 2 ? mpn_mod_1_1p_2 (ap, n, b, pre)  \
+      : __gmpn_mod_1_1p (ap, n, b, pre)))
+
+#undef mpn_mod_1_1p_cps
+#define mpn_mod_1_1p_cps(pre, b)				\
+  (mod_1_1p_method == 1 ? mpn_mod_1_1p_cps_1 (pre, b)		\
+   : (mod_1_1p_method == 2 ? mpn_mod_1_1p_cps_2 (pre, b)	\
+      : __gmpn_mod_1_1p_cps (pre, b)))
+#endif /* TUNE_PROGRAM_BUILD && !HAVE_NATIVE_mpn_mod_1_1p */
+
 
 /* The comments in mpn/generic/divrem_1.c apply here too.
 
diff -r 16a9ccb257a7 -r 1b7872594f9b tune/tuneup.c
--- a/tune/tuneup.c	Thu Mar 03 09:29:02 2011 +0100
+++ b/tune/tuneup.c	Thu Mar 03 11:47:56 2011 +0100
@@ -200,6 +200,7 @@
 mp_size_t  divrem_1_unnorm_threshold    = MP_SIZE_T_MAX;
 mp_size_t  mod_1_norm_threshold         = MP_SIZE_T_MAX;
 mp_size_t  mod_1_unnorm_threshold       = MP_SIZE_T_MAX;
+int	   mod_1_1p_method		= 0; 
 mp_size_t  mod_1n_to_mod_1_1_threshold  = MP_SIZE_T_MAX;
 mp_size_t  mod_1u_to_mod_1_1_threshold  = MP_SIZE_T_MAX;
 mp_size_t  mod_1_1_to_mod_1_2_threshold = MP_SIZE_T_MAX;
@@ -254,6 +255,9 @@
 #ifndef HAVE_NATIVE_mpn_mod_1
 #define HAVE_NATIVE_mpn_mod_1 0
 #endif
+#ifndef HAVE_NATIVE_mpn_mod_1_1p
+#define HAVE_NATIVE_mpn_mod_1_1p 0
+#endif
 #ifndef HAVE_NATIVE_mpn_modexact_1_odd
 #define HAVE_NATIVE_mpn_modexact_1_odd 0
 #endif
@@ -1851,29 +1855,27 @@
       return;
     }
 
-  {
-    static struct param_t  param;
-    double   t1, t2;
-    int      method;
-
-    s.size = 10;
-    s.r = randlimb_half ();
-
-    t1 = tuneup_measure (speed_mpn_mod_1_1_1, &param, &s);
-    t2 = tuneup_measure (speed_mpn_mod_1_1_2, &param, &s);
-
-    if (t1 == -1.0 || t2 == -1.0)
-      {
-	printf ("Oops, can't measure all mpn_mod_1_1 methods at %ld\n",
-		(long) s.size);
-	abort ();
-      }
-    method = (t1 < t2) ? 1 : 2;
-    print_define ("MOD_1_1P_METHOD", method);
-
-    /* FIXME: Use this choice when tuning the thresholds below, except
-       if we have a native mod_1_1. */
-  }
+  if (!HAVE_NATIVE_mpn_mod_1_1p)
+    {
+      static struct param_t  param;
+      double   t1, t2;
+      int      method;
+
+      s.size = 10;
+      s.r = randlimb_half ();
+
+      t1 = tuneup_measure (speed_mpn_mod_1_1_1, &param, &s);
+      t2 = tuneup_measure (speed_mpn_mod_1_1_2, &param, &s);
+
+      if (t1 == -1.0 || t2 == -1.0)
+	{
+	  printf ("Oops, can't measure all mpn_mod_1_1 methods at %ld\n",
+		  (long) s.size);
+	  abort ();
+	}
+      mod_1_1p_method = (t1 < t2) ? 1 : 2;
+      print_define ("MOD_1_1P_METHOD", mod_1_1p_method);
+    }
 
   if (UDIV_PREINV_ALWAYS)
     {


More information about the gmp-commit mailing list