GCD project status?

Niels Möller nisse at lysator.liu.se
Sun Sep 22 08:23:19 UTC 2019


nisse at lysator.liu.se (Niels Möller) writes:

> Hmm. So the hgcd2-x-y.c would be there als for speed, and hgcd2.c would
> have something like
>
> #if TUNE_PROGRAM_BUILD
> int mpn_hgcd2(...)
> {
>   return (*hgcd2_method_pointer)(...);
> }

See below patch. 

diff -r 3e04a9bbba13 gmp-impl.h
--- a/gmp-impl.h	Fri Sep 20 20:36:30 2019 +0200
+++ b/gmp-impl.h	Sun Sep 22 10:19:06 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 3e04a9bbba13 tune/Makefile.am
--- a/tune/Makefile.am	Fri Sep 20 20:36:30 2019 +0200
+++ b/tune/Makefile.am	Sun Sep 22 10:19:06 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 3e04a9bbba13 tune/hgcd2.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tune/hgcd2.c	Sun Sep 22 10:19:06 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 3e04a9bbba13 tune/tuneup.c
--- a/tune/tuneup.c	Fri Sep 20 20:36:30 2019 +0200
+++ b/tune/tuneup.c	Sun Sep 22 10:19:06 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", &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 @@
 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;


-- 
Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677.
Internet email is subject to wholesale government surveillance.


More information about the gmp-devel mailing list