3 * $Id: gfx.h,v 1.1 2000/10/08 15:49:37 mdw Exp $
5 * Low-level arithmetic on binary polynomials
7 * (c) 2000 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
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.
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.
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,
30 /*----- Revision history --------------------------------------------------*
33 * Revision 1.1 2000/10/08 15:49:37 mdw
34 * First glimmerings of binary polynomial arithmetic.
38 #ifndef CATACOMB_GFX_H
39 #define CATACOMB_GFX_H
45 /*----- Header files ------------------------------------------------------*/
47 #ifndef CATACOMB_MPX_H
51 /*----- Functions provided ------------------------------------------------*/
53 /* --- @gfx_add@ --- *
55 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
56 * @const mpw *av, *avl@ = first addend vector base and limit
57 * @const mpw *bv, *bvl@ = second addend vector base and limit
61 * Use: Adds two %$\gf{2}$% polynomials. This is the same as
65 extern void gfx_add(mpw */
*dv*/
, mpw */
*dvl*/
,
66 const mpw */
*av*/
, const mpw */
*avl*/
,
67 const mpw */
*bv*/
, const mpw */
*bvl*/
);
69 /* --- @gfx_acc@ --- *
71 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
72 * @const mpw *av, *avl@ = addend vector base and limit
76 * Use: Adds the addend into the destination. This is considerably
77 * faster than the three-address add call.
80 extern void gfx_acc(mpw */
*dv*/
, mpw */
*dvl*/
,
81 const mpw */
*av*/
, const mpw */
*avl*/
);
83 /* --- @gfx_accshift@ --- *
85 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
86 * @const mpw *av, *avl@ = addend vector base and limit
87 * @size_t n@ = number of bits to shift
91 * Use: Shifts the argument left by %$n$% places and adds it to the
92 * destination. This is a primitive used by multiplication and
96 extern void gfx_accshift(mpw */
*dv*/
, mpw */
*dvl*/
,
97 const mpw */
*av*/
, const mpw */
*avl*/
,
100 /* --- @gfx_mul@ --- *
102 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
103 * @const mpw *av, *avl@ = first argument vector base and limit
104 * @const mpw *bv, *bvl@ = second argument vector base and limit
108 * Use: Does multiplication of polynomials over %$\gf{2}$%.
111 extern void gfx_mul(mpw */
*dv*/
, mpw */
*dvl*/
,
112 const mpw */
*av*/
, const mpw */
*avl*/
,
113 const mpw */
*bv*/
, const mpw */
*bvl*/
);
115 /* --- @gfx_div@ --- *
117 * Arguments: @mpw *qv, *qvl@ = quotient vector base and limit
118 * @mpw *rv, *rvl@ = dividend/remainder vector base and limit
119 * @const mpw *dv, *dvl@ = divisor vector base and limit
123 * Use: Performs division on polynomials over %$\gf{2}$%.
126 extern void gfx_div(mpw */
*qv*/
, mpw */
*qvl*/
, mpw */
*rv*/
, mpw */
*rvl*/
,
127 const mpw */
*dv*/
, const mpw */
*dvl*/
);
129 /*----- Karatsuba multiplication algorithms -------------------------------*/
131 /* --- @GFK_THRESH@ --- *
133 * This is the limiting length for using Karatsuba algorithms. It's best to
134 * use the simpler classical multiplication method on numbers smaller than
140 /* --- @gfx_kmul@ --- *
142 * Arguments: @mpw *dv, *dvl@ = pointer to destination buffer
143 * @const mpw *av, *avl@ = pointer to first argument
144 * @const mpw *bv, *bvl@ = pointer to second argument
145 * @mpw *sv, *svl@ = pointer to scratch workspace
149 * Use: Multiplies two binary polynomials using Karatsuba's
150 * algorithm. This is rather faster than traditional long
151 * multiplication (e.g., @gfx_umul@) on polynomials with large
152 * degree, although more expensive on small ones.
154 * The destination must be twice as large as the larger
155 * argument. The scratch space must be twice as large as the
159 extern void gfx_kmul(mpw */
*dv*/
, mpw */
*dvl*/
,
160 const mpw */
*av*/
, const mpw */
*avl*/
,
161 const mpw */
*bv*/
, const mpw */
*bvl*/
,
162 mpw */
*sv*/
, mpw */
*svl*/
);
164 /*----- That's all, folks -------------------------------------------------*/