[Gmp-commit] /var/hg/gmp: tune/: support mpz_invert

mercurial at gmplib.org mercurial at gmplib.org
Fri Dec 30 07:09:47 UTC 2016


details:   /var/hg/gmp/rev/0ce63e6ff725
changeset: 17194:0ce63e6ff725
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Fri Dec 30 07:56:52 2016 +0100
description:
tune/: support mpz_invert

diffstat:

 tune/common.c |  41 +++++++++++++++++++++++++++++++++++++++++
 tune/speed.c  |   1 +
 tune/speed.h  |   1 +
 3 files changed, 43 insertions(+), 0 deletions(-)

diffs (73 lines):

diff -r bc1f3c6a749d -r 0ce63e6ff725 tune/common.c
--- a/tune/common.c	Thu Dec 29 00:41:34 2016 +0100
+++ b/tune/common.c	Fri Dec 30 07:56:52 2016 +0100
@@ -2039,6 +2039,47 @@
 }
 
 
+/* An inverse (s->r) or (s->size)/2 modulo s->size limbs */
+
+double
+speed_mpz_invert (struct speed_params *s)
+{
+  mpz_t     a, m, r;
+  mp_size_t k;
+  unsigned  i;
+  double    t;
+
+  if (s->r == 0)
+    k = s->size/2;
+  else if (s->r < GMP_LIMB_HIGHBIT)
+    k = s->r;
+  else /* s->r < 0 */
+    k = s->size - (-s->r);
+
+  SPEED_RESTRICT_COND (k > 0 && k <= s->size);
+
+  mpz_init_set_n (m, s->yp, s->size);
+  mpz_setbit (m, 0);	/* force m to odd */
+
+  mpz_init_set_n (a, s->xp, k);
+
+  mpz_init (r);
+  while (mpz_invert (r, a, m) == 0)
+    mpz_add_ui (a, a, 1);
+
+  speed_starttime ();
+  i = s->reps;
+  do
+    mpz_invert (r, a, m);
+  while (--i != 0);
+  t = speed_endtime ();
+
+  mpz_clear (r);
+  mpz_clear (a);
+  mpz_clear (m);
+  return t;
+  }
+
 /* If r==0, calculate binomial(size,size/2),
    otherwise calculate binomial(size,r). */
 
diff -r bc1f3c6a749d -r 0ce63e6ff725 tune/speed.c
--- a/tune/speed.c	Thu Dec 29 00:41:34 2016 +0100
+++ b/tune/speed.c	Fri Dec 30 07:56:52 2016 +0100
@@ -403,6 +403,7 @@
   { "mpz_lucnum2_ui",    speed_mpz_lucnum2_ui, FLAG_NODATA },
 
   { "mpz_add",           speed_mpz_add              },
+  { "mpz_invert",        speed_mpz_invert,   FLAG_R_OPTIONAL },
   { "mpz_bin_uiui",      speed_mpz_bin_uiui, FLAG_NODATA | FLAG_R_OPTIONAL },
   { "mpz_bin_ui",        speed_mpz_bin_ui,   FLAG_NODATA | FLAG_R_OPTIONAL },
   { "mpz_fac_ui",        speed_mpz_fac_ui,   FLAG_NODATA   },
diff -r bc1f3c6a749d -r 0ce63e6ff725 tune/speed.h
--- a/tune/speed.h	Thu Dec 29 00:41:34 2016 +0100
+++ b/tune/speed.h	Fri Dec 30 07:56:52 2016 +0100
@@ -384,6 +384,7 @@
 double speed_mpq_init_clear (struct speed_params *);
 
 double speed_mpz_add (struct speed_params *);
+double speed_mpz_invert (struct speed_params *);
 double speed_mpz_bin_uiui (struct speed_params *);
 double speed_mpz_bin_ui (struct speed_params *);
 double speed_mpz_fac_ui (struct speed_params *);


More information about the gmp-commit mailing list