New function for division by a small integer.
authormdw <mdw>
Wed, 22 Dec 1999 15:49:07 +0000 (15:49 +0000)
committermdw <mdw>
Wed, 22 Dec 1999 15:49:07 +0000 (15:49 +0000)
mpx.c
mpx.h

diff --git a/mpx.c b/mpx.c
index e63750f..36b424c 100644 (file)
--- a/mpx.c
+++ b/mpx.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
 /* -*-c-*-
  *
- * $Id: mpx.c,v 1.6 1999/11/20 22:43:44 mdw Exp $
+ * $Id: mpx.c,v 1.7 1999/12/22 15:49:07 mdw Exp $
  *
  * Low-level multiprecision arithmetic
  *
  *
  * Low-level multiprecision arithmetic
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: mpx.c,v $
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: mpx.c,v $
+ * Revision 1.7  1999/12/22 15:49:07  mdw
+ * New function for division by a small integer.
+ *
  * Revision 1.6  1999/11/20 22:43:44  mdw
  * Integrate testing for MPX routines.
  *
  * Revision 1.6  1999/11/20 22:43:44  mdw
  * Integrate testing for MPX routines.
  *
@@ -900,6 +903,35 @@ void mpx_udiv(mpw *qv, mpw *qvl, mpw *rv, mpw *rvl,
   mpx_lsr(rv, rvl, rv, rvl, norm);
 }
 
   mpx_lsr(rv, rvl, rv, rvl, norm);
 }
 
+/* --- @mpx_udivn@ --- *
+ *
+ * Arguments:  @mpw *qv, *qvl@ = storage for the quotient (may overlap
+ *                     dividend)
+ *             @const mpw *rv, *rvl@ = dividend
+ *             @mpw d@ = single-precision divisor
+ *
+ * Returns:    Remainder after divison.
+ *
+ * Use:                Performs a single-precision division operation.
+ */
+
+mpw mpx_udivn(mpw *qv, mpw *qvl, const mpw *rv, const mpw *rvl, mpw d)
+{
+  size_t i;
+  size_t ql = qvl - qv;
+  mpd r = 0;
+
+  i = rvl - rv;
+  while (i > 0) {
+    i--;
+    r = (r << MPW_BITS) | rv[i];
+    if (i < ql)
+      qv[i] = r / d;
+    r %= d;
+  }
+  return (MPW(r));
+}
+
 /*----- Test rig ----------------------------------------------------------*/
 
 #ifdef TEST_RIG
 /*----- Test rig ----------------------------------------------------------*/
 
 #ifdef TEST_RIG
diff --git a/mpx.h b/mpx.h
index 509da02..076f14a 100644 (file)
--- a/mpx.h
+++ b/mpx.h
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
 /* -*-c-*-
  *
- * $Id: mpx.h,v 1.8 1999/12/11 10:57:43 mdw Exp $
+ * $Id: mpx.h,v 1.9 1999/12/22 15:49:07 mdw Exp $
  *
  * Low level multiprecision arithmetic
  *
  *
  * Low level multiprecision arithmetic
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: mpx.h,v $
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: mpx.h,v $
+ * Revision 1.9  1999/12/22 15:49:07  mdw
+ * New function for division by a small integer.
+ *
  * Revision 1.8  1999/12/11 10:57:43  mdw
  * Karatsuba squaring algorithm.
  *
  * Revision 1.8  1999/12/11 10:57:43  mdw
  * Karatsuba squaring algorithm.
  *
@@ -539,6 +542,21 @@ extern void mpx_udiv(mpw */*qv*/, mpw */*qvl*/, mpw */*rv*/, mpw */*rvl*/,
                     const mpw */*dv*/, const mpw */*dvl*/,
                     mpw */*sv*/, mpw */*svl*/);
 
                     const mpw */*dv*/, const mpw */*dvl*/,
                     mpw */*sv*/, mpw */*svl*/);
 
+/* --- @mpx_udivn@ --- *
+ *
+ * Arguments:  @mpw *qv, *qvl@ = storage for the quotient (may overlap
+ *                     dividend)
+ *             @const mpw *rv, *rvl@ = dividend
+ *             @mpw d@ = single-precision divisor
+ *
+ * Returns:    Remainder after divison.
+ *
+ * Use:                Performs a single-precision division operation.
+ */
+
+extern mpw mpx_udivn(mpw */*qv*/, mpw */*qvl*/,
+                    const mpw */*rv*/, const mpw */*rvl*/, mpw /*d*/);
+
 /*----- Karatsuba multiplication algorithms -------------------------------*/
 
 /* --- @KARATSUBA_CUTOFF@ --- *
 /*----- Karatsuba multiplication algorithms -------------------------------*/
 
 /* --- @KARATSUBA_CUTOFF@ --- *
@@ -557,7 +575,7 @@ extern void mpx_udiv(mpw */*qv*/, mpw */*qvl*/, mpw */*rv*/, mpw */*rvl*/,
  * required is proportional to the recursion depth.
  */
 
  * required is proportional to the recursion depth.
  */
 
-#define KARATSUBA_SLOP 32
+#define KARATSUBA_SLOP 64
 
 /* --- @mpx_kmul@ --- *
  *
 
 /* --- @mpx_kmul@ --- *
  *