[Gmp-commit] /home/hgfiles/gmp: Handle carry-out from a carry propagation sub...

mercurial at gmplib.org mercurial at gmplib.org
Thu Jan 7 04:22:28 CET 2010


details:   /home/hgfiles/gmp/rev/3a31c92c72e4
changeset: 13344:3a31c92c72e4
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Thu Jan 07 04:22:25 2010 +0100
description:
Handle carry-out from a carry propagation subtract.  Fix decls.

diffstat:

 ChangeLog                  |  20 +++++++++++++-------
 gmp-impl.h                 |   4 ++--
 mpn/generic/mu_div_qr.c    |  11 ++++++-----
 mpn/generic/mu_divappr_q.c |  13 +++++++------
 4 files changed, 28 insertions(+), 20 deletions(-)

diffs (149 lines):

diff -r 6d3e18062456 -r 3a31c92c72e4 ChangeLog
--- a/ChangeLog	Thu Jan 07 00:51:21 2010 +0100
+++ b/ChangeLog	Thu Jan 07 04:22:25 2010 +0100
@@ -2,6 +2,14 @@
 
 	* Version 5.0.0 released.
 
+	* mpn/generic/mu_div_qr.c: Handle carry-out from a carry propagation
+	subtract.
+	* mpn/generic/mu_divappr_q.c: Likewise.
+
+	* mpn/generic/mu_divappr_q.c
+	(mpn_preinv_mu_divappr_q, mpn_mu_divappr_q): Declare dividend constant.
+	* gmp-impl.h: Likewise.
+
 	* perfpow.c (mpn_perfect_power_p): Call mpn_divexact instead of mpn_bdiv_q (with
 	too little scratch space!).
 
@@ -19,6 +27,10 @@
 	* tests/mpn/t-div.c (check_one): Checking based on multiplication,
 	refmpn_mul, rather than refmpn_tdiv_qr.
 
+2010-01-06 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mpn/generic/toom8h_mul.c: Avoid overflows of mp_size_t.
+
 2010-01-06  Torbjorn Granlund  <tege at gmplib.org>
 
 	* gmp-h.in (__GNU_MP__): Bump.
@@ -37,19 +49,13 @@
 	* mpn/generic/rootrem.c: Use mpn_div_q.
 	* mpz/tdiv_q.c: Likewise.
 
-2010-01-06 Marco Bodrato <bodrato at mail.dm.unipi.it>
-
-	* mpn/generic/toom8h_mul.c: Avoid overflows of mp_size_t.
-
-2010-01-06  Torbjorn Granlund  <tege at gmplib.org>
-
 	* tests/mpn/t-div.c: Test mpn_div_q.
 	(SIZE_LOG): Up to 17.
 
 	* mpn/generic/div_q.c: New file.
 	* configure.in (gmp_mpn_functions): Add div_q.
 
-	* mpn/generic/mu_div_q.c: Actually make dividend constant.
+	* mpn/generic/mu_div_q.c: Actually declare dividend constant.
 
 2010-01-04  Torbjorn Granlund  <tege at gmplib.org>
 
diff -r 6d3e18062456 -r 3a31c92c72e4 gmp-impl.h
--- a/gmp-impl.h	Thu Jan 07 00:51:21 2010 +0100
+++ b/gmp-impl.h	Thu Jan 07 04:22:25 2010 +0100
@@ -1189,14 +1189,14 @@
 __GMP_DECLSPEC mp_limb_t mpn_preinv_mu_div_qr __GMP_PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t, mp_ptr));
 
 #define   mpn_mu_divappr_q __MPN(mu_divappr_q)
-__GMP_DECLSPEC mp_limb_t mpn_mu_divappr_q __GMP_PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_ptr));
+__GMP_DECLSPEC mp_limb_t mpn_mu_divappr_q __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t, mp_ptr));
 #define   mpn_mu_divappr_q_itch __MPN(mu_divappr_q_itch)
 __GMP_DECLSPEC mp_size_t mpn_mu_divappr_q_itch __GMP_PROTO ((mp_size_t, mp_size_t, int));
 #define   mpn_mu_divappr_q_choose_in __MPN(mu_divappr_q_choose_in)
 __GMP_DECLSPEC mp_size_t mpn_mu_divappr_q_choose_in __GMP_PROTO ((mp_size_t, mp_size_t, int));
 
 #define   mpn_preinv_mu_divappr_q __MPN(preinv_mu_divappr_q)
-__GMP_DECLSPEC mp_limb_t mpn_preinv_mu_divappr_q __GMP_PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t, mp_ptr));
+__GMP_DECLSPEC mp_limb_t mpn_preinv_mu_divappr_q __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t, mp_ptr));
 
 #define   mpn_mu_div_q __MPN(mu_div_q)
 __GMP_DECLSPEC mp_limb_t mpn_mu_div_q __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t, mp_ptr));
diff -r 6d3e18062456 -r 3a31c92c72e4 mpn/generic/mu_div_qr.c
--- a/mpn/generic/mu_div_qr.c	Thu Jan 07 00:51:21 2010 +0100
+++ b/mpn/generic/mu_div_qr.c	Thu Jan 07 04:22:25 2010 +0100
@@ -245,7 +245,7 @@
 		      mp_ptr scratch)
 {
   mp_size_t qn;
-  mp_limb_t cy, qh;
+  mp_limb_t cy, cx, qh;
   mp_limb_t r;
   mp_size_t tn, wn;
 
@@ -286,7 +286,7 @@
 
       /* Compute the product of the quotient block and the divisor D, to be
 	 subtracted from the partial remainder combined with new limbs from the
-	 dividend N.  We only really need the low dn limbs.  */
+	 dividend N.  We only really need the low dn+1 limbs.  */
 
       if (BELOW_THRESHOLD (in, MUL_TO_MULMOD_BNM1_FOR_2NXN_THRESHOLD))
 	mpn_mul (tp, dp, dn, qp, in);		/* dn+in limbs, high 'in' cancels */
@@ -298,9 +298,10 @@
 	  if (wn > 0)
 	    {
 	      cy = mpn_sub_n (tp, tp, rp + dn - wn, wn);
-	      mpn_decr_u (tp + wn, cy);
-	      cy = mpn_cmp (rp + dn - in, tp + dn, tn - dn) < 0;
-	      mpn_incr_u (tp, cy);
+	      cy = mpn_sub_1 (tp + wn, tp + wn, tn - wn, cy);
+	      cx = mpn_cmp (rp + dn - in, tp + dn, tn - dn) < 0;
+	      ASSERT_ALWAYS (cx >= cy);
+	      mpn_incr_u (tp, cx - cy);
 	    }
 	}
 
diff -r 6d3e18062456 -r 3a31c92c72e4 mpn/generic/mu_divappr_q.c
--- a/mpn/generic/mu_divappr_q.c	Thu Jan 07 00:51:21 2010 +0100
+++ b/mpn/generic/mu_divappr_q.c	Thu Jan 07 04:22:25 2010 +0100
@@ -81,7 +81,7 @@
 
 mp_limb_t
 mpn_mu_divappr_q (mp_ptr qp,
-		  mp_ptr np,
+		  mp_srcptr np,
 		  mp_size_t nn,
 		  mp_srcptr dp,
 		  mp_size_t dn,
@@ -165,7 +165,7 @@
 
 mp_limb_t
 mpn_preinv_mu_divappr_q (mp_ptr qp,
-			 mp_ptr np,
+			 mp_srcptr np,
 			 mp_size_t nn,
 			 mp_srcptr dp,
 			 mp_size_t dn,
@@ -174,7 +174,7 @@
 			 mp_ptr scratch)
 {
   mp_size_t qn;
-  mp_limb_t cy, qh;
+  mp_limb_t cy, cx, qh;
   mp_limb_t r;
   mp_size_t tn, wn;
 
@@ -230,9 +230,10 @@
 	  if (wn > 0)
 	    {
 	      cy = mpn_sub_n (tp, tp, rp + dn - wn, wn);
-	      mpn_decr_u (tp + wn, cy);
-	      cy = mpn_cmp (rp + dn - in, tp + dn, tn - dn) < 0;
-	      mpn_incr_u (tp, cy);
+	      cy = mpn_sub_1 (tp + wn, tp + wn, tn - wn, cy);
+	      cx = mpn_cmp (rp + dn - in, tp + dn, tn - dn) < 0;
+	      ASSERT_ALWAYS (cx >= cy);
+	      mpn_incr_u (tp, cx - cy);
 	    }
 	}
 


More information about the gmp-commit mailing list