[Gmp-commit] /var/hg/gmp: 5 new changesets

mercurial at gmplib.org mercurial at gmplib.org
Sun Jan 5 09:37:47 UTC 2014


details:   /var/hg/gmp/rev/10e18c31f5d6
changeset: 16162:10e18c31f5d6
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Jan 05 10:07:55 2014 +0100
description:
tests/mpn/t-minvert.c: always compare with mpz_invert results.

details:   /var/hg/gmp/rev/05ac6d1bad54
changeset: 16163:05ac6d1bad54
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Jan 05 10:23:00 2014 +0100
description:
tests/mpn/t-sizeinbase.c: New test.

details:   /var/hg/gmp/rev/19f018d8a5ce
changeset: 16164:19f018d8a5ce
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Jan 05 10:27:53 2014 +0100
description:
ChangeLog

details:   /var/hg/gmp/rev/10c0e6509ccb
changeset: 16165:10c0e6509ccb
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Jan 05 10:28:20 2014 +0100
description:
mpn/generic/pow_1.c: micro-opt.

details:   /var/hg/gmp/rev/7b875bb261b3
changeset: 16166:7b875bb261b3
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Jan 05 10:30:24 2014 +0100
description:
ChangeLog

diffstat:

 ChangeLog                |    8 +++
 mpn/generic/pow_1.c      |    8 ++-
 tests/mpn/Makefile.am    |    4 +-
 tests/mpn/t-minvert.c    |   11 +---
 tests/mpn/t-sizeinbase.c |  108 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 125 insertions(+), 14 deletions(-)

diffs (192 lines):

diff -r 88dfcecd000d -r 7b875bb261b3 ChangeLog
--- a/ChangeLog	Sat Jan 04 21:18:58 2014 +0100
+++ b/ChangeLog	Sun Jan 05 10:30:24 2014 +0100
@@ -1,3 +1,11 @@
+2014-01-05 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* tests/mpn/t-minvert.c: Always compare with mpz_invert results.
+	* tests/mpn/t-sizeinbase.c: New test.
+	* tests/mpn/Makefile.am (check_PROGRAMS): Added t-sizeinbase.c .
+
+	* mpn/generic/pow_1.c: Micro-optimisation.
+
 2014-01-04  Torbjorn Granlund  <tege at gmplib.org>
 
 	* acinclude.m4 (GMP_PROG_M4): Avoid hex output, since case varies.
diff -r 88dfcecd000d -r 7b875bb261b3 mpn/generic/pow_1.c
--- a/mpn/generic/pow_1.c	Sat Jan 04 21:18:58 2014 +0100
+++ b/mpn/generic/pow_1.c	Sun Jan 05 10:30:24 2014 +0100
@@ -57,11 +57,13 @@
      so much time that the slowness of this code will be negligible.  */
   par = 0;
   cnt = GMP_LIMB_BITS;
-  for (x = exp; x != 0; x >>= 1)
+  x = exp;
+  do
     {
-      par ^= x & 1;
+      par ^= x;
       cnt--;
-    }
+      x >>= 1;
+    } while (x != 0);
   exp <<= cnt;
 
   if (bn == 1)
diff -r 88dfcecd000d -r 7b875bb261b3 tests/mpn/Makefile.am
--- a/tests/mpn/Makefile.am	Sat Jan 04 21:18:58 2014 +0100
+++ b/tests/mpn/Makefile.am	Sun Jan 05 10:30:24 2014 +0100
@@ -1,6 +1,6 @@
 ## Process this file with automake to generate Makefile.in
 
-# Copyright 2001-2003, 2009-2012 Free Software Foundation, Inc.
+# Copyright 2001-2003, 2009-2014 Free Software Foundation, Inc.
 #
 # This file is part of the GNU MP Library test suite.
 #
@@ -28,7 +28,7 @@
   t-toom2-sqr t-toom3-sqr t-toom4-sqr t-toom6-sqr t-toom8-sqr		\
   t-mul t-mullo t-mulmod_bnm1 t-sqrmod_bnm1 t-mulmid			\
   t-hgcd t-hgcd_appr t-matrix22 t-invert t-div t-bdiv			\
-  t-broot t-brootinv t-minvert
+  t-broot t-brootinv t-minvert t-sizeinbase
 
 EXTRA_DIST = toom-shared.h toom-sqr-shared.h
 
diff -r 88dfcecd000d -r 7b875bb261b3 tests/mpn/t-minvert.c
--- a/tests/mpn/t-minvert.c	Sat Jan 04 21:18:58 2014 +0100
+++ b/tests/mpn/t-minvert.c	Sun Jan 05 10:30:24 2014 +0100
@@ -1,4 +1,4 @@
-/* Copyright 2013 Free Software Foundation, Inc.
+/* Copyright 2013, 2014 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library test suite.
 
@@ -119,14 +119,7 @@
 	      }
 	}
 
-      if (mpz_cmp_ui (m, 1) == 0)
-	{
-	  /* mpn_sec_minvert considers a^{-1} = 0 (mod 1) for all a */
-	  rres = 1;
-	  mpz_set_ui (r, 0);
-	}
-      else
-	rres = mpz_invert (r, a, m);
+      rres = mpz_invert (r, a, m);
       if ( (test & 4) && !rres)
 	{
 	  gmp_fprintf (stderr, "test %d: Not invertible!\n"
diff -r 88dfcecd000d -r 7b875bb261b3 tests/mpn/t-sizeinbase.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/mpn/t-sizeinbase.c	Sun Jan 05 10:30:24 2014 +0100
@@ -0,0 +1,108 @@
+/* Test for sizeinbase function.
+
+Copyright 2014 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library test suite.
+
+The GNU MP Library test suite is free software; you can redistribute it
+and/or modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 3 of the License,
+or (at your option) any later version.
+
+The GNU MP Library test suite 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 a copy of the GNU General Public License along with
+the GNU MP Library test suite.  If not, see https://www.gnu.org/licenses/.  */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "gmp.h"
+#include "gmp-impl.h"
+#include "tests.h"
+
+/* Exponents up to 2^SIZE_LOG */
+#ifndef SIZE_LOG
+#define SIZE_LOG 13
+#endif
+
+#ifndef COUNT
+#define COUNT 30
+#endif
+
+#define MAX_N (1<<SIZE_LOG)
+
+int
+main (int argc, char **argv)
+{
+  mp_limb_t a;
+  mp_ptr pp, scratch;
+  mp_limb_t max_b;
+  int count = COUNT;
+  int test;
+  gmp_randstate_ptr rands;
+  TMP_DECL;
+
+  if (argc > 1)
+    {
+      char *end;
+      count = strtol (argv[1], &end, 0);
+      if (*end || count <= 0)
+	{
+	  fprintf (stderr, "Invalid test count: %s.\n", argv[1]);
+	  return 1;
+	}
+    }
+
+  tests_start ();
+  TMP_MARK;
+  rands = RANDS;
+
+  pp = TMP_ALLOC_LIMBS (MAX_N);
+  scratch = TMP_ALLOC_LIMBS (MAX_N);
+  max_b = numberof (mp_bases);
+
+  ASSERT_ALWAYS (max_b > 62);
+  ASSERT_ALWAYS (max_b < GMP_NUMB_MAX);
+
+  for (a = 2; a < max_b; ++a)
+    for (test = 0; test < count; ++test)
+      {
+	mp_size_t pn;
+	mp_limb_t exp;
+	mp_bitcnt_t res;
+
+	exp = gmp_urandomm_ui (rands, MAX_N);
+
+	pn = mpn_pow_1 (pp, &a, 1, exp, scratch);
+
+	res = mpn_sizeinbase (pp, pn, a) - 1;
+
+	if ((res < exp) || (res > exp + 1))
+	  {
+	    printf ("ERROR in test %d, base = %d, exp = %d, res = %d\n",
+		    test, (int) a, (int) exp, (int) res);
+	    abort();
+	  }
+
+	mpn_sub_1 (pp, pp, pn, CNST_LIMB(1));
+	pn -= pp[pn-1] == 0;
+
+	res = mpn_sizeinbase (pp, pn, a);
+
+	if ((res < exp) || (res - 1 > exp))
+	  {
+	    printf ("ERROR in -1 test %d, base = %d, exp = %d, res = %d\n",
+		    test, (int) a, (int) exp, (int) res);
+	    abort();
+	  }
+      }
+
+  TMP_FREE;
+  tests_end ();
+  return 0;
+}


More information about the gmp-commit mailing list