summaryrefslogtreecommitdiff
path: root/tune
diff options
context:
space:
mode:
authorNiels M?ller <nisse@lysator.liu.se>2019-09-23 17:26:46 +0200
committerNiels M?ller <nisse@lysator.liu.se>2019-09-23 17:26:46 +0200
commit5149e9a3ff21e81edcf59825c3e31d2dbbef6a0a (patch)
tree944487c77dcfb17466fd11ff689f8897faaef978 /tune
parentb4b615920b330e37aa4b806674bbeb7a5a284195 (diff)
downloadgmp-5149e9a3ff21e81edcf59825c3e31d2dbbef6a0a.tar.gz
Make tuning of hgcd and gcd take hgcd2 choice into account
* gmp-impl.h (hgcd2_func_t) [TUNE_PROGRAM_BUILD]: New typedef. (hgcd2_func) [TUNE_PROGRAM_BUILD]: New function pointer. * tune/hgcd2.c (mpn_hgcd2): New file, with a redefined function to invoke an implementation via the hgcd2_func function pointer. Initially points to the default implementation in mpn/generic/hgcd2.c. * tune/Makefile.am (tuneup_SOURCES): Add hgcd2.c. * tune/tuneup.c (one_method): Return index of selected function. (tune_hgcd2): Set hgcd2_func to point to selected function. So that the later tuning of mpn_hgcd and mpn_gcd uses the right implementation of hgcd2.
Diffstat (limited to 'tune')
-rw-r--r--tune/Makefile.am2
-rw-r--r--tune/hgcd2.c49
-rw-r--r--tune/tuneup.c27
3 files changed, 65 insertions, 13 deletions
diff --git a/tune/Makefile.am b/tune/Makefile.am
index bb107833c..7a8f04ac7 100644
--- a/tune/Makefile.am
+++ b/tune/Makefile.am
@@ -96,7 +96,7 @@ speed_dynamic_SOURCES = speed.c
speed_ext_SOURCES = speed-ext.c
speed_ext_LDFLAGS = $(STATIC)
-tuneup_SOURCES = tuneup.c
+tuneup_SOURCES = tuneup.c hgcd2.c
nodist_tuneup_SOURCES = sqr_basecase.c fac_ui.c $(TUNE_MPN_SRCS)
tuneup_DEPENDENCIES = $(TUNE_SQR_OBJ) libspeed.la
tuneup_LDADD = $(tuneup_DEPENDENCIES) $(TUNE_LIBS)
diff --git a/tune/hgcd2.c b/tune/hgcd2.c
new file mode 100644
index 000000000..146af7217
--- /dev/null
+++ b/tune/hgcd2.c
@@ -0,0 +1,49 @@
+/* mpn/generic/hgcd2.c for tuning
+
+Copyright 2019 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of either:
+
+ * the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 3 of the License, or (at your
+ option) any later version.
+
+or
+
+ * the GNU General Public License as published by the Free Software
+ Foundation; either version 2 of the License, or (at your option) any
+ later version.
+
+or both in parallel, as here.
+
+The GNU MP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received copies of the GNU General Public License and the
+GNU Lesser General Public License along with the GNU MP Library. If not,
+see https://www.gnu.org/licenses/. */
+
+#define TUNE_PROGRAM_BUILD 1
+
+#include "gmp-impl.h"
+
+hgcd2_func_t mpn_hgcd2_default;
+
+hgcd2_func_t *hgcd2_func = &mpn_hgcd2_default;
+
+int
+mpn_hgcd2 (mp_limb_t ah, mp_limb_t al, mp_limb_t bh, mp_limb_t bl,
+ struct hgcd_matrix1 *M)
+{
+ return hgcd2_func(ah, al, bh, bl, M);
+}
+
+#undef mpn_hgcd2
+#define mpn_hgcd2 mpn_hgcd2_default
+
+#include "mpn/generic/hgcd2.c"
diff --git a/tune/tuneup.c b/tune/tuneup.c
index fd7ecbac9..94926d653 100644
--- a/tune/tuneup.c
+++ b/tune/tuneup.c
@@ -716,8 +716,11 @@ one (mp_size_t *threshold, struct param_t *param)
select the fastest. Since *_METHOD defines start numbering from
one, if functions[i] is fastest, the value of the define is i+1.
Also output a comment with speedup compared to the next fastest
- function. The NAME argument is used only for trace output.*/
-void
+ function. The NAME argument is used only for trace output.
+
+ Returns the index of the fastest function.
+*/
+int
one_method (int n, speed_function_t *functions,
const char *name, const char *define,
const struct param_t *param)
@@ -757,6 +760,7 @@ one_method (int n, speed_function_t *functions,
t[method_runner_up] / t[method]);
TMP_FREE;
+ return method;
}
@@ -1958,15 +1962,17 @@ void
tune_hgcd2 (void)
{
static struct param_t param;
- speed_function_t f[3] =
- {
- speed_mpn_hgcd2_1,
- speed_mpn_hgcd2_2,
- speed_mpn_hgcd2_3,
- };
+ hgcd2_func_t *f[3] =
+ { mpn_hgcd2_1, mpn_hgcd2_2, mpn_hgcd2_3 };
+ speed_function_t speed_f[3] =
+ { speed_mpn_hgcd2_1, speed_mpn_hgcd2_2, speed_mpn_hgcd2_3 };
+ int best;
s.size = 1;
- one_method (3, f, "mpn_hgcd2", "HGCD2_DIV1_METHOD", &param);
+ best = one_method (3, speed_f, "mpn_hgcd2", "HGCD2_DIV1_METHOD", &param);
+
+ /* Use selected function when tuning hgcd and gcd */
+ hgcd2_func = f[best];
}
void
@@ -2236,9 +2242,6 @@ tune_divrem_1 (void)
void
tune_div_qr_1 (void)
{
- static struct param_t param;
- double t1, t2;
-
if (!HAVE_NATIVE_mpn_div_qr_1n_pi1)
{
static struct param_t param;