Rearrange the file tree.
[u/mdw/catacomb] / math / mpscan.c
1 /* -*-c-*-
2 *
3 * Sequential bit scan of multiprecision integers
4 *
5 * (c) 1999 Straylight/Edgeware
6 */
7
8 /*----- Licensing notice --------------------------------------------------*
9 *
10 * This file is part of Catacomb.
11 *
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
16 *
17 * Catacomb is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
21 *
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 * MA 02111-1307, USA.
26 */
27
28 /*----- Header files ------------------------------------------------------*/
29
30 #include "mpscan.h"
31
32 /*----- Right-to-left scanning --------------------------------------------*/
33
34 /* --- @mpscan_initx@ --- *
35 *
36 * Arguments: @mpscan *m@ = pointer to bitscanner structure
37 * @const mpw *v, *vl@ = vector of words to scan
38 *
39 * Returns: ---
40 *
41 * Use: Initializes a bitscanner from a low-level vector-and-length
42 * representation of an integer. Initially no bit is ready; you
43 * must call @mpscan_step@ before anything useful will come
44 * out.
45 */
46
47 void mpscan_initx(mpscan *m, const mpw *v, const mpw *vl)
48 {
49 MPSCAN_INITX(m, v, vl);
50 }
51
52 /* --- @mpscan_step@ --- *
53 *
54 * Arguments: @mpscan *m@ = pointer to bitscanner
55 *
56 * Returns: Nonzero if there is another bit to read.
57 *
58 * Use: Steps on to the next bit in the integer. The macro version
59 * evaluates its argument multiple times.
60 */
61
62 int mpscan_step(mpscan *m) { return (MPSCAN_STEP(m)); }
63
64 /* --- @mpscan_bit@ --- *
65 *
66 * Arguments: @const mpscan *m@ = pointer to bitscanner
67 *
68 * Returns: The value of the current bit.
69 *
70 * Use: Reads the value of the current bit looked at by a
71 * bitscanner.
72 */
73
74 int mpscan_bit(const mpscan *m) { return (MPSCAN_BIT(m)); }
75
76 /*----- Left-to right-scanning --------------------------------------------*/
77
78 /* --- @mpscan_rinitx@ --- *
79 *
80 * Arguments: @mpscan *m@ = pointer to bitscanner structure
81 * @const mpw *v, *vl@ = vector of words to scan
82 *
83 * Returns: ---
84 *
85 * Use: Initializes a reverse bitscanner from a low-level
86 * vector-and-length representation of an integer. Initially no
87 * bit is ready; you must call @mpscan_rstep@ before anything
88 * useful will come out.
89 */
90
91 void mpscan_rinitx(mpscan *m, const mpw *v, const mpw *vl)
92 {
93 MPSCAN_RINITX(m, v, vl);
94 }
95
96 /* --- @mpscan_rstep@ --- *
97 *
98 * Arguments: @mpscan *m@ = pointer to bitscanner
99 *
100 * Returns: Nonzero if there is another bit to read.
101 *
102 * Use: Steps on to the next bit in the integer. The macro version
103 * evaluates its argument multiple times.
104 */
105
106 int mpscan_rstep(mpscan *m) { return (MPSCAN_RSTEP(m)); }
107
108 /* --- @mpscan_rbit@ --- *
109 *
110 * Arguments: @const mpscan *m@ = pointer to bitscanner
111 *
112 * Returns: The value of the current bit.
113 *
114 * Use: Reads the value of the current bit looked at by a
115 * reverse bitscanner.
116 */
117
118 int mpscan_rbit(const mpscan *m) { return (MPSCAN_RBIT(m)); }
119
120 /*----- That's all, folks -------------------------------------------------*/