[Gmp-commit] /var/hg/gmp: Make tuning of hgcd and gcd take hgcd2 choice into ...
mercurial at gmplib.org
mercurial at gmplib.org
Mon Sep 23 15:26:57 UTC 2019
details: /var/hg/gmp/rev/f9792b5ae2ec
changeset: 17923:f9792b5ae2ec
user: Niels M?ller <nisse at lysator.liu.se>
date: Mon Sep 23 17:26:46 2019 +0200
description:
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:
ChangeLog | 16 ++++++++++++++++
gmp-impl.h | 4 ++++
tune/Makefile.am | 2 +-
tune/hgcd2.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
tune/tuneup.c | 27 +++++++++++++++------------
5 files changed, 85 insertions(+), 13 deletions(-)
diffs (162 lines):
diff -r 882413828d04 -r f9792b5ae2ec ChangeLog
--- a/ChangeLog Mon Sep 23 16:55:18 2019 +0200
+++ b/ChangeLog Mon Sep 23 17:26:46 2019 +0200
@@ -1,3 +1,19 @@
+2019-09-23 Niels Möller <nisse at lysator.liu.se>
+
+ * 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.
+
2019-09-18 Torbjörn Granlund <tg at gmplib.org>
* mpn/generic/hgcd2.c (div1, div2): Rearrange things to allow for asm.
diff -r 882413828d04 -r f9792b5ae2ec gmp-impl.h
--- a/gmp-impl.h Mon Sep 23 16:55:18 2019 +0200
+++ b/gmp-impl.h Mon Sep 23 17:26:46 2019 +0200
@@ -4949,6 +4949,10 @@
#define MATRIX22_STRASSEN_THRESHOLD matrix22_strassen_threshold
extern mp_size_t matrix22_strassen_threshold;
+typedef int hgcd2_func_t (mp_limb_t, mp_limb_t, mp_limb_t, mp_limb_t,
+ struct hgcd_matrix1 *);
+extern hgcd2_func_t *hgcd2_func;
+
#undef HGCD_THRESHOLD
#define HGCD_THRESHOLD hgcd_threshold
extern mp_size_t hgcd_threshold;
diff -r 882413828d04 -r f9792b5ae2ec tune/Makefile.am
--- a/tune/Makefile.am Mon Sep 23 16:55:18 2019 +0200
+++ b/tune/Makefile.am Mon Sep 23 17:26:46 2019 +0200
@@ -96,7 +96,7 @@
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 -r 882413828d04 -r f9792b5ae2ec tune/hgcd2.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tune/hgcd2.c Mon Sep 23 17:26:46 2019 +0200
@@ -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 -r 882413828d04 -r f9792b5ae2ec tune/tuneup.c
--- a/tune/tuneup.c Mon Sep 23 16:55:18 2019 +0200
+++ b/tune/tuneup.c Mon Sep 23 17:26:46 2019 +0200
@@ -716,8 +716,11 @@
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 @@
t[method_runner_up] / t[method]);
TMP_FREE;
+ return method;
}
@@ -1958,15 +1962,17 @@
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", ¶m);
+ best = one_method (3, speed_f, "mpn_hgcd2", "HGCD2_DIV1_METHOD", ¶m);
+
+ /* Use selected function when tuning hgcd and gcd */
+ hgcd2_func = f[best];
}
void
@@ -2236,9 +2242,6 @@
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;
More information about the gmp-commit
mailing list