3 * $Id: mpscan.c,v 1.4 2004/04/08 01:36:15 mdw Exp $
5 * Sequential bit scan of multiprecision integers
7 * (c) 1999 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Header files ------------------------------------------------------*/
34 /*----- Right-to-left scanning --------------------------------------------*/
36 /* --- @mpscan_initx@ --- *
38 * Arguments: @mpscan *m@ = pointer to bitscanner structure
39 * @const mpw *v, *vl@ = vector of words to scan
43 * Use: Initializes a bitscanner from a low-level vector-and-length
44 * representation of an integer. Initially no bit is ready; you
45 * must call @mpscan_step@ before anything useful will come
49 void mpscan_initx(mpscan *m, const mpw *v, const mpw *vl)
51 MPSCAN_INITX(m, v, vl);
54 /* --- @mpscan_step@ --- *
56 * Arguments: @mpscan *m@ = pointer to bitscanner
58 * Returns: Nonzero if there is another bit to read.
60 * Use: Steps on to the next bit in the integer. The macro version
61 * evaluates its argument multiple times.
64 int mpscan_step(mpscan *m) { return (MPSCAN_STEP(m)); }
66 /* --- @mpscan_bit@ --- *
68 * Arguments: @const mpscan *m@ = pointer to bitscanner
70 * Returns: The value of the current bit.
72 * Use: Reads the value of the current bit looked at by a
76 int mpscan_bit(const mpscan *m) { return (MPSCAN_BIT(m)); }
78 /*----- Left-to right-scanning --------------------------------------------*/
80 /* --- @mpscan_rinitx@ --- *
82 * Arguments: @mpscan *m@ = pointer to bitscanner structure
83 * @const mpw *v, *vl@ = vector of words to scan
87 * Use: Initializes a reverse bitscanner from a low-level
88 * vector-and-length representation of an integer. Initially no
89 * bit is ready; you must call @mpscan_rstep@ before anything
90 * useful will come out.
93 void mpscan_rinitx(mpscan *m, const mpw *v, const mpw *vl)
95 MPSCAN_RINITX(m, v, vl);
98 /* --- @mpscan_rstep@ --- *
100 * Arguments: @mpscan *m@ = pointer to bitscanner
102 * Returns: Nonzero if there is another bit to read.
104 * Use: Steps on to the next bit in the integer. The macro version
105 * evaluates its argument multiple times.
108 int mpscan_rstep(mpscan *m) { return (MPSCAN_RSTEP(m)); }
110 /* --- @mpscan_rbit@ --- *
112 * Arguments: @const mpscan *m@ = pointer to bitscanner
114 * Returns: The value of the current bit.
116 * Use: Reads the value of the current bit looked at by a
117 * reverse bitscanner.
120 int mpscan_rbit(const mpscan *m) { return (MPSCAN_RBIT(m)); }
122 /*----- That's all, folks -------------------------------------------------*/