[Gmp-commit] /home/hgfiles/gmp: Add tuning of INV_NEWTON_THRESHOLD, but leave...

mercurial at gmplib.org mercurial at gmplib.org
Tue Dec 8 10:54:51 CET 2009


details:   /home/hgfiles/gmp/rev/415fa264bb46
changeset: 13005:415fa264bb46
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Tue Dec 08 10:54:47 2009 +0100
description:
Add tuning of INV_NEWTON_THRESHOLD, but leave disabled for now.

diffstat:

 ChangeLog                  |  12 +++++++++++-
 gmp-impl.h                 |   4 ++++
 mpn/generic/dcpi1_bdiv_q.c |   2 +-
 mpz/powm.c                 |   2 +-
 tune/Makefile.am           |   2 +-
 tune/common.c              |  19 ++++++-------------
 tune/speed.c               |   8 ++++----
 tune/speed.h               |  38 ++++++++++++++++++++++++++++++++++++--
 tune/tuneup.c              |  31 +++++++++++++++++--------------
 9 files changed, 81 insertions(+), 37 deletions(-)

diffs (263 lines):

diff -r 336c0e91f5ca -r 415fa264bb46 ChangeLog
--- a/ChangeLog	Tue Dec 08 08:48:57 2009 +0100
+++ b/ChangeLog	Tue Dec 08 10:54:47 2009 +0100
@@ -1,3 +1,13 @@
+2009-12-08  Torbjorn Granlund  <tege at gmplib.org>
+
+	* tune/speed.c (routine): Add mpn_invert.
+
+	* tune/tuneup.c	(tune_invert): New function.
+	* tune/speed.h (SPEED_ROUTINE_MPN_INVERT): New macro.
+	* tune/common.c (speed_mpn_invert): New function.
+	* gmp-impl.h: Provide declarations for corresponding threshold var.
+	* tune/Makefile.am (TUNE_MPN_SRCS_BASIC): Add invert.c.
+
 2009-12-08  Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* tests/devel/try.c: Test mpn_addlsh2_n and mpn_{add,sub}lsh_n;
@@ -146,7 +156,7 @@
 	(tune_binvert): New function.
 	* tune/speed.h (SPEED_ROUTINE_MPN_BINVERT): New macro.
 	* tune/common.c (speed_mpn_binvert): New function.
-	* gmp-impl.h: Provide declarations for corresponding threshold vars.
+	* gmp-impl.h: Provide declarations for corresponding threshold var.
 	* tune/Makefile.am (TUNE_MPN_SRCS_BASIC): Add binvert.c.
 
 	* tune/tuneup.c: Tune DC_BDIV_QR_THRESHOLD and DC_BDIV_Q_THRESHOLD.
diff -r 336c0e91f5ca -r 415fa264bb46 gmp-impl.h
--- a/gmp-impl.h	Tue Dec 08 08:48:57 2009 +0100
+++ b/gmp-impl.h	Tue Dec 08 10:54:47 2009 +0100
@@ -4164,6 +4164,10 @@
 #define DC_BDIV_QR_THRESHOLD         dc_bdiv_qr_threshold
 extern mp_size_t                     dc_bdiv_qr_threshold;
 
+#undef  INV_NEWTON_THRESHOLD
+#define INV_NEWTON_THRESHOLD         inv_newton_threshold
+extern mp_size_t                     inv_newton_threshold;
+
 #undef  BINV_NEWTON_THRESHOLD
 #define BINV_NEWTON_THRESHOLD        binv_newton_threshold
 extern mp_size_t                     binv_newton_threshold;
diff -r 336c0e91f5ca -r 415fa264bb46 mpn/generic/dcpi1_bdiv_q.c
--- a/mpn/generic/dcpi1_bdiv_q.c	Tue Dec 08 08:48:57 2009 +0100
+++ b/mpn/generic/dcpi1_bdiv_q.c	Tue Dec 08 10:54:47 2009 +0100
@@ -32,7 +32,7 @@
 mp_size_t
 mpn_dcpi1_bdiv_q_n_itch (mp_size_t n)
 {
-  /* NOTE: Depends om mullo_n interface */
+  /* NOTE: Depends on mullo_n interface */
   return n;
 }
 
diff -r 336c0e91f5ca -r 415fa264bb46 mpz/powm.c
--- a/mpz/powm.c	Tue Dec 08 08:48:57 2009 +0100
+++ b/mpz/powm.c	Tue Dec 08 10:54:47 2009 +0100
@@ -33,7 +33,7 @@
 
  * Improve handling of buffers.  It is pretty ugly now.
 
- * For even moduli, we compute an binvert of its odd part both here and in
+ * For even moduli, we compute a binvert of its odd part both here and in
    mpn_powm.  How can we avoid this recomputation?
 */
 
diff -r 336c0e91f5ca -r 415fa264bb46 tune/Makefile.am
--- a/tune/Makefile.am	Tue Dec 08 08:48:57 2009 +0100
+++ b/tune/Makefile.am	Tue Dec 08 10:54:47 2009 +0100
@@ -123,7 +123,7 @@
 
 TUNE_MPN_SRCS = $(TUNE_MPN_SRCS_BASIC) divrem_1.c mod_1.c
 TUNE_MPN_SRCS_BASIC = dcpi1_div_qr.c dcpi1_divappr_q.c dcpi1_bdiv_qr.c dcpi1_bdiv_q.c	\
-  binvert.c divrem_2.c gcd.c gcdext.c get_str.c				\
+  invert.c binvert.c divrem_2.c gcd.c gcdext.c get_str.c		\
   set_str.c matrix22_mul.c hgcd.c mul_n.c sqr_n.c			\
   mullo_n.c mul_fft.c mul.c tdiv_qr.c mulmod_bnm1.c			\
   toom22_mul.c toom2_sqr.c toom33_mul.c toom3_sqr.c toom44_mul.c toom4_sqr.c
diff -r 336c0e91f5ca -r 415fa264bb46 tune/common.c
--- a/tune/common.c	Tue Dec 08 08:48:57 2009 +0100
+++ b/tune/common.c	Tue Dec 08 10:54:47 2009 +0100
@@ -786,6 +786,12 @@
 }
 
 double
+speed_mpn_invert (struct speed_params *s)
+{
+  SPEED_ROUTINE_MPN_INVERT (mpn_invert, mpn_invert_itch);
+}
+
+double
 speed_mpn_redc_1 (struct speed_params *s)
 {
   SPEED_ROUTINE_REDC_1 (mpn_redc_1);
@@ -1253,19 +1259,6 @@
 {
   SPEED_ROUTINE_MPN_GCD (mpn_gcd);
 }
-#if 0
-double
-speed_mpn_gcd_binary (struct speed_params *s)
-{
-  SPEED_ROUTINE_MPN_GCD (mpn_gcd_binary);
-}
-double
-speed_mpn_gcd_accel (struct speed_params *s)
-{
-  SPEED_ROUTINE_MPN_GCD (mpn_gcd_accel);
-}
-#endif
-
 
 double
 speed_mpn_gcdext (struct speed_params *s)
diff -r 336c0e91f5ca -r 415fa264bb46 tune/speed.c
--- a/tune/speed.c	Tue Dec 08 08:48:57 2009 +0100
+++ b/tune/speed.c	Tue Dec 08 10:54:47 2009 +0100
@@ -310,12 +310,12 @@
 
   { "mpn_mulmod_bnm1",   speed_mpn_mulmod_bnm1      },
 
+  { "mpn_invert",        speed_mpn_invert           },
   { "mpn_binvert",       speed_mpn_binvert          },
 
-  { "mpn_get_str",       speed_mpn_get_str,  FLAG_R_OPTIONAL },
-
-  { "mpn_set_str",         speed_mpn_set_str,     FLAG_R_OPTIONAL },
-  { "mpn_set_str_basecase",speed_mpn_bc_set_str,  FLAG_R_OPTIONAL },
+  { "mpn_get_str",          speed_mpn_get_str,     FLAG_R_OPTIONAL },
+  { "mpn_set_str",          speed_mpn_set_str,     FLAG_R_OPTIONAL },
+  { "mpn_set_str_basecase", speed_mpn_bc_set_str,  FLAG_R_OPTIONAL },
 
   { "mpn_sqrtrem",       speed_mpn_sqrtrem          },
   { "mpn_rootrem",       speed_mpn_rootrem, FLAG_R  },
diff -r 336c0e91f5ca -r 415fa264bb46 tune/speed.h
--- a/tune/speed.h	Tue Dec 08 08:48:57 2009 +0100
+++ b/tune/speed.h	Tue Dec 08 10:54:47 2009 +0100
@@ -189,8 +189,6 @@
 double speed_mpn_gcd __GMP_PROTO ((struct speed_params *s));
 double speed_mpn_gcd_1 __GMP_PROTO ((struct speed_params *s));
 double speed_mpn_gcd_1N __GMP_PROTO ((struct speed_params *s));
-double speed_mpn_gcd_binary __GMP_PROTO ((struct speed_params *s));
-double speed_mpn_gcd_accel __GMP_PROTO ((struct speed_params *s));
 double speed_mpn_gcdext __GMP_PROTO ((struct speed_params *s));
 double speed_mpn_gcdext_double __GMP_PROTO ((struct speed_params *s));
 double speed_mpn_gcdext_one_double __GMP_PROTO ((struct speed_params *s));
@@ -243,6 +241,7 @@
 double speed_mpn_dcpi1_bdiv_qr __GMP_PROTO ((struct speed_params *s));
 double speed_mpn_sbpi1_bdiv_q __GMP_PROTO ((struct speed_params *s));
 double speed_mpn_dcpi1_bdiv_q __GMP_PROTO ((struct speed_params *s));
+double speed_mpn_invert __GMP_PROTO ((struct speed_params *s));
 double speed_mpn_binvert __GMP_PROTO ((struct speed_params *s));
 double speed_mpn_redc_1 __GMP_PROTO ((struct speed_params *s));
 double speed_mpn_redc_2 __GMP_PROTO ((struct speed_params *s));
@@ -1431,6 +1430,41 @@
     return t;								\
   }
 
+#define SPEED_ROUTINE_MPN_INVERT(function,itchfn)			\
+  {									\
+    long  i;								\
+    mp_ptr    up, tp, ip;						\
+    double    t;							\
+    TMP_DECL;								\
+									\
+    SPEED_RESTRICT_COND (s->size >= 1);					\
+									\
+    TMP_MARK;								\
+    SPEED_TMP_ALLOC_LIMBS (ip, s->size, s->align_xp);			\
+    SPEED_TMP_ALLOC_LIMBS (up, s->size,   s->align_yp);			\
+    SPEED_TMP_ALLOC_LIMBS (tp, itchfn (s->size), s->align_wp);		\
+									\
+    MPN_COPY (up, s->xp, s->size);					\
+									\
+    /* normalize the data */						\
+    up[s->size-1] |= GMP_NUMB_HIGHBIT;					\
+									\
+    speed_operand_src (s, up, s->size);					\
+    speed_operand_dst (s, tp, s->size);					\
+    speed_operand_dst (s, ip, s->size);					\
+    speed_cache_fill (s);						\
+									\
+    speed_starttime ();							\
+    i = s->reps;							\
+    do									\
+      function (ip, up, s->size, tp);					\
+    while (--i != 0);							\
+    t = speed_endtime ();						\
+									\
+    TMP_FREE;								\
+    return t;								\
+  }
+
 #define SPEED_ROUTINE_MPN_BINVERT(function,itchfn)			\
   {									\
     long  i;								\
diff -r 336c0e91f5ca -r 415fa264bb46 tune/tuneup.c
--- a/tune/tuneup.c	Tue Dec 08 08:48:57 2009 +0100
+++ b/tune/tuneup.c	Tue Dec 08 10:54:47 2009 +0100
@@ -168,6 +168,7 @@
 mp_size_t  dc_divappr_q_threshold       = MP_SIZE_T_MAX;
 mp_size_t  dc_bdiv_qr_threshold         = MP_SIZE_T_MAX;
 mp_size_t  dc_bdiv_q_threshold          = MP_SIZE_T_MAX;
+mp_size_t  inv_newton_threshold         = MP_SIZE_T_MAX;
 mp_size_t  binv_newton_threshold        = MP_SIZE_T_MAX;
 mp_size_t  redc_1_to_redc_2_threshold   = MP_SIZE_T_MAX;
 mp_size_t  redc_1_to_redc_n_threshold   = MP_SIZE_T_MAX;
@@ -1039,6 +1040,19 @@
 }
 
 void
+tune_invert (void)
+{
+  {
+    static struct param_t  param;
+    param.name = "INV_NEWTON_THRESHOLD";
+    param.function = speed_mpn_invert;
+    param.step_factor = 0.02;
+    param.max_size = 5000;
+    one (&inv_newton_threshold, &param);
+  }
+}
+
+void
 tune_binvert (void)
 {
   {
@@ -1122,17 +1136,6 @@
   one (&hgcd_threshold, &param);
 }
 
-#if 0
-void
-tune_gcd_accel (void)
-{
-  static struct param_t  param;
-  param.name = "GCD_ACCEL_THRESHOLD";
-  param.function = speed_mpn_gcd;
-  param.min_size = 1;
-  one (&gcd_accel_threshold, &param);
-}
-#endif
 void
 tune_gcd_dc (void)
 {
@@ -1909,6 +1912,9 @@
 
   tune_dc_div ();
   tune_dc_bdiv ();
+#if 0
+  tune_invert ();
+#endif
   tune_binvert ();
   tune_redc ();
   printf("\n");
@@ -1917,9 +1923,6 @@
   tune_hgcd ();
   tune_gcd_dc ();
   tune_gcdext_dc ();
-#if 0
-  tune_gcd_accel ();
-#endif
   tune_jacobi_base ();
   printf("\n");
 


More information about the gmp-commit mailing list