[Gmp-commit] /var/hg/gmp: Add optional /r (for size ratio) to speed program.
mercurial at gmplib.org
mercurial at gmplib.org
Sun Sep 24 17:22:05 CEST 2023
details: /var/hg/gmp/rev/a12813260de7
changeset: 18454:a12813260de7
user: Niels Möller <nisse at lysator.liu.se>
date: Sun Sep 24 17:21:44 2023 +0200
description:
Add optional /r (for size ratio) to speed program.
diffstat:
ChangeLog | 14 +++++++++++++
tune/speed.c | 63 +++++++++++++++++++++++++++++++++++++++++++++--------------
tune/speed.h | 11 +++++++--
3 files changed, 70 insertions(+), 18 deletions(-)
diffs (182 lines):
diff -r 8225bdfc499f -r a12813260de7 ChangeLog
--- a/ChangeLog Tue Sep 05 18:32:26 2023 +0200
+++ b/ChangeLog Sun Sep 24 17:21:44 2023 +0200
@@ -1,3 +1,17 @@
+2023-09-24 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 all unbalanced multiplication
+ functions.
+ (slash_r_string): New function, parse float ratio.
+ (run_one): Copy size_ratio field.
+ (routine_find): Handle optional /r.
+ (usage): Deisplay 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 8225bdfc499f -r a12813260de7 tune/speed.c
--- a/tune/speed.c Tue Sep 05 18:32:26 2023 +0200
+++ b/tune/speed.c Sun Sep 24 17:21:44 2023 +0200
@@ -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 },
@@ -346,22 +346,22 @@
{ "mpn_toom4_sqr", speed_mpn_toom4_sqr },
{ "mpn_toom6_sqr", speed_mpn_toom6_sqr },
{ "mpn_toom8_sqr", speed_mpn_toom8_sqr },
- { "mpn_toom22_mul", speed_mpn_toom22_mul },
- { "mpn_toom33_mul", speed_mpn_toom33_mul },
- { "mpn_toom44_mul", speed_mpn_toom44_mul },
- { "mpn_toom6h_mul", speed_mpn_toom6h_mul },
- { "mpn_toom8h_mul", speed_mpn_toom8h_mul },
- { "mpn_toom32_mul", speed_mpn_toom32_mul },
- { "mpn_toom42_mul", speed_mpn_toom42_mul },
- { "mpn_toom43_mul", speed_mpn_toom43_mul },
- { "mpn_toom63_mul", speed_mpn_toom63_mul },
- { "mpn_nussbaumer_mul", speed_mpn_nussbaumer_mul },
+ { "mpn_toom22_mul", speed_mpn_toom22_mul, FLAG_SR_OPTIONAL },
+ { "mpn_toom33_mul", speed_mpn_toom33_mul, FLAG_SR_OPTIONAL },
+ { "mpn_toom44_mul", speed_mpn_toom44_mul, FLAG_SR_OPTIONAL },
+ { "mpn_toom6h_mul", speed_mpn_toom6h_mul, FLAG_SR_OPTIONAL },
+ { "mpn_toom8h_mul", speed_mpn_toom8h_mul, FLAG_SR_OPTIONAL },
+ { "mpn_toom32_mul", speed_mpn_toom32_mul, FLAG_SR_OPTIONAL },
+ { "mpn_toom42_mul", speed_mpn_toom42_mul, FLAG_SR_OPTIONAL },
+ { "mpn_toom43_mul", speed_mpn_toom43_mul, FLAG_SR_OPTIONAL },
+ { "mpn_toom63_mul", speed_mpn_toom63_mul, FLAG_SR_OPTIONAL },
+ { "mpn_nussbaumer_mul", speed_mpn_nussbaumer_mul, FLAG_SR_OPTIONAL},
{ "mpn_nussbaumer_mul_sqr",speed_mpn_nussbaumer_mul_sqr},
#if WANT_OLD_FFT_FULL
- { "mpn_mul_fft_full", speed_mpn_mul_fft_full },
+ { "mpn_mul_fft_full", speed_mpn_mul_fft_full, FLAG_SR_OPTIONAL},
{ "mpn_mul_fft_full_sqr", speed_mpn_mul_fft_full_sqr },
#endif
- { "mpn_mul_fft", speed_mpn_mul_fft, FLAG_R_OPTIONAL },
+ { "mpn_mul_fft", speed_mpn_mul_fft, FLAG_SR_OPTIONAL },
{ "mpn_mul_fft_sqr", speed_mpn_mul_fft_sqr, FLAG_R_OPTIONAL },
{ "mpn_sqrlo", speed_mpn_sqrlo },
@@ -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)
@@ -1054,6 +1067,22 @@
c->r = r_string (s + nlen + 1);
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->size_ratio = slash_r_string (s + nlen + 1);
+ return;
+ }
if (s[nlen] == '\0')
{
@@ -1125,6 +1154,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 +1166,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 8225bdfc499f -r a12813260de7 tune/speed.h
--- a/tune/speed.h Tue Sep 05 18:32:26 2023 +0200
+++ b/tune/speed.h Sun Sep 24 17:21:44 2023 +0200
@@ -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,13 @@
double t; \
TMP_DECL; \
\
- size1 = (s->r == 0 ? s->size : s->r); \
- if (size1 < 0) size1 = -size1 - s->size; \
- \
+ if (s->size_ratio > 0.0) \
+ size1 = s->size_ratio * s->size; \
+ else \
+ { \
+ 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); \
\
More information about the gmp-commit
mailing list