3 * $Id: karatsuba.h,v 1.2 2000/10/08 15:47:47 mdw Exp $
5 * Macros for Karatsuba functions
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 --------------------------------------------------*
32 * $Log: karatsuba.h,v $
33 * Revision 1.2 2000/10/08 15:47:47 mdw
34 * Rename from `mpx-kmac.h', and add macros for @gfx_kmul@.
36 * Revision 1.1 2000/06/17 11:42:11 mdw
37 * Moved the Karatsuba macros into a separate file for better sharing.
38 * Fixed some comments.
42 #ifndef CATACOMB_KARATSUBA_H
43 #define CATACOMB_KARATSUBA_H
49 /*----- Header files ------------------------------------------------------*/
51 #ifndef CATACOMB_MPW_H
55 /*----- Normal arithmetic macros ------------------------------------------*/
57 #define UADD(dv, av, avl) do { \
59 const mpw *_av = (av), *_avl = (avl); \
62 while (_av < _avl) { \
67 _x = (mpd)_a + (mpd)_b + _c; \
69 _c = _x >> MPW_BITS; \
72 mpd _x = (mpd)*_dv + (mpd)_c; \
74 _c = _x >> MPW_BITS; \
78 #define UADD2(dv, dvl, av, avl, bv, bvl) do { \
79 mpw *_dv = (dv), *_dvl = (dvl); \
80 const mpw *_av = (av), *_avl = (avl); \
81 const mpw *_bv = (bv), *_bvl = (bvl); \
84 while (_av < _avl || _bv < _bvl) { \
87 _a = (_av < _avl) ? *_av++ : 0; \
88 _b = (_bv < _bvl) ? *_bv++ : 0; \
89 _x = (mpd)_a + (mpd)_b + _c; \
91 _c = _x >> MPW_BITS; \
98 #define USUB(dv, av, avl) do { \
100 const mpw *_av = (av), *_avl = (avl); \
103 while (_av < _avl) { \
108 _x = (mpd)_b - (mpd)_a - _c; \
110 if (_x >> MPW_BITS) \
116 mpd _x = (mpd)*_dv - (mpd)_c; \
118 if (_x >> MPW_BITS) \
125 /*----- Binary polynomial arithmetic macros -------------------------------*/
127 #define UXOR(dv, av, avl) do { \
129 const mpw *_av = (av), *_avl = (avl); \
135 #define UXOR2(dv, dvl, av, avl, bv, bvl) do { \
136 mpw *_dv = (dv), *_dvl = (dvl); \
137 const mpw *_av = (av), *_avl = (avl); \
138 const mpw *_bv = (bv), *_bvl = (bvl); \
140 while (_av < _avl || _bv < _bvl) { \
142 _a = (_av < _avl) ? *_av++ : 0; \
143 _b = (_bv < _bvl) ? *_bv++ : 0; \
150 /*----- That's all, folks -------------------------------------------------*/