Add some simple bitwise operations so that Perl can use them.
[u/mdw/catacomb] / mpx.c
diff --git a/mpx.c b/mpx.c
index 13b6fa0..f89a89b 100644 (file)
--- a/mpx.c
+++ b/mpx.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: mpx.c,v 1.10 2000/10/08 12:06:12 mdw Exp $
+ * $Id: mpx.c,v 1.11 2001/04/03 19:36:05 mdw Exp $
  *
  * Low-level multiprecision arithmetic
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: mpx.c,v $
+ * Revision 1.11  2001/04/03 19:36:05  mdw
+ * Add some simple bitwise operations so that Perl can use them.
+ *
  * Revision 1.10  2000/10/08 12:06:12  mdw
  * Provide @mpx_ueq@ for rapidly testing equality of two integers.
  *
@@ -400,6 +403,50 @@ void mpx_lsr(mpw *dv, mpw *dvl, const mpw *av, const mpw *avl, size_t n)
 done:;
 }
 
+/*----- Bitwise operations ------------------------------------------------*/
+
+/* --- @mpx_and@, @mpx_or@, @mpx_xor@, @mpx_not@ --- *
+ *
+ * Arguments:  @mpw *dv, *dvl@ = destination vector
+ *             @const mpw *av, *avl@ = first source vector
+ *             @const mpw *bv, *bvl@ = second source vector
+ *
+ * Returns:    ---
+ *
+ * Use;                Does the obvious bitwise operations.
+ */
+
+#define MPX_BITBINOP(name, op)                                         \
+                                                                       \
+void mpx_##name(mpw *dv, mpw *dvl, const mpw *av, const mpw *avl,      \
+               const mpw *bv, const mpw *bvl)                          \
+{                                                                      \
+  MPX_SHRINK(av, avl);                                                 \
+  MPX_SHRINK(bv, bvl);                                                 \
+                                                                       \
+  while (dv < dvl) {                                                   \
+    mpw a, b;                                                          \
+    a = (av < avl) ? *av++ : 0;                                                \
+    b = (bv < bvl) ? *bv++ : 0;                                                \
+    *dv++ = a op b;                                                    \
+  }                                                                    \
+}
+
+MPX_BITBINOP(and, &)
+MPX_BITBINOP(or, |)
+MPX_BITBINOP(xor, ^)
+
+void mpx_not(mpw *dv, mpw *dvl, const mpw *av, const mpw *avl)
+{
+  MPX_SHRINK(av, avl);
+
+  while (dv < dvl) {
+    mpw a;
+    a = (av < avl) ? *av++ : 0;
+    *dv++ = ~a;
+  }
+}
+
 /*----- Unsigned arithmetic -----------------------------------------------*/
 
 /* --- @mpx_2c@ --- *