Indentation fix.
[u/mdw/catacomb] / mp-arith.c
index 82fda15..d6d892b 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: mp-arith.c,v 1.9 2000/10/08 15:48:35 mdw Exp $
+ * $Id: mp-arith.c,v 1.10 2001/04/03 19:36:05 mdw Exp $
  *
  * Basic arithmetic on multiprecision integers
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: mp-arith.c,v $
+ * Revision 1.10  2001/04/03 19:36:05  mdw
+ * Add some simple bitwise operations so that Perl can use them.
+ *
  * Revision 1.9  2000/10/08 15:48:35  mdw
  * Rename Karatsuba constants now that we have @gfx_kmul@ too.
  *
@@ -176,6 +179,38 @@ int mp_cmp(const mp *a, const mp *b)
     return (+1);
 }
 
+/* --- @mpx_and@, @mpx_or@, @mpx_xor@, @mpx_not@ --- *
+ *
+ * Arguments:  @mp *d@ = destination
+ *             @mp *a, *b@ = sources
+ *
+ * Returns:    The result of the obvious bitwise operation.
+ */
+
+#define MP_BITBINOP(name)                                              \
+                                                                       \
+mp *mp_##name(mp *d, mp *a, mp *b)                                     \
+{                                                                      \
+  MP_DEST(d, MAX(MP_LEN(a), MP_LEN(b)), a->f | b->f);                  \
+  mpx_##name(d->v, d->vl, a->v, a->vl, b->v, b->vl);                   \
+  d->f = (a->f | b->f) & MP_BURN;                                      \
+  MP_SHRINK(d);                                                                \
+  return (d);                                                          \
+}
+
+MP_BITBINOP(and)
+MP_BITBINOP(or)
+MP_BITBINOP(xor)
+
+mp *mp_not(mp *d, mp *a)
+{
+  MP_DEST(d, MP_LEN(a), a->f);
+  mpx_not(d->v, d->vl, a->v, a->vl);
+  d->f = a->f & MP_BURN;
+  MP_SHRINK(d);
+  return (d);
+}
+
 /* --- @mp_add@ --- *
  *
  * Arguments:  @mp *d@ = destination