X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/22a073c05a6237e8e4b3c4d9a761b04656209efe..2685767a6125c1620719c7de6234aedf41857b7e:/mp.h diff --git a/mp.h b/mp.h index 12003d0..dcf4349 100644 --- a/mp.h +++ b/mp.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: mp.h,v 1.8 2000/06/22 19:02:01 mdw Exp $ + * $Id: mp.h,v 1.11 2001/04/03 19:36:05 mdw Exp $ * * Simple multiprecision arithmetic * @@ -30,6 +30,17 @@ /*----- 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. + * + * Revision 1.9 2000/07/29 17:03:31 mdw + * Add support for left-to-right bitscanning, for use in modular + * exponentiation. + * * Revision 1.8 2000/06/22 19:02:01 mdw * Add new functions. * @@ -420,13 +431,36 @@ extern void mp_scan(mpscan */*sc*/, const mp */*m*/); MPSCAN_INITX(_sc, _mm->v, _mm->vl); \ } while (0) +/* --- @mp_rscan@ --- * + * + * Arguments: @mpscan *sc@ = pointer to bitscanner block + * @const mp *m@ = pointer to a multiprecision integer + * + * Returns: --- + * + * Use: Initializes a reverse bitscanner on a multiprecision + * integer. + */ + +extern void mp_rscan(mpscan */*sc*/, const mp */*m*/); + +#define MP_RSCAN(sc, m) do { \ + const mp *_mm = (m); \ + mpscan *_sc = (sc); \ + MPSCAN_RINITX(_sc, _mm->v, _mm->vl); \ +} while (0) + /* --- Other bitscanning aliases --- */ #define mp_step mpscan_step #define mp_bit mpscan_bit +#define mp_rstep mpscan_rstep +#define mp_rbit mpscan_rbit #define MP_STEP MPSCAN_STEP #define MP_BIT MPSCAN_BIT +#define MP_RSTEP MPSCAN_RSTEP +#define MP_RBIT MPSCAN_RBIT /*----- Loading and storing -----------------------------------------------*/ @@ -569,6 +603,19 @@ extern mp *mp_lsl(mp */*d*/, mp */*a*/, size_t /*n*/); extern mp *mp_lsr(mp */*d*/, mp */*a*/, size_t /*n*/); +/* --- @mp_eq@ --- * + * + * Arguments: @const mp *a, *b@ = two numbers + * + * Returns: Nonzero if the numbers are equal. + */ + +extern int mp_eq(const mp */*a*/, const mp */*b*/); + +#define MP_EQ(a, b) \ + ((((a)->f ^ (b)->f) & MP_NEG) == 0 && \ + mpx_ueq((a)->v, (a)->vl, (b)->v, (b)->vl)) + /* --- @mp_cmp@ --- * * * Arguments: @const mp *a, *b@ = two numbers @@ -581,6 +628,19 @@ extern int mp_cmp(const mp */*a*/, const mp */*b*/); #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