X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/d03ab969116fe715d569304c1c474749b2f64529..59919ae4b1721ca271c3d3e5955c09d322573821:/mpscan.c diff --git a/mpscan.c b/mpscan.c index a49eddf..0a5b4f0 100644 --- a/mpscan.c +++ b/mpscan.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: mpscan.c,v 1.1 1999/09/03 08:41:12 mdw Exp $ + * $Id: mpscan.c,v 1.3 2000/07/29 17:03:31 mdw Exp $ * * Sequential bit scan of multiprecision integers * @@ -30,6 +30,13 @@ /*----- Revision history --------------------------------------------------* * * $Log: mpscan.c,v $ + * Revision 1.3 2000/07/29 17:03:31 mdw + * Add support for left-to-right bitscanning, for use in modular + * exponentiation. + * + * Revision 1.2 1999/11/13 01:55:10 mdw + * Fixed so that they compile. Minor interface changes. + * * Revision 1.1 1999/09/03 08:41:12 mdw * Initial import. * @@ -37,17 +44,14 @@ /*----- Header files ------------------------------------------------------*/ -/*----- Data structures ---------------------------------------------------*/ - -/*----- Static variables --------------------------------------------------*/ +#include "mpscan.h" -/*----- Main code ---------------------------------------------------------*/ +/*----- Right-to-left scanning --------------------------------------------*/ /* --- @mpscan_initx@ --- * * * Arguments: @mpscan *m@ = pointer to bitscanner structure - * @const mpw *v@ = vector of words to scan - * @size_t len@ = length of vector in words + * @const mpw *v, *vl@ = vector of words to scan * * Returns: --- * @@ -57,9 +61,9 @@ * out. */ -void mpscan_initx(mpscan *m, const mpw *v, size_t len) +void mpscan_initx(mpscan *m, const mpw *v, const mpw *vl) { - MPSCAN_INITX(m, v, len); + MPSCAN_INITX(m, v, vl); } /* --- @mpscan_step@ --- * @@ -86,4 +90,48 @@ int mpscan_step(mpscan *m) { return (MPSCAN_STEP(m)); } int mpscan_bit(const mpscan *m) { return (MPSCAN_BIT(m)); } +/*----- Left-to right-scanning --------------------------------------------*/ + +/* --- @mpscan_rinitx@ --- * + * + * Arguments: @mpscan *m@ = pointer to bitscanner structure + * @const mpw *v, *vl@ = vector of words to scan + * + * Returns: --- + * + * Use: Initializes a reverse bitscanner from a low-level + * vector-and-length representation of an integer. Initially no + * bit is ready; you must call @mpscan_rstep@ before anything + * useful will come out. + */ + +void mpscan_rinitx(mpscan *m, const mpw *v, const mpw *vl) +{ + MPSCAN_RINITX(m, v, vl); +} + +/* --- @mpscan_rstep@ --- * + * + * Arguments: @mpscan *m@ = pointer to bitscanner + * + * Returns: Nonzero if there is another bit to read. + * + * Use: Steps on to the next bit in the integer. The macro version + * evaluates its argument multiple times. + */ + +int mpscan_rstep(mpscan *m) { return (MPSCAN_RSTEP(m)); } + +/* --- @mpscan_rbit@ --- * + * + * Arguments: @const mpscan *m@ = pointer to bitscanner + * + * Returns: The value of the current bit. + * + * Use: Reads the value of the current bit looked at by a + * reverse bitscanner. + */ + +int mpscan_rbit(const mpscan *m) { return (MPSCAN_RBIT(m)); } + /*----- That's all, folks -------------------------------------------------*/