d03ab969 |
1 | /* -*-c-*- |
2 | * |
5fbe3846 |
3 | * $Id: mpscan.c,v 1.3 2000/07/29 17:03:31 mdw Exp $ |
d03ab969 |
4 | * |
5 | * Sequential bit scan of multiprecision integers |
6 | * |
7 | * (c) 1999 Straylight/Edgeware |
8 | */ |
9 | |
10 | /*----- Licensing notice --------------------------------------------------* |
11 | * |
12 | * This file is part of Catacomb. |
13 | * |
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. |
18 | * |
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. |
23 | * |
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, |
27 | * MA 02111-1307, USA. |
28 | */ |
29 | |
30 | /*----- Revision history --------------------------------------------------* |
31 | * |
32 | * $Log: mpscan.c,v $ |
5fbe3846 |
33 | * Revision 1.3 2000/07/29 17:03:31 mdw |
34 | * Add support for left-to-right bitscanning, for use in modular |
35 | * exponentiation. |
36 | * |
962405ef |
37 | * Revision 1.2 1999/11/13 01:55:10 mdw |
38 | * Fixed so that they compile. Minor interface changes. |
39 | * |
d03ab969 |
40 | * Revision 1.1 1999/09/03 08:41:12 mdw |
41 | * Initial import. |
42 | * |
43 | */ |
44 | |
45 | /*----- Header files ------------------------------------------------------*/ |
46 | |
962405ef |
47 | #include "mpscan.h" |
d03ab969 |
48 | |
5fbe3846 |
49 | /*----- Right-to-left scanning --------------------------------------------*/ |
d03ab969 |
50 | |
51 | /* --- @mpscan_initx@ --- * |
52 | * |
53 | * Arguments: @mpscan *m@ = pointer to bitscanner structure |
962405ef |
54 | * @const mpw *v, *vl@ = vector of words to scan |
d03ab969 |
55 | * |
56 | * Returns: --- |
57 | * |
58 | * Use: Initializes a bitscanner from a low-level vector-and-length |
59 | * representation of an integer. Initially no bit is ready; you |
60 | * must call @mpscan_step@ before anything useful will come |
61 | * out. |
62 | */ |
63 | |
962405ef |
64 | void mpscan_initx(mpscan *m, const mpw *v, const mpw *vl) |
d03ab969 |
65 | { |
962405ef |
66 | MPSCAN_INITX(m, v, vl); |
d03ab969 |
67 | } |
68 | |
69 | /* --- @mpscan_step@ --- * |
70 | * |
71 | * Arguments: @mpscan *m@ = pointer to bitscanner |
72 | * |
73 | * Returns: Nonzero if there is another bit to read. |
74 | * |
75 | * Use: Steps on to the next bit in the integer. The macro version |
76 | * evaluates its argument multiple times. |
77 | */ |
78 | |
79 | int mpscan_step(mpscan *m) { return (MPSCAN_STEP(m)); } |
80 | |
81 | /* --- @mpscan_bit@ --- * |
82 | * |
83 | * Arguments: @const mpscan *m@ = pointer to bitscanner |
84 | * |
85 | * Returns: The value of the current bit. |
86 | * |
87 | * Use: Reads the value of the current bit looked at by a |
88 | * bitscanner. |
89 | */ |
90 | |
91 | int mpscan_bit(const mpscan *m) { return (MPSCAN_BIT(m)); } |
92 | |
5fbe3846 |
93 | /*----- Left-to right-scanning --------------------------------------------*/ |
94 | |
95 | /* --- @mpscan_rinitx@ --- * |
96 | * |
97 | * Arguments: @mpscan *m@ = pointer to bitscanner structure |
98 | * @const mpw *v, *vl@ = vector of words to scan |
99 | * |
100 | * Returns: --- |
101 | * |
102 | * Use: Initializes a reverse bitscanner from a low-level |
103 | * vector-and-length representation of an integer. Initially no |
104 | * bit is ready; you must call @mpscan_rstep@ before anything |
105 | * useful will come out. |
106 | */ |
107 | |
108 | void mpscan_rinitx(mpscan *m, const mpw *v, const mpw *vl) |
109 | { |
110 | MPSCAN_RINITX(m, v, vl); |
111 | } |
112 | |
113 | /* --- @mpscan_rstep@ --- * |
114 | * |
115 | * Arguments: @mpscan *m@ = pointer to bitscanner |
116 | * |
117 | * Returns: Nonzero if there is another bit to read. |
118 | * |
119 | * Use: Steps on to the next bit in the integer. The macro version |
120 | * evaluates its argument multiple times. |
121 | */ |
122 | |
123 | int mpscan_rstep(mpscan *m) { return (MPSCAN_RSTEP(m)); } |
124 | |
125 | /* --- @mpscan_rbit@ --- * |
126 | * |
127 | * Arguments: @const mpscan *m@ = pointer to bitscanner |
128 | * |
129 | * Returns: The value of the current bit. |
130 | * |
131 | * Use: Reads the value of the current bit looked at by a |
132 | * reverse bitscanner. |
133 | */ |
134 | |
135 | int mpscan_rbit(const mpscan *m) { return (MPSCAN_RBIT(m)); } |
136 | |
d03ab969 |
137 | /*----- That's all, folks -------------------------------------------------*/ |