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

mercurial at gmplib.org mercurial at gmplib.org
Thu Jun 8 04:41:52 UTC 2017


details:   /var/hg/gmp/rev/1479deb286c2
changeset: 17441:1479deb286c2
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Jun 08 00:17:45 2017 +0200
description:
tests/devel/sqrtrem_1_2.c (check_some_values): Support two limb sizes.

details:   /var/hg/gmp/rev/c6c92db6c9d6
changeset: 17442:c6c92db6c9d6
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Jun 08 06:33:45 2017 +0200
description:
tests/devel/sqrtrem_1_2.c: allow some faster tests.

diffstat:

 tests/devel/sqrtrem_1_2.c |  135 ++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 114 insertions(+), 21 deletions(-)

diffs (249 lines):

diff -r cc7270a8e51e -r c6c92db6c9d6 tests/devel/sqrtrem_1_2.c
--- a/tests/devel/sqrtrem_1_2.c	Wed Jun 07 20:26:29 2017 +0200
+++ b/tests/devel/sqrtrem_1_2.c	Thu Jun 08 06:33:45 2017 +0200
@@ -49,8 +49,8 @@
 #include "gmp-impl.h"
 #include "longlong.h"
 #include "tests.h"
-/* #define STOP(x) return (x) */
-#define STOP(x) x
+#define STOP(x) return (x)
+/* #define STOP(x) x */
 #define SPINNER(v)					\
   do {							\
     MPN_SIZEINBASE_2EXP (spinner_count, q, v, 1);	\
@@ -65,16 +65,20 @@
 }
 
 int
-check_all_values (int justone)
+check_all_values (int justone, int quick)
 {
   mp_limb_t es, mer, er, s[1], r[2], q[2];
   mp_size_t x;
   unsigned bits;
 
   es=1;
+  if (quick) {
+    printf ("Quick, skipping some... (%u)\n", GMP_NUMB_BITS - 2);
+    es <<= GMP_NUMB_BITS / 2 - 1;
+  }
   er=0;
-  mer=2;
-  *q = 1;
+  mer= es << 1;
+  *q = es * es;
   printf ("All values tested, up to bits:\n");
   do {
     x = mpn_sqrtrem (s, r, q, 1);
@@ -115,9 +119,9 @@
       ++er;
     q[1] += (++*q == 0);
   } while (1);
-  MPN_SIZEINBASE_2EXP (bits, q, 2, 1);
-  printf("\n%u\n", bits);
+  SPINNER(2);
   printf ("\nValues with at most a limb for reminder, tested.\n");
+  printf ("Testing more values not supported, jet.\n");
   return 0;
 }
 
@@ -146,13 +150,17 @@
 }
 
 int
-check_some_values (int justone)
+check_some_values (int justone, int quick)
 {
-  mp_limb_t es, mer, er, k, s[1], r[2], q[2];
+  mp_limb_t es, her, er, k, s[1], r[2], q[2];
   mp_size_t x;
   unsigned bits;
 
   es = 1 << 1;
+  if (quick) {
+    es <<= GMP_NUMB_BITS / 4 - 1;
+    printf ("Quick, skipping some... (%u)\n", GMP_NUMB_BITS / 2);
+  }
   er = 0;
   *q = es * es;
   printf ("High-half values tested, up to bits:\n");
@@ -164,6 +172,8 @@
 	  || UNLIKELY ((x == 1) && (er != *r)))
 	STOP (something_wrong (er, 0, es));
 
+      if (UNLIKELY ((es & 0xffff) == 0))
+	SPINNER(1);
       if ((*q & k) == 0) {
 	*q |= k;
 	er = upd (&es, k + er);
@@ -171,28 +181,100 @@
 	++*q;
 	er = upd1 (&es, er);
       }
-      if (UNLIKELY ((es & 0xffff) == 0))
-	SPINNER(1);
     } while (es & k);
   } while (*q != 0);
   q[1] = 1;
   SPINNER(2);
   printf ("\nValues of a single limb, tested.\n");
   if (justone) return 0;
-  printf ("Testing more values not supported, jet.\n");
-  return -1;
+  if (quick) {
+    es <<= GMP_NUMB_BITS / 2 - 1;
+    q[1] <<= GMP_NUMB_BITS - 2;
+    printf ("Quick, skipping some... (%u)\n", GMP_NUMB_BITS - 2);
+  }
+  printf ("High-half values tested, up to bits:\n");
+  do {
+    x = mpn_sqrtrem (s, r, q, 2);
+    if (UNLIKELY (x != (er != 0)) || UNLIKELY (*s != es)
+	|| UNLIKELY ((x == 1) && (er != *r)))
+      STOP (something_wrong (er, 0, es));
+
+    if (*q == 0) {
+      *q = GMP_NUMB_MAX;
+      if (UNLIKELY ((es & 0xffff) == 0)) {
+	if (UNLIKELY (es == GMP_NUMB_HIGHBIT))
+	  break;
+	SPINNER(2);
+      }
+      /* er = er + GMP_NUMB_MAX - 1 - es*2 // postponed */
+      ++es;
+      /* er = er + GMP_NUMB_MAX - 1 - 2*(es-1) =
+            = er +(GMP_NUMB_MAX + 1)- 2* es = er - 2*es */
+      er = upd (&es, er - 2 * es);
+    } else {
+      *q = 0;
+      ++q[1];
+      er = upd1 (&es, er);
+    }
+  } while (1);
+  SPINNER(2);
+  printf ("\nValues with at most a limb for reminder, tested.\n");
+  er = GMP_NUMB_MAX; her = 0;
+  
+  printf ("High-half values tested, up to bits:\n");
+  do {
+    x = mpn_sqrtrem (s, r, q, 2);
+    if (UNLIKELY (x != (her?2:(er != 0))) || UNLIKELY (*s != es)
+	|| UNLIKELY ((x != 0) && ((er != *r) || ((x == 2) && (r[1] != 1)))))
+      STOP (something_wrong (er, her, es));
+
+    if (*q == 0) {
+      *q = GMP_NUMB_MAX;
+      if (UNLIKELY ((es & 0xffff) == 0)) {
+	SPINNER(2);
+      }
+      if (her) {
+	++es;
+	her = 0;
+	er = er - 2 * es;
+      } else {
+	her = --er != GMP_NUMB_MAX;
+	if (her & (er > es * 2)) {
+	  er -= es * 2 + 1;
+	  her = 0;
+	  ++es;
+	}
+      }
+    } else {
+      *q = 0;
+      if (++q[1] == 0) break;
+      if ((her == 0) | (er < es * 2)) {
+	her += ++er == 0;
+      }	else {
+	  er -= es * 2;
+	  her = 0;
+	  ++es;
+      }
+    }
+  } while (1);
+  printf ("| %u\nValues of at most two limbs, tested.\n", GMP_NUMB_BITS*2);
+  return 0;
 }
 
 int
-check_corner_cases (int justone)
+check_corner_cases (int justone, int quick)
 {
   mp_limb_t es, er, s[1], r[2], q[2];
   mp_size_t x;
   unsigned bits;
 
   es = 1;
+  if (quick) {
+    es <<= GMP_NUMB_BITS / 2 - 1;
+    printf ("Quick, skipping some... (%u)\n", GMP_NUMB_BITS - 2);
+  }
   er = 0;
-  *q = 1;
+  *q = es*es;
   printf ("Corner cases tested, up to bits:\n");
   do {
     x = mpn_sqrtrem (s, r, q, 1);
@@ -215,6 +297,14 @@
   SPINNER(2);
   printf ("\nValues of a single limb, tested.\n");
   if (justone) return 0;
+  if (quick) {
+    es <<= GMP_NUMB_BITS / 2 - 1;
+    q[1] <<= GMP_NUMB_BITS - 2;
+    printf ("Quick, skipping some... (%u)\n", GMP_NUMB_BITS - 2);
+    --es;
+    --q[1];
+    q[0] -= es*2+1;
+  }
   printf ("Corner cases tested, up to bits:\n");
   do {
     x = mpn_sqrtrem (s, r, q, 2);
@@ -265,8 +355,7 @@
       add_ssaaaa (q[1], *q, q[1], *q, 1, er);
     }
   } while (1);
-  MPN_SIZEINBASE_2EXP (bits, q, 2, 1);
-  printf ("\n%u\nValues of at most two limbs, tested.\n", bits);
+  printf ("| %u\nValues of at most two limbs, tested.\n", GMP_NUMB_BITS*2);
   return 0;
 }
 
@@ -275,11 +364,12 @@
 {
   int mode = 0;
   int justone = 0;
+  int quick = 0;
 
   for (;argc > 1;--argc,++argv)
     switch (*argv[1]) {
     default:
-      fprintf (stderr, "usage: sqrtrem_1_2 [x|c|s] [1|2]\n");
+      fprintf (stderr, "usage: sqrtrem_1_2 [x|c|s] [1|2] [q]\n");
       exit (1);
     case 'x':
       mode = 0;
@@ -290,6 +380,9 @@
     case 's':
       mode = 2;
       break;
+    case 'q':
+      quick = 1;
+      break;
     case '1':
       justone = 1;
       break;
@@ -299,10 +392,10 @@
 
   switch (mode) {
   default:
-    return check_all_values (justone);
+    return check_all_values (justone, quick);
   case 1:
-    return check_corner_cases (justone);
+    return check_corner_cases (justone, quick);
   case 2:
-    return check_some_values (justone);
+    return check_some_values (justone, quick);
   }
 }


More information about the gmp-commit mailing list