X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/36c67859bdb3aae4d5b837290939548bd24ad842..0f32e0f83177bd620a1deee0e0641f8323742b6c:/mpx.c diff --git a/mpx.c b/mpx.c index 13b6fa0..f89a89b 100644 --- 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@ --- *