/* -*-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
*
/*----- 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.
*
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
/* -*-c-*-
*
- * $Id: mp.h,v 1.10 2000/10/08 12:03:16 mdw Exp $
+ * $Id: mp.h,v 1.11 2001/04/03 19:36:05 mdw Exp $
*
* Simple multiprecision arithmetic
*
/*----- Revision history --------------------------------------------------*
*
* $Log: mp.h,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:03:16 mdw
* Provide @mp_eq@ and @MP_EQ@ for rapidly testing equality of two
* integers.
#define MP_CMP(a, op, b) (mp_cmp((a), (b)) op 0)
+/* --- @mpx_and@, @mpx_or@, @mpx_xor@, @mpx_not@ --- *
+ *
+ * Arguments: @mp *d@ = destination
+ * @mp *a, *b@ = sources
+ *
+ * Returns: The result of the obvious bitwise operation.
+ */
+
+extern mp *mp_and(mp */*d*/, mp */*a*/, mp */*b*/);
+extern mp *mp_or(mp */*d*/, mp */*a*/, mp */*b*/);
+extern mp *mp_xor(mp */*d*/, mp */*a*/, mp */*b*/);
+extern mp *mp_not(mp */*d*/, mp */*a*/);
+
/* --- @mp_add@ --- *
*
* Arguments: @mp *d@ = destination
/* -*-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
*
/*----- 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.
*
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@ --- *
/* -*-c-*-
*
- * $Id: mpx.h,v 1.11 2000/10/08 15:48:35 mdw Exp $
+ * $Id: mpx.h,v 1.12 2001/04/03 19:36:05 mdw Exp $
*
* Low level multiprecision arithmetic
*
/*----- Revision history --------------------------------------------------*
*
* $Log: mpx.h,v $
+ * Revision 1.12 2001/04/03 19:36:05 mdw
+ * Add some simple bitwise operations so that Perl can use them.
+ *
* Revision 1.11 2000/10/08 15:48:35 mdw
* Rename Karatsuba constants now that we have @gfx_kmul@ too.
*
const mpw */*av*/, const mpw */*avl*/,
size_t /*n*/);
+/*----- 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.
+ */
+
+extern void mpx_and(mpw */*dv*/, mpw */*dvl*/,
+ const mpw */*av*/, const mpw */*avl*/,
+ const mpw */*bv*/, const mpw */*bvl*/);
+
+extern void mpx_or(mpw */*dv*/, mpw */*dvl*/,
+ const mpw */*av*/, const mpw */*avl*/,
+ const mpw */*bv*/, const mpw */*bvl*/);
+
+extern void mpx_xor(mpw */*dv*/, mpw */*dvl*/,
+ const mpw */*av*/, const mpw */*avl*/,
+ const mpw */*bv*/, const mpw */*bvl*/);
+
+extern void mpx_not(mpw */*dv*/, mpw */*dvl*/,
+ const mpw */*av*/, const mpw */*avl*/);
+
/*----- Unsigned arithmetic -----------------------------------------------*/
/* --- @mpx_2c@ --- *