[Gmp-commit] /var/hg/gmp: Add optional /r (for size ratio) to speed program.

mercurial at gmplib.org mercurial at gmplib.org
Mon Nov 20 19:37:48 CET 2023


details:   /var/hg/gmp/rev/78ae53e3531e
changeset: 18461:78ae53e3531e
user:      Niels Möller <nisse at lysator.liu.se>
date:      Mon Nov 20 19:37:26 2023 +0100
description:
Add optional /r (for size ratio) to speed program.

diffstat:

 ChangeLog     |  13 +++++++++++++
 tune/speed.c  |  44 ++++++++++++++++++++++++++++++++++++++++----
 tune/speed.h  |  10 +++++++---
 tune/tuneup.c |   1 +
 4 files changed, 61 insertions(+), 7 deletions(-)

diffs (175 lines):

diff -r c678b487c101 -r 78ae53e3531e ChangeLog
--- a/ChangeLog	Sun Oct 22 17:04:29 2023 +0200
+++ b/ChangeLog	Mon Nov 20 19:37:26 2023 +0100
@@ -1,3 +1,16 @@
+2023-11-20  Niels Möller  <nisse at lysator.liu.se>
+
+	* tune/speed.h (struct speed_params): Add size_ratio field.
+	(SPEED_ROUTINE_MPN_MUL): If size_ratio > 0.0, use it to set size1.
+
+	* tune/speed.c (FLAG_SR_OPTIONAL): New flag.
+	(FLAG_RSIZE): Deleted unused flag.
+	(routine): Add FLAG_SR_OPTIONAL to mpn_mul and mpn_mul_basecase.
+	(run_one): Copy size_ratio field.
+	(slash_r_string): New function, parse float ratio.
+	(routine_find): Handle optional /r.
+	(usage): Display help on /r option.
+
 2023-09-05 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* mpn/generic/toom{54,63,6h,8h}_mul.c, mpn/generic/toom_couple_handling.c,
diff -r c678b487c101 -r 78ae53e3531e tune/speed.c
--- a/tune/speed.c	Sun Oct 22 17:04:29 2023 +0200
+++ b/tune/speed.c	Mon Nov 20 19:37:26 2023 +0100
@@ -130,7 +130,7 @@
 
 #define FLAG_R            (1<<0)  /* require ".r" */
 #define FLAG_R_OPTIONAL   (1<<1)  /* optional ".r" */
-#define FLAG_RSIZE        (1<<2)
+#define FLAG_SR_OPTIONAL  (1<<2)  /* optional ".r" or "/r" */
 #define FLAG_NODATA       (1<<3)  /* don't alloc xp, yp */
 
 const struct routine_t {
@@ -328,8 +328,8 @@
   { "mpn_jacobi_base_3", speed_mpn_jacobi_base_3    },
   { "mpn_jacobi_base_4", speed_mpn_jacobi_base_4    },
 
-  { "mpn_mul",           speed_mpn_mul,         FLAG_R_OPTIONAL },
-  { "mpn_mul_basecase",  speed_mpn_mul_basecase,FLAG_R_OPTIONAL },
+  { "mpn_mul",           speed_mpn_mul,         FLAG_SR_OPTIONAL },
+  { "mpn_mul_basecase",  speed_mpn_mul_basecase,FLAG_SR_OPTIONAL },
   { "mpn_sqr_basecase",  speed_mpn_sqr_basecase     },
 #if HAVE_NATIVE_mpn_sqr_diagonal
   { "mpn_sqr_diagonal",  speed_mpn_sqr_diagonal     },
@@ -576,6 +576,7 @@
 struct choice_t {
   const struct routine_t  *p;
   mp_limb_t               r;
+  double                  size_ratio;
   double                  scale;
   double                  time;
   int                     no_time;
@@ -670,6 +671,7 @@
   for (i = 0; i < num_choices; i++)
     {
       s->r = choice[i].r;
+      s->size_ratio = choice[i].size_ratio;
       choice[i].time = speed_measure (choice[i].p->fun, s);
       choice[i].no_time = (choice[i].time == -1.0);
       if (! choice[i].no_time)
@@ -1011,6 +1013,17 @@
   return n;
 }
 
+double slash_r_string (const char *s)
+{
+  char *end;
+  double r = strtod(s, &end);
+  if (s[0] == '\0' || end[0] != '\0' || r > 1.0 || r < 0.0)
+    {
+      fprintf (stderr, "invalid /r parameter: %s\n", s);
+      exit (1);
+    }
+  return r;
+}
 
 void
 routine_find (struct choice_t *c, const char *s_orig)
@@ -1042,7 +1055,7 @@
         {
           /* match, with a .r parameter */
 
-          if (! (routine[i].flag & (FLAG_R|FLAG_R_OPTIONAL)))
+          if (! (routine[i].flag & (FLAG_R|FLAG_R_OPTIONAL|FLAG_SR_OPTIONAL)))
             {
               fprintf (stderr,
                        "Choice %s bad: doesn't take a \".<r>\" parameter\n",
@@ -1052,6 +1065,24 @@
 
           c->p = &routine[i];
           c->r = r_string (s + nlen + 1);
+          c->size_ratio = 0.0;
+          return;
+        }
+      if (s[nlen] == '/')
+        {
+          /* match, with a /r parameter */
+
+          if (! (routine[i].flag & (FLAG_SR_OPTIONAL)))
+            {
+              fprintf (stderr,
+                       "Choice %s bad: doesn't take a \"/<r>\" parameter\n",
+                       s_orig);
+              exit (1);
+            }
+
+          c->p = &routine[i];
+          c->r = 0;
+          c->size_ratio = slash_r_string (s + nlen + 1);
           return;
         }
 
@@ -1069,6 +1100,7 @@
 
           c->p = &routine[i];
           c->r = 0;
+          c->size_ratio = 0.0;
           return;
         }
     }
@@ -1125,6 +1157,8 @@
         printf ("\t%s.r\n", routine[i].name);
       else if (routine[i].flag & FLAG_R_OPTIONAL)
         printf ("\t%s (optional .r)\n", routine[i].name);
+      else if (routine[i].flag & FLAG_SR_OPTIONAL)
+        printf ("\t%s (optional .r or /r)\n", routine[i].name);
       else
         printf ("\t%s\n", routine[i].name);
     }
@@ -1135,6 +1169,8 @@
   printf ("Special forms for r are \"<N>bits\" for a random N bit number, \"<N>ones\" for\n");
   printf ("N one bits, or \"aas\" for 0xAA..AA.\n");
   printf ("\n");
+  printf ("Routines with an optional \"/r\" take a decimal ratio, for example mpn_mul/0.7.\n");
+  printf ("\n");
   printf ("Times for sizes out of the range accepted by a routine are shown as 0.\n");
   printf ("The fastest routine at each size is marked with a # (free form output only).\n");
   printf ("\n");
diff -r c678b487c101 -r 78ae53e3531e tune/speed.h
--- a/tune/speed.h	Sun Oct 22 17:04:29 2023 +0200
+++ b/tune/speed.h	Mon Nov 20 19:37:26 2023 +0100
@@ -113,6 +113,7 @@
   mp_ptr     yp;	/* second argument */
   mp_size_t  size;	/* size of both arguments */
   mp_limb_t  r;		/* user supplied parameter */
+  double     size_ratio; /* ratio for smaller to larger size, e.g., for mpn_mul */
   mp_size_t  align_xp;	/* alignment of xp */
   mp_size_t  align_yp;	/* alignment of yp */
   mp_size_t  align_wp;	/* intended alignment of wp */
@@ -1122,9 +1123,12 @@
     double    t;							\
     TMP_DECL;								\
 									\
-    size1 = (s->r == 0 ? s->size : s->r);				\
-    if (size1 < 0) size1 = -size1 - s->size;				\
-									\
+    size1 = s->size_ratio * s->size;					\
+    if (size1 == 0)							\
+      {									\
+	size1 = (s->r == 0 ? s->size : s->r);				\
+	if (size1 < 0) size1 = -size1 - s->size;			\
+      }									\
     SPEED_RESTRICT_COND (size1 >= 1);					\
     SPEED_RESTRICT_COND (s->size >= size1);				\
 									\
diff -r c678b487c101 -r 78ae53e3531e tune/tuneup.c
--- a/tune/tuneup.c	Sun Oct 22 17:04:29 2023 +0200
+++ b/tune/tuneup.c	Mon Nov 20 19:37:26 2023 +0100
@@ -2948,6 +2948,7 @@
 #endif
   }
   printf ("\n");
+  s.size_ratio = 0.0;
 
   tune_divrem_1 ();
   tune_mod_1 ();


More information about the gmp-commit mailing list