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

mercurial at gmplib.org mercurial at gmplib.org
Sun Jan 20 13:04:10 CET 2013


details:   /var/hg/gmp/rev/61990c8418e7
changeset: 15329:61990c8418e7
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Sun Jan 20 13:03:58 2013 +0100
description:
(main): Separate divisor into normalised (dnp) and unnormalised (dup), pass appropriate variant to each function.

details:   /var/hg/gmp/rev/e31e492faf3d
changeset: 15330:e31e492faf3d
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Sun Jan 20 13:04:06 2013 +0100
description:
ChangeLog

diffstat:

 ChangeLog         |    2 +
 tests/mpn/t-div.c |  115 +++++++++++++++++++----------------------------------
 2 files changed, 44 insertions(+), 73 deletions(-)

diffs (truncated from 310 to 300 lines):

diff -r 79a14284250c -r e31e492faf3d ChangeLog
--- a/ChangeLog	Sun Jan 20 12:27:36 2013 +0100
+++ b/ChangeLog	Sun Jan 20 13:04:06 2013 +0100
@@ -1,6 +1,8 @@
 2013-01-20  Torbjorn Granlund  <tege at gmplib.org>
 
 	* tests/mpn/t-div.c: Test mpn_sb_div_qr_sec and mpn_sb_div_r_sec.
+	(main): Separate divisor into normalised (dnp) and unnormalised (dup),
+	pass appropriate variant to each function.
 
 	* tests/mpz/t-remove.c: Back out last change which left `divisor_size'
 	uninitialised; achieve change's aim with a parameter tweak.
diff -r 79a14284250c -r e31e492faf3d tests/mpn/t-div.c
--- a/tests/mpn/t-div.c	Sun Jan 20 12:27:36 2013 +0100
+++ b/tests/mpn/t-div.c	Sun Jan 20 13:04:06 2013 +0100
@@ -144,7 +144,7 @@
   unsigned long maxnbits, maxdbits, nbits, dbits;
   mpz_t n, d, q, r, tz;
   mp_size_t maxnn, maxdn, nn, dn, clearn, i;
-  mp_ptr np, dp, qp, rp;
+  mp_ptr np, dup, dnp, qp, rp;
   mp_limb_t t;
   gmp_pi1_t dinv;
   int count = COUNT;
@@ -152,6 +152,7 @@
   mp_limb_t ran;
   mp_size_t alloc, itch;
   mp_limb_t rran0, rran1, qran0, qran1;
+  mp_limb_t dh;
   TMP_DECL;
 
   if (argc > 1)
@@ -165,7 +166,6 @@
 	}
     }
 
-
   maxdbits = MAX_DN;
   maxnbits = MAX_NN;
 
@@ -185,6 +185,7 @@
 
   qp = TMP_ALLOC_LIMBS (maxnn + 2) + 1;
   rp = TMP_ALLOC_LIMBS (maxnn + 2) + 1;
+  dnp = TMP_ALLOC_LIMBS (maxdn + 2) + 1;
 
   alloc = 1;
   scratch = __GMP_ALLOCATE_FUNC_LIMBS (alloc);
@@ -211,8 +212,9 @@
 	RANDFUNC (d, rands, dbits);
       while (mpz_sgn (d) == 0);
       dn = SIZ (d);
-      dp = PTR (d);
-      dp[dn - 1] |= GMP_NUMB_HIGHBIT;
+      dup = PTR (d);
+      MPN_COPY (dnp, dup, dn);
+     dnp[dn - 1] |= GMP_NUMB_HIGHBIT;
 
       if (test % 2 == 0)
 	{
@@ -242,7 +244,10 @@
       t = mpz_get_ui (tz);
 
       if (t % 17 == 0)
-	dp[dn - 1] = GMP_NUMB_MAX;
+	{
+	  dnp[dn - 1] = GMP_NUMB_MAX;
+	  dup[dn - 1] = GMP_NUMB_MAX;
+	}
 
       switch ((int) t % 16)
 	{
@@ -252,16 +257,16 @@
 	    np[i] = 0;
 	  break;
 	case 1:
-	  mpn_sub_1 (np + nn - dn, dp, dn, random_word (rands));
+	  mpn_sub_1 (np + nn - dn, dnp, dn, random_word (rands));
 	  break;
 	case 2:
-	  mpn_add_1 (np + nn - dn, dp, dn, random_word (rands));
+	  mpn_add_1 (np + nn - dn, dnp, dn, random_word (rands));
 	  break;
 	}
 
       test++;
 
-      invert_pi1 (dinv, dp[dn - 1], dp[dn - 2]);
+      invert_pi1 (dinv, dnp[dn - 1], dnp[dn - 2]);
 
       rran0 = random_word (rands);
       rran1 = random_word (rands);
@@ -282,8 +287,8 @@
 	      MPN_COPY (rp, np, nn);
 	      if (nn > dn)
 		MPN_ZERO (qp, nn - dn);
-	      qp[nn - dn] = mpn_sbpi1_div_qr (qp, rp, nn, dp, dn, dinv.inv32);
-	      check_one (qp, rp, np, nn, dp, dn, "mpn_sbpi1_div_qr", 0);
+	      qp[nn - dn] = mpn_sbpi1_div_qr (qp, rp, nn, dnp, dn, dinv.inv32);
+	      check_one (qp, rp, np, nn, dnp, dn, "mpn_sbpi1_div_qr", 0);
 	    }
 
 	  /* Test mpn_sbpi1_divappr_q */
@@ -292,8 +297,8 @@
 	      MPN_COPY (rp, np, nn);
 	      if (nn > dn)
 		MPN_ZERO (qp, nn - dn);
-	      qp[nn - dn] = mpn_sbpi1_divappr_q (qp, rp, nn, dp, dn, dinv.inv32);
-	      check_one (qp, NULL, np, nn, dp, dn, "mpn_sbpi1_divappr_q", 1);
+	      qp[nn - dn] = mpn_sbpi1_divappr_q (qp, rp, nn, dnp, dn, dinv.inv32);
+	      check_one (qp, NULL, np, nn, dnp, dn, "mpn_sbpi1_divappr_q", 1);
 	    }
 
 	  /* Test mpn_sbpi1_div_q */
@@ -302,8 +307,8 @@
 	      MPN_COPY (rp, np, nn);
 	      if (nn > dn)
 		MPN_ZERO (qp, nn - dn);
-	      qp[nn - dn] = mpn_sbpi1_div_q (qp, rp, nn, dp, dn, dinv.inv32);
-	      check_one (qp, NULL, np, nn, dp, dn, "mpn_sbpi1_div_q", 0);
+	      qp[nn - dn] = mpn_sbpi1_div_q (qp, rp, nn, dnp, dn, dinv.inv32);
+	      check_one (qp, NULL, np, nn, dnp, dn, "mpn_sbpi1_div_q", 0);
 	    }
 
 	  /* Test mpn_sb_div_qr_sec */
@@ -317,9 +322,9 @@
 	  MPN_COPY (rp, np, nn);
 	  if (nn >= dn)
 	    MPN_ZERO (qp, nn - dn + 1);
-	  mpn_sb_div_qr_sec (qp, rp, nn, dp, dn, scratch);
+	  mpn_sb_div_qr_sec (qp, rp, nn, dup, dn, scratch);
 	  ASSERT_ALWAYS (ran == scratch[itch]);
-	  check_one (qp, rp, np, nn, dp, dn, "mpn_sb_div_qr_sec", 0);
+	  check_one (qp, rp, np, nn, dup, dn, "mpn_sb_div_qr_sec", 0);
 
 	  /* Test mpn_sb_div_r_sec */
 	  itch = nn + 2 * dn + 2;
@@ -330,11 +335,11 @@
 	    }
 	  scratch[itch] = ran;
 	  MPN_COPY (rp, np, nn);
-	  mpn_sb_div_r_sec (rp, nn, dp, dn, scratch);
+	  mpn_sb_div_r_sec (rp, nn, dup, dn, scratch);
 	  ASSERT_ALWAYS (ran == scratch[itch]);
 	  /* Note: Since check_one cannot cope with random-only functions, we
 	     pass qp[] from the previous function, mpn_sb_div_qr_sec.  */
-	  check_one (qp, rp, np, nn, dp, dn, "mpn_sb_div_r_sec", 0);
+	  check_one (qp, rp, np, nn, dup, dn, "mpn_sb_div_r_sec", 0);
 	}
 
       /* Test mpn_dcpi1_div_qr */
@@ -343,10 +348,10 @@
 	  MPN_COPY (rp, np, nn);
 	  if (nn > dn)
 	    MPN_ZERO (qp, nn - dn);
-	  qp[nn - dn] = mpn_dcpi1_div_qr (qp, rp, nn, dp, dn, &dinv);
+	  qp[nn - dn] = mpn_dcpi1_div_qr (qp, rp, nn, dnp, dn, &dinv);
 	  ASSERT_ALWAYS (qp[-1] == qran0);  ASSERT_ALWAYS (qp[nn - dn + 1] == qran1);
 	  ASSERT_ALWAYS (rp[-1] == rran0);
-	  check_one (qp, rp, np, nn, dp, dn, "mpn_dcpi1_div_qr", 0);
+	  check_one (qp, rp, np, nn, dnp, dn, "mpn_dcpi1_div_qr", 0);
 	}
 
       /* Test mpn_dcpi1_divappr_q */
@@ -355,10 +360,10 @@
 	  MPN_COPY (rp, np, nn);
 	  if (nn > dn)
 	    MPN_ZERO (qp, nn - dn);
-	  qp[nn - dn] = mpn_dcpi1_divappr_q (qp, rp, nn, dp, dn, &dinv);
+	  qp[nn - dn] = mpn_dcpi1_divappr_q (qp, rp, nn, dnp, dn, &dinv);
 	  ASSERT_ALWAYS (qp[-1] == qran0);  ASSERT_ALWAYS (qp[nn - dn + 1] == qran1);
 	  ASSERT_ALWAYS (rp[-1] == rran0);
-	  check_one (qp, NULL, np, nn, dp, dn, "mpn_dcpi1_divappr_q", 1);
+	  check_one (qp, NULL, np, nn, dnp, dn, "mpn_dcpi1_divappr_q", 1);
 	}
 
       /* Test mpn_dcpi1_div_q */
@@ -367,10 +372,10 @@
 	  MPN_COPY (rp, np, nn);
 	  if (nn > dn)
 	    MPN_ZERO (qp, nn - dn);
-	  qp[nn - dn] = mpn_dcpi1_div_q (qp, rp, nn, dp, dn, &dinv);
+	  qp[nn - dn] = mpn_dcpi1_div_q (qp, rp, nn, dnp, dn, &dinv);
 	  ASSERT_ALWAYS (qp[-1] == qran0);  ASSERT_ALWAYS (qp[nn - dn + 1] == qran1);
 	  ASSERT_ALWAYS (rp[-1] == rran0);
-	  check_one (qp, NULL, np, nn, dp, dn, "mpn_dcpi1_div_q", 0);
+	  check_one (qp, NULL, np, nn, dnp, dn, "mpn_dcpi1_div_q", 0);
 	}
 
      /* Test mpn_mu_div_qr */
@@ -386,11 +391,11 @@
 	  MPN_ZERO (qp, nn - dn);
 	  MPN_ZERO (rp, dn);
 	  rp[dn] = rran1;
-	  qp[nn - dn] = mpn_mu_div_qr (qp, rp, np, nn, dp, dn, scratch);
+	  qp[nn - dn] = mpn_mu_div_qr (qp, rp, np, nn, dnp, dn, scratch);
 	  ASSERT_ALWAYS (ran == scratch[itch]);
 	  ASSERT_ALWAYS (qp[-1] == qran0);  ASSERT_ALWAYS (qp[nn - dn + 1] == qran1);
 	  ASSERT_ALWAYS (rp[-1] == rran0);  ASSERT_ALWAYS (rp[dn] == rran1);
-	  check_one (qp, rp, np, nn, dp, dn, "mpn_mu_div_qr", 0);
+	  check_one (qp, rp, np, nn, dnp, dn, "mpn_mu_div_qr", 0);
 	}
 
       /* Test mpn_mu_divappr_q */
@@ -404,10 +409,10 @@
 	    }
 	  scratch[itch] = ran;
 	  MPN_ZERO (qp, nn - dn);
-	  qp[nn - dn] = mpn_mu_divappr_q (qp, np, nn, dp, dn, scratch);
+	  qp[nn - dn] = mpn_mu_divappr_q (qp, np, nn, dnp, dn, scratch);
 	  ASSERT_ALWAYS (ran == scratch[itch]);
 	  ASSERT_ALWAYS (qp[-1] == qran0);  ASSERT_ALWAYS (qp[nn - dn + 1] == qran1);
-	  check_one (qp, NULL, np, nn, dp, dn, "mpn_mu_divappr_q", 4);
+	  check_one (qp, NULL, np, nn, dnp, dn, "mpn_mu_divappr_q", 4);
 	}
 
       /* Test mpn_mu_div_q */
@@ -421,13 +426,12 @@
 	    }
 	  scratch[itch] = ran;
 	  MPN_ZERO (qp, nn - dn);
-	  qp[nn - dn] = mpn_mu_div_q (qp, np, nn, dp, dn, scratch);
+	  qp[nn - dn] = mpn_mu_div_q (qp, np, nn, dnp, dn, scratch);
 	  ASSERT_ALWAYS (ran == scratch[itch]);
 	  ASSERT_ALWAYS (qp[-1] == qran0);  ASSERT_ALWAYS (qp[nn - dn + 1] == qran1);
-	  check_one (qp, NULL, np, nn, dp, dn, "mpn_mu_div_q", 0);
+	  check_one (qp, NULL, np, nn, dnp, dn, "mpn_mu_div_q", 0);
 	}
 
-
       if (1)
 	{
 	  itch = nn + 1;
@@ -437,10 +441,10 @@
 	      alloc = itch + 1;
 	    }
 	  scratch[itch] = ran;
-	  mpn_div_q (qp, np, nn, dp, dn, scratch);
+	  mpn_div_q (qp, np, nn, dup, dn, scratch);
 	  ASSERT_ALWAYS (ran == scratch[itch]);
 	  ASSERT_ALWAYS (qp[-1] == qran0);  ASSERT_ALWAYS (qp[nn - dn + 1] == qran1);
-	  check_one (qp, NULL, np, nn, dp, dn, "mpn_div_q", 0);
+	  check_one (qp, NULL, np, nn, dup, dn, "mpn_div_q", 0);
 	}
 
       if (dn >= 2 && nn >= 2)
@@ -451,58 +455,23 @@
 	  MPN_COPY (rp, np, nn);
 	  qp[nn - 2] = qp[nn-1] = qran1;
 
-	  qh = mpn_divrem_2 (qp, 0, rp, nn, dp + dn - 2);
+	  qh = mpn_divrem_2 (qp, 0, rp, nn, dnp + dn - 2);
 	  ASSERT_ALWAYS (qp[nn - 2] == qran1);
 	  ASSERT_ALWAYS (qp[-1] == qran0);  ASSERT_ALWAYS (qp[nn - 1] == qran1);
 	  qp[nn - 2] = qh;
-
-	  check_one (qp, rp, np, nn, dp + dn - 2, 2, "mpn_divrem_2", 0);
+	  check_one (qp, rp, np, nn, dnp + dn - 2, 2, "mpn_divrem_2", 0);
 
 	  /* Missing: divrem_2 with fraction limbs. */
 
-	  /* mpn_div_qr_2 (normalized) */
+	  /* mpn_div_qr_2 */
 	  qp[nn - 2] = qran1;
 
-	  qh = mpn_div_qr_2 (qp, rp, np, nn, dp + dn - 2);
+	  qh = mpn_div_qr_2 (qp, rp, np, nn, dup + dn - 2);
 	  ASSERT_ALWAYS (qp[nn - 2] == qran1);
 	  ASSERT_ALWAYS (qp[-1] == qran0);  ASSERT_ALWAYS (qp[nn - 1] == qran1);
 	  qp[nn - 2] = qh;
-
-	  check_one (qp, rp, np, nn, dp + dn - 2, 2, "mpn_div_qr_2 (normalized)", 0);
-
-	  /* mpn_div_qr_2 (unnormalized) */
-	  dp[dn - 1] &= ~GMP_NUMB_HIGHBIT;
-	  if (dp[dn - 1] == 0)
-	    continue;
-
-	  qp[nn - 2] = qran1;
-
-	  qh = mpn_div_qr_2 (qp, rp, np, nn, dp + dn - 2);
-	  ASSERT_ALWAYS (qp[nn - 2] == qran1);
-	  ASSERT_ALWAYS (qp[-1] == qran0);  ASSERT_ALWAYS (qp[nn - 1] == qran1);
-	  qp[nn - 2] = qh;
-
-	  check_one (qp, rp, np, nn, dp + dn - 2, 2, "mpn_div_qr_2 (unnormalized)", 0);
-
-	  qp[nn - dn + 1] = qran1;
+	  check_one (qp, rp, np, nn, dup + dn - 2, 2, "mpn_div_qr_2", 0);
 	}
-
-      /* Finally, test mpn_div_q without msb set.  */
-      dp[dn - 1] &= ~GMP_NUMB_HIGHBIT;
-      if (dp[dn - 1] == 0)
-	continue;
-
-      itch = nn + 1;
-      if (itch + 1> alloc)
-	{
-	  scratch = __GMP_REALLOCATE_FUNC_LIMBS (scratch, alloc, itch + 1);


More information about the gmp-commit mailing list