chiark / gitweb /
math/f25519.c: Order 10-bit constants the same as 26-bit constants.
[catacomb] / math / mpscan.c
CommitLineData
d03ab969 1/* -*-c-*-
d03ab969 2 *
3 * Sequential bit scan of multiprecision integers
4 *
5 * (c) 1999 Straylight/Edgeware
6 */
7
45c0fd36 8/*----- Licensing notice --------------------------------------------------*
d03ab969 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.
45c0fd36 16 *
d03ab969 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.
45c0fd36 21 *
d03ab969 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
d03ab969 28/*----- Header files ------------------------------------------------------*/
29
962405ef 30#include "mpscan.h"
d03ab969 31
5fbe3846 32/*----- Right-to-left scanning --------------------------------------------*/
d03ab969 33
34/* --- @mpscan_initx@ --- *
35 *
36 * Arguments: @mpscan *m@ = pointer to bitscanner structure
962405ef 37 * @const mpw *v, *vl@ = vector of words to scan
d03ab969 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
962405ef 47void mpscan_initx(mpscan *m, const mpw *v, const mpw *vl)
d03ab969 48{
962405ef 49 MPSCAN_INITX(m, v, vl);
d03ab969 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
62int 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
74int mpscan_bit(const mpscan *m) { return (MPSCAN_BIT(m)); }
75
5fbe3846 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
91void 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
106int 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
118int mpscan_rbit(const mpscan *m) { return (MPSCAN_RBIT(m)); }
119
d03ab969 120/*----- That's all, folks -------------------------------------------------*/