Fix bit operations. Test them (a bit) better.
[u/mdw/catacomb] / mpx.h
diff --git a/mpx.h b/mpx.h
index 948e7dd..3364137 100644 (file)
--- a/mpx.h
+++ b/mpx.h
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: mpx.h,v 1.13 2002/10/06 22:52:50 mdw Exp $
+ * $Id: mpx.h,v 1.15 2002/10/19 17:56:50 mdw Exp $
  *
  * Low level multiprecision arithmetic
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: mpx.h,v $
+ * Revision 1.15  2002/10/19 17:56:50  mdw
+ * Fix bit operations.  Test them (a bit) better.
+ *
+ * Revision 1.14  2002/10/09 00:36:03  mdw
+ * Fix bounds on workspace for Karatsuba operations.
+ *
  * Revision 1.13  2002/10/06 22:52:50  mdw
  * Pile of changes for supporting two's complement properly.
  *
@@ -380,29 +386,6 @@ extern void mpx_lsr(mpw */*dv*/, mpw */*dvl*/,
 
 /*----- Bitwise operations ------------------------------------------------*/
 
-/* --- How to implement them --- *
- *
- *   x:  0011
- *   y:  0101
- */
-
-#define MPX_B0000(x, y) (0u)
-#define MPX_B0001(x, y) ((x) & (y))
-#define MPX_B0010(x, y) ((x) & ~(y))
-#define MPX_B0011(x, y) (x)
-#define MPX_B0100(x, y) (~(x) & ~(y))
-#define MPX_B0101(x, y) (y)
-#define MPX_B0110(x, y) ((x) ^ (y))
-#define MPX_B0111(x, y) ((x) | (y))
-#define MPX_B1000(x, y) (~((x) | (y)))
-#define MPX_B1001(x, y) (~((x) ^ (y)))
-#define MPX_B1010(x, y) (~(y))
-#define MPX_B1011(x, y) ((x) | ~(y))
-#define MPX_B1100(x, y) (~(x))
-#define MPX_B1101(x, y) (~(x) | (y))
-#define MPX_B1110(x, y) (~((x) & (y)))
-#define MPX_B1111(x, y) (~0u)
-
 /* --- @mpx_bitop@ --- *
  *
  * Arguments:  @mpw *dv, *dvl@ = destination vector
@@ -733,20 +716,12 @@ extern mpw mpx_udivn(mpw */*qv*/, mpw */*qvl*/,
  *
  * This is the limiting length for using Karatsuba algorithms.  It's best to
  * use the simpler classical multiplication method on numbers smaller than
- * this.
+ * this.  It is unsafe to make this constant less than four (i.e., the
+ * algorithms will fail).
  */
 
 #define MPK_THRESH 16
 
-/* --- @MPK_SLOP@ --- *
- *
- * The extra number of words required as scratch space by the Karatsuba
- * routines.  This is a (generous) guess, since the actual amount of space
- * required is proportional to the recursion depth.
- */
-
-#define MPK_SLOP 64
-
 /* --- @mpx_kmul@ --- *
  *
  * Arguments:  @mpw *dv, *dvl@ = pointer to destination buffer
@@ -761,10 +736,9 @@ extern mpw mpx_udivn(mpw */*qv*/, mpw */*qvl*/,
  *             multiplication (e.g., @mpx_umul@) on large numbers, although
  *             more expensive on small ones.
  *
- *             The destination and scratch buffers must be twice as large as
- *             the larger argument.  The scratch space must be twice as
- *             large as the larger argument, plus the magic number
- *             @MPK_SLOP@.
+ *             The destination must be three times as large as the larger
+ *             argument.  The scratch space must be five times as large as
+ *             the larger argument.
  */
 
 extern void mpx_kmul(mpw */*dv*/, mpw */*dvl*/,
@@ -786,9 +760,9 @@ extern void mpx_kmul(mpw */*dv*/, mpw */*dvl*/,
  *             large numbers, although more expensive on small ones, and
  *             rather simpler than full-blown Karatsuba multiplication.
  *
- *             The destination must be twice as large as the argument.  The
- *             scratch space must be twice as large as the argument, plus
- *             the magic number @MPK_SLOP@.
+ *             The destination must be three times as large as the larger
+ *             argument.  The scratch space must be five times as large as
+ *             the larger argument.
  */
 
 extern void mpx_ksqr(mpw */*dv*/, mpw */*dvl*/,