chiark / gitweb /
group-parse: Emit useful error messages when parsing fails.
[catacomb] / gfx.h
1 /* -*-c-*-
2  *
3  * $Id: gfx.h,v 1.3 2004/04/08 01:36:15 mdw Exp $
4  *
5  * Low-level arithmetic on binary polynomials
6  *
7  * (c) 2000 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 #ifndef CATACOMB_GFX_H
31 #define CATACOMB_GFX_H
32
33 #ifdef __cplusplus
34   extern "C" {
35 #endif
36
37 /*----- Header files ------------------------------------------------------*/
38
39 #ifndef CATACOMB_MPX_H
40 #  include "mpx.h"
41 #endif
42
43 /*----- Functions provided ------------------------------------------------*/
44
45 /* --- @gfx_add@ --- *
46  *
47  * Arguments:   @mpw *dv, *dvl@ = destination vector base and limit
48  *              @const mpw *av, *avl@ = first addend vector base and limit
49  *              @const mpw *bv, *bvl@ = second addend vector base and limit
50  *
51  * Returns:     ---
52  *
53  * Use:         Adds two %$\gf{2}$% polynomials.  This is the same as
54  *              subtraction.
55  */
56
57 extern void gfx_add(mpw */*dv*/, mpw */*dvl*/,
58                     const mpw */*av*/, const mpw */*avl*/,
59                     const mpw */*bv*/, const mpw */*bvl*/);
60
61 /* --- @gfx_acc@ --- *
62  *
63  * Arguments:   @mpw *dv, *dvl@ = destination vector base and limit
64  *              @const mpw *av, *avl@ = addend vector base and limit
65  *
66  * Returns:     ---
67  *
68  * Use:         Adds the addend into the destination.  This is considerably
69  *              faster than the three-address add call.
70  */
71
72 extern void gfx_acc(mpw */*dv*/, mpw */*dvl*/,
73                     const mpw */*av*/, const mpw */*avl*/);
74
75 /* --- @gfx_accshift@ --- *
76  *
77  * Arguments:   @mpw *dv, *dvl@ = destination vector base and limit
78  *              @const mpw *av, *avl@ = addend vector base and limit
79  *              @size_t n@ = number of bits to shift
80  *
81  * Returns:     ---
82  *
83  * Use:         Shifts the argument left by %$n$% places and adds it to the
84  *              destination.  This is a primitive used by multiplication and
85  *              division.
86  */
87
88 extern void gfx_accshift(mpw */*dv*/, mpw */*dvl*/,
89                          const mpw */*av*/, const mpw */*avl*/,
90                          size_t /*n*/);
91
92 /* --- @gfx_mul@ --- *
93  *
94  * Arguments:   @mpw *dv, *dvl@ = destination vector base and limit
95  *              @const mpw *av, *avl@ = first argument vector base and limit
96  *              @const mpw *bv, *bvl@ = second argument vector base and limit
97  *
98  * Returns:     ---
99  *
100  * Use:         Does multiplication of polynomials over %$\gf{2}$%.
101  */
102
103 extern void gfx_mul(mpw */*dv*/, mpw */*dvl*/,
104                     const mpw */*av*/, const mpw */*avl*/,
105                     const mpw */*bv*/, const mpw */*bvl*/);
106
107 /* --- @gfx_sqr@ --- *
108  *
109  * Arguments:   @mpw *dv, *dvl@ = destination vector base and limit
110  *              @const mpw *av, *avl@ = argument vector base and limit
111  *
112  * Returns:     ---
113  *
114  * Use:         Performs squaring of binary polynomials.
115  */
116
117 extern void gfx_sqr(mpw */*dv*/, mpw */*dvl*/,
118                     const mpw */*av*/, const mpw */*avl*/);
119
120 /* --- @gfx_div@ --- *
121  *
122  * Arguments:   @mpw *qv, *qvl@ = quotient vector base and limit
123  *              @mpw *rv, *rvl@ = dividend/remainder vector base and limit
124  *              @const mpw *dv, *dvl@ = divisor vector base and limit
125  *
126  * Returns:     ---
127  *
128  * Use:         Performs division on polynomials over %$\gf{2}$%.
129  */
130
131 extern void gfx_div(mpw */*qv*/, mpw */*qvl*/, mpw */*rv*/, mpw */*rvl*/,
132                     const mpw */*dv*/, const mpw */*dvl*/);
133
134 /*----- Karatsuba multiplication algorithms -------------------------------*/
135
136 /* --- @GFK_THRESH@ --- *
137  *
138  * This is the limiting length for using Karatsuba algorithms.  It's best to
139  * use the simpler classical multiplication method on numbers smaller than
140  * this.
141  */
142
143 #define GFK_THRESH 2
144
145 /* --- @gfx_kmul@ --- *
146  *
147  * Arguments:   @mpw *dv, *dvl@ = pointer to destination buffer
148  *              @const mpw *av, *avl@ = pointer to first argument
149  *              @const mpw *bv, *bvl@ = pointer to second argument
150  *              @mpw *sv, *svl@ = pointer to scratch workspace
151  *
152  * Returns:     ---
153  *
154  * Use:         Multiplies two binary polynomials using Karatsuba's
155  *              algorithm.  This is rather faster than traditional long
156  *              multiplication (e.g., @gfx_umul@) on polynomials with large
157  *              degree, although more expensive on small ones.
158  *
159  *              The destination must be twice as large as the larger
160  *              argument.  The scratch space must be twice as large as the
161  *              larger argument.
162  */
163
164 extern void gfx_kmul(mpw */*dv*/, mpw */*dvl*/,
165                      const mpw */*av*/, const mpw */*avl*/,
166                      const mpw */*bv*/, const mpw */*bvl*/,
167                      mpw */*sv*/, mpw */*svl*/);
168
169 /*----- That's all, folks -------------------------------------------------*/
170
171 #ifdef __cplusplus
172   }
173 #endif
174
175 #endif