3 * $Id: mpscan.h,v 1.2 1999/11/13 01:55:10 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 /*----- Revision history --------------------------------------------------*
33 * Revision 1.2 1999/11/13 01:55:10 mdw
34 * Fixed so that they compile. Minor interface changes.
36 * Revision 1.1 1999/09/03 08:41:12 mdw
48 /*----- Header files ------------------------------------------------------*/
54 /*----- Data structures ---------------------------------------------------*/
56 typedef struct mpscan
{
57 const mpw
*v
, *vl
; /* Vector of words to scan */
58 mpw w
; /* Current word to scan */
59 int bits
; /* Number of bits left in @w@ */
62 /*----- Functions provided ------------------------------------------------*/
64 /* --- @mpscan_initx@ --- *
66 * Arguments: @mpscan *m@ = pointer to bitscanner structure
67 * @const mpw *v, *vl@ = vector of words to scan
71 * Use: Initializes a bitscanner from a low-level base-and-limit
72 * representation of an integer. Initially no bit is ready; you
73 * must call @mpscan_step@ before anything useful will come
77 #define MPSCAN_INITX(m_, v_, vl_) do { \
84 extern void mpscan_initx(mpscan */
*m*/
, const mpw */
*v*/
, const mpw */
*vl*/
);
86 /* --- @mpscan_step@ --- *
88 * Arguments: @mpscan *m@ = pointer to bitscanner
90 * Returns: Nonzero if there is another bit to read.
92 * Use: Steps on to the next bit in the integer. The macro version
93 * evaluates its argument multiple times.
96 #define MPSCAN_STEP(m) \
97 ((m)->bits ? ((m)->w >>= 1, \
99 (m)->v < (m)->vl ? ((m)->w = *(m)->v++, \
100 (m)->bits = MPW_BITS - 1, 1) : \
103 extern int mpscan_step(mpscan */
*m*/
);
105 /* --- @mpscan_bit@ --- *
107 * Arguments: @const mpscan *m@ = pointer to bitscanner
109 * Returns: The value of the current bit.
111 * Use: Reads the value of the current bit looked at by a
115 #define MPSCAN_BIT(m) ((m)->w & 1)
117 extern int mpscan_bit(const mpscan */
*m*/
);
119 /*----- That's all, folks -------------------------------------------------*/