[Gmp-commit] /var/hg/gmp: Test mpn_sec_add_1 and mpn_sec_sub_1. Pass smaller ...

mercurial at gmplib.org mercurial at gmplib.org
Sat Jan 18 18:09:12 UTC 2014


details:   /var/hg/gmp/rev/7079887fac7b
changeset: 16200:7079887fac7b
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Sat Jan 18 19:08:43 2014 +0100
description:
Test mpn_sec_add_1 and mpn_sec_sub_1. Pass smaller bit_size to mpn_sec_minvert tests

diffstat:

 ChangeLog             |   7 +++++++
 tests/mpn/t-aors_1.c  |  40 ++++++++++++++++++++++++++++++++++++++++
 tests/mpn/t-minvert.c |  11 ++++++++++-
 3 files changed, 57 insertions(+), 1 deletions(-)

diffs (127 lines):

diff -r 4f0bb1002c5c -r 7079887fac7b ChangeLog
--- a/ChangeLog	Sat Jan 18 17:41:28 2014 +0100
+++ b/ChangeLog	Sat Jan 18 19:08:43 2014 +0100
@@ -1,3 +1,10 @@
+2014-01-18  Niels Möller  <nisse at lysator.liu.se>
+
+	* tests/mpn/t-aors_1.c: Test also mpn_sec_add_1 and mpn_sec_sub_1.
+
+	* tests/mpn/t-minvert.c (main): Pass smallest allowed bit_size
+	argument to mpn_sec_minvert.
+
 2014-01-18  Marc Glisse  <marc.glisse at inria.fr>
 
 	* doc/gmp.texi (C++ Interface Limitations): Warn against C++11 auto.
diff -r 4f0bb1002c5c -r 7079887fac7b tests/mpn/t-aors_1.c
--- a/tests/mpn/t-aors_1.c	Sat Jan 18 17:41:28 2014 +0100
+++ b/tests/mpn/t-aors_1.c	Sat Jan 18 19:08:43 2014 +0100
@@ -133,6 +133,8 @@
 
   mp_limb_t  got[ASIZE];
   mp_limb_t  got_c;
+  /* mpn_sec_add_a_itch(n) <= n */
+  mp_limb_t  scratch[ASIZE];
   int        i;
 
   for (i = 0; i < numberof (data); i++)
@@ -145,6 +147,14 @@
       got_c = mpn_add_1 (got, got, data[i].size, data[i].n);
       VERIFY ("check_add_1 (in-place)");
 
+      SETUP ();
+      got_c = mpn_sec_add_1 (got, data[i].src, data[i].size, data[i].n, scratch);
+      VERIFY ("check_sec_add_1 (separate)");
+
+      SETUP_INPLACE ();
+      got_c = mpn_sec_add_1 (got, got, data[i].size, data[i].n, scratch);
+      VERIFY ("check_sec_add_1 (in-place)");
+
       if (data[i].n == 1)
         {
           SETUP ();
@@ -154,6 +164,16 @@
           SETUP_INPLACE ();
           got_c = mpn_add_1 (got, got, data[i].size, CNST_LIMB(1));
           VERIFY ("check_add_1 (in-place, const 1)");
+
+          SETUP ();
+          got_c = mpn_sec_add_1 (got, data[i].src, data[i].size,
+				 CNST_LIMB(1), scratch);
+          VERIFY ("check_sec_add_1 (separate, const 1)");
+
+          SETUP_INPLACE ();
+          got_c = mpn_sec_add_1 (got, got, data[i].size,
+				 CNST_LIMB(1), scratch);
+          VERIFY ("check_sec_add_1 (in-place, const 1)");
         }
 
       /* Same again on functions, not inlines. */
@@ -212,6 +232,8 @@
 
   mp_limb_t  got[ASIZE];
   mp_limb_t  got_c;
+  /* mpn_sec_sub_1_itch(n) <= n */
+  mp_limb_t  scratch[ASIZE];
   int        i;
 
   for (i = 0; i < numberof (data); i++)
@@ -224,6 +246,14 @@
       got_c = mpn_sub_1 (got, got, data[i].size, data[i].n);
       VERIFY ("check_sub_1 (in-place)");
 
+      SETUP ();
+      got_c = mpn_sec_sub_1 (got, data[i].src, data[i].size, data[i].n, scratch);
+      VERIFY ("check_sec_sub_1 (separate)");
+
+      SETUP_INPLACE ();
+      got_c = mpn_sec_sub_1 (got, got, data[i].size, data[i].n, scratch);
+      VERIFY ("check_sec_sub_1 (in-place)");
+
       if (data[i].n == 1)
         {
           SETUP ();
@@ -233,6 +263,16 @@
           SETUP_INPLACE ();
           got_c = mpn_sub_1 (got, got, data[i].size, CNST_LIMB(1));
           VERIFY ("check_sub_1 (in-place, const 1)");
+
+          SETUP ();
+          got_c = mpn_sec_sub_1 (got, data[i].src, data[i].size,
+				 CNST_LIMB(1), scratch);
+          VERIFY ("check_sec_sub_1 (separate, const 1)");
+
+          SETUP_INPLACE ();
+          got_c = mpn_sec_sub_1 (got, got, data[i].size,
+				 CNST_LIMB(1), scratch);
+          VERIFY ("check_sec_sub_1 (in-place, const 1)");
         }
 
       /* Same again on functions, not inlines. */
diff -r 4f0bb1002c5c -r 7079887fac7b tests/mpn/t-minvert.c
--- a/tests/mpn/t-minvert.c	Sat Jan 18 17:41:28 2014 +0100
+++ b/tests/mpn/t-minvert.c	Sat Jan 18 19:08:43 2014 +0100
@@ -46,6 +46,13 @@
 	  && mpn_zero_p (ap + bn, an - bn));
 }
 
+static mp_bitcnt_t
+bit_size (mp_srcptr xp, mp_size_t n)
+{
+  MPN_NORMALIZE (xp, n);
+  return n > 0 ? mpn_sizeinbase (xp, n, 2) : 0;
+}
+
 int
 main (int argc, char **argv)
 {
@@ -140,7 +147,9 @@
       mpz_to_mpn (ap, n, a);
       mpz_to_mpn (mp, n, m);
       tres = mpn_sec_minvert (tp,
-			      ap, mp, n, 2*bits, scratch);
+			      ap, mp, n,
+			      bit_size (ap, n) + bit_size (mp, n),
+			      scratch);
 
       if (rres != tres || (rres == 1 && !mpz_eq_mpn (tp, n, r)) || ran != scratch[itch])
 	{


More information about the gmp-commit mailing list