7765e926 |
1 | /* -*-c-*- |
7765e926 |
2 | * |
3 | * Generalized exponentiation |
4 | * |
5 | * (c) 2001 Straylight/Edgeware |
6 | */ |
7 | |
45c0fd36 |
8 | /*----- Licensing notice --------------------------------------------------* |
7765e926 |
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 | * |
7765e926 |
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 | * |
7765e926 |
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 | |
7765e926 |
28 | /*----- Header files ------------------------------------------------------*/ |
29 | |
30 | #define EXP_TYPE /* Hack */ |
31 | #include "exp.h" |
32 | |
33 | /*----- Main code ---------------------------------------------------------*/ |
34 | |
35 | /* --- @exp_simulnext@ --- * |
36 | * |
37 | * Arguments: @exp_simul *e@ = pointer to state structure |
38 | * @size_t x@ = a current accumulator |
39 | * |
40 | * Returns: The next column of bits. |
41 | * |
42 | * Use: Scans the next column of bits for a simultaneous |
43 | * exponentiation. |
44 | */ |
45 | |
46 | size_t exp_simulnext(exp_simul *e, size_t x) |
47 | { |
48 | size_t i; |
49 | |
50 | /* --- Move to the next word along --- */ |
51 | |
52 | if (!e->b) { |
53 | e->o--; |
54 | for (i = 0; i < e->n; i++) |
55 | e->s[i].w = e->o < e->s[i].len ? e->s[i].v[e->o] : 0; |
56 | e->b = MPW_BITS; |
57 | } |
58 | |
59 | /* --- Scan out a column of bits --- */ |
60 | |
61 | for (i = 0; i < e->n; i++) { |
62 | x = (x << 1) | ((e->s[i].w >> (MPW_BITS - 1)) & 1u); |
63 | e->s[i].w <<= 1; |
45c0fd36 |
64 | } |
7765e926 |
65 | e->b--; |
66 | return (x); |
67 | } |
68 | |
69 | /*----- That's all, folks -------------------------------------------------*/ |