X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/d03ab969116fe715d569304c1c474749b2f64529..c3321b13915e3b839da060f8dc63c68e31bcc360:/mpscan.c diff --git a/mpscan.c b/mpscan.c index a49eddf..a939333 100644 --- a/mpscan.c +++ b/mpscan.c @@ -1,13 +1,13 @@ /* -*-c-*- * - * $Id: mpscan.c,v 1.1 1999/09/03 08:41:12 mdw Exp $ + * $Id: mpscan.c,v 1.4 2004/04/08 01:36:15 mdw Exp $ * * Sequential bit scan of multiprecision integers * * (c) 1999 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of Catacomb. * @@ -15,39 +15,28 @@ * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. - * + * * Catacomb is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. - * + * * You should have received a copy of the GNU Library General Public * License along with Catacomb; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: mpscan.c,v $ - * Revision 1.1 1999/09/03 08:41:12 mdw - * Initial import. - * - */ - /*----- 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 +46,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 +75,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 -------------------------------------------------*/