3 * Macros for Karatsuba functions
5 * (c) 2000 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
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.
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.
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,
28 #ifndef CATACOMB_KARATSUBA_H
29 #define CATACOMB_KARATSUBA_H
35 /*----- Header files ------------------------------------------------------*/
37 #ifndef CATACOMB_MPW_H
41 /*----- Normal arithmetic macros ------------------------------------------*/
43 #define UADD(dv, av, avl) do { \
45 const mpw *_av = (av), *_avl = (avl); \
48 while (_av < _avl) { \
53 _x = (mpd)_a + (mpd)_b + _c; \
55 _c = _x >> MPW_BITS; \
58 mpd _x = (mpd)*_dv + (mpd)_c; \
60 _c = _x >> MPW_BITS; \
64 #define UADD2(dv, dvl, av, avl, bv, bvl) do { \
65 mpw *_dv = (dv), *_dvl = (dvl); \
66 const mpw *_av = (av), *_avl = (avl); \
67 const mpw *_bv = (bv), *_bvl = (bvl); \
70 while (_av < _avl || _bv < _bvl) { \
73 _a = (_av < _avl) ? *_av++ : 0; \
74 _b = (_bv < _bvl) ? *_bv++ : 0; \
75 _x = (mpd)_a + (mpd)_b + _c; \
77 _c = _x >> MPW_BITS; \
84 #define USUB(dv, av, avl) do { \
86 const mpw *_av = (av), *_avl = (avl); \
89 while (_av < _avl) { \
94 _x = (mpd)_b - (mpd)_a - _c; \
102 mpd _x = (mpd)*_dv - (mpd)_c; \
104 if (_x >> MPW_BITS) \
111 /*----- Binary polynomial arithmetic macros -------------------------------*/
113 #define UXOR(dv, av, avl) do { \
115 const mpw *_av = (av), *_avl = (avl); \
121 #define UXOR2(dv, dvl, av, avl, bv, bvl) do { \
122 mpw *_dv = (dv), *_dvl = (dvl); \
123 const mpw *_av = (av), *_avl = (avl); \
124 const mpw *_bv = (bv), *_bvl = (bvl); \
126 while (_av < _avl || _bv < _bvl) { \
128 _a = (_av < _avl) ? *_av++ : 0; \
129 _b = (_bv < _bvl) ? *_bv++ : 0; \
136 /*----- That's all, folks -------------------------------------------------*/