3 * $Id: karatsuba.h,v 1.3 2004/04/08 01:36:15 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 #ifndef CATACOMB_KARATSUBA_H
31 #define CATACOMB_KARATSUBA_H
37 /*----- Header files ------------------------------------------------------*/
39 #ifndef CATACOMB_MPW_H
43 /*----- Normal arithmetic macros ------------------------------------------*/
45 #define UADD(dv, av, avl) do { \
47 const mpw *_av = (av), *_avl = (avl); \
50 while (_av < _avl) { \
55 _x = (mpd)_a + (mpd)_b + _c; \
57 _c = _x >> MPW_BITS; \
60 mpd _x = (mpd)*_dv + (mpd)_c; \
62 _c = _x >> MPW_BITS; \
66 #define UADD2(dv, dvl, av, avl, bv, bvl) do { \
67 mpw *_dv = (dv), *_dvl = (dvl); \
68 const mpw *_av = (av), *_avl = (avl); \
69 const mpw *_bv = (bv), *_bvl = (bvl); \
72 while (_av < _avl || _bv < _bvl) { \
75 _a = (_av < _avl) ? *_av++ : 0; \
76 _b = (_bv < _bvl) ? *_bv++ : 0; \
77 _x = (mpd)_a + (mpd)_b + _c; \
79 _c = _x >> MPW_BITS; \
86 #define USUB(dv, av, avl) do { \
88 const mpw *_av = (av), *_avl = (avl); \
91 while (_av < _avl) { \
96 _x = (mpd)_b - (mpd)_a - _c; \
104 mpd _x = (mpd)*_dv - (mpd)_c; \
106 if (_x >> MPW_BITS) \
113 /*----- Binary polynomial arithmetic macros -------------------------------*/
115 #define UXOR(dv, av, avl) do { \
117 const mpw *_av = (av), *_avl = (avl); \
123 #define UXOR2(dv, dvl, av, avl, bv, bvl) do { \
124 mpw *_dv = (dv), *_dvl = (dvl); \
125 const mpw *_av = (av), *_avl = (avl); \
126 const mpw *_bv = (bv), *_bvl = (bvl); \
128 while (_av < _avl || _bv < _bvl) { \
130 _a = (_av < _avl) ? *_av++ : 0; \
131 _b = (_bv < _bvl) ? *_bv++ : 0; \
138 /*----- That's all, folks -------------------------------------------------*/