X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/b817bfc642225b8c3c0b6a7e42d1fb949b61a606..95d9246390251adba7e6e9f0cc70bf0ebe0b2e60:/mpx.c diff --git a/mpx.c b/mpx.c index e122760..29e1ded 100644 --- a/mpx.c +++ b/mpx.c @@ -1,13 +1,13 @@ /* -*-c-*- * - * $Id: mpx.c,v 1.20 2004/04/08 01:36:15 mdw Exp $ + * $Id$ * * Low-level multiprecision arithmetic * * (c) 1999 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of Catacomb. * @@ -15,12 +15,12 @@ * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. - * + * * Catacomb is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. - * + * * You should have received a copy of the GNU Library General Public * License along with Catacomb; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, @@ -417,7 +417,7 @@ void mpx_lsl(mpw *dv, mpw *dvl, const mpw *av, const mpw *avl, size_t n) } /* --- Break out word and bit shifts for more sophisticated work --- */ - + nw = n / MPW_BITS; nb = n % MPW_BITS; @@ -462,11 +462,11 @@ void mpx_lsl(mpw *dv, mpw *dvl, const mpw *av, const mpw *avl, size_t n) while (avl > av) { mpw t = *--avl; - *--dvl = (t >> nr) | w; + *--dvl = MPW((t >> nr) | w); w = t << nb; } - *--dvl = w; + *--dvl = MPW(w); MPX_ZERO(dv, dvl); } @@ -515,7 +515,7 @@ void mpx_lslc(mpw *dv, mpw *dvl, const mpw *av, const mpw *avl, size_t n) } /* --- Break out word and bit shifts for more sophisticated work --- */ - + nw = n / MPW_BITS; nb = n % MPW_BITS; @@ -560,11 +560,11 @@ void mpx_lslc(mpw *dv, mpw *dvl, const mpw *av, const mpw *avl, size_t n) while (avl > av) { mpw t = *--avl; - *--dvl = (t >> nr) | w; + *--dvl = MPW((t >> nr) | w); w = t << nb; } - *--dvl = (MPW_MAX >> nr) | w; + *--dvl = MPW((MPW_MAX >> nr) | w); MPX_ONE(dv, dvl); } @@ -919,7 +919,7 @@ void mpx_usubnlsl(mpw *dv, mpw *dvl, mpw a, unsigned o) a <<= o; if (dv < dvl) { - mpd x = (mpd)*dv - (mpd)a; + mpd x = (mpd)*dv - MPW(a); *dv++ = MPW(x); if (x >> MPW_BITS) b++; @@ -950,7 +950,7 @@ void mpx_umul(mpw *dv, mpw *dvl, const mpw *av, const mpw *avl, MPX_SHRINK(bv, bvl); /* --- Deal with a multiply by zero --- */ - + if (bv == bvl) { MPX_ZERO(dv, dvl); return; @@ -995,9 +995,7 @@ void mpx_umul(mpw *dv, mpw *dvl, const mpw *av, const mpw *avl, */ void mpx_umuln(mpw *dv, mpw *dvl, const mpw *av, const mpw *avl, mpw m) -{ - MPX_UMULN(dv, dvl, av, avl, m); -} + { MPX_UMULN(dv, dvl, av, avl, m); } /* --- @mpx_umlan@ --- * * @@ -1012,9 +1010,7 @@ void mpx_umuln(mpw *dv, mpw *dvl, const mpw *av, const mpw *avl, mpw m) */ void mpx_umlan(mpw *dv, mpw *dvl, const mpw *av, const mpw *avl, mpw m) -{ - MPX_UMLAN(dv, dvl, av, avl, m); -} + { MPX_UMLAN(dv, dvl, av, avl, m); } /* --- @mpx_usqr@ --- * * @@ -1120,7 +1116,7 @@ void mpx_udiv(mpw *qv, mpw *qvl, mpw *rv, mpw *rvl, unsigned b; d = dvl[-1]; - for (b = MPW_BITS / 2; b; b >>= 1) { + for (b = MPW_P2; b; b >>= 1) { if (d <= (MPW_MAX >> b)) { d <<= b; norm += b; @@ -1334,7 +1330,7 @@ mpw mpx_udivn(mpw *qv, mpw *qvl, const mpw *rv, const mpw *rvl, mpw d) } while (0) #define MAX(x, y) ((x) > (y) ? (x) : (y)) - + static void dumpbits(const char *msg, const void *pp, size_t sz) { const octet *p = pp; @@ -1421,7 +1417,7 @@ static int loadstore(dstr *v) if (!ok) dumpbits("input data", v->buf, v->len); - free(m); + xfree(m); dstr_destroy(&d); return (ok); } @@ -1459,7 +1455,7 @@ static int twocl(dstr *v) dumpbits("neg", v[1].buf, v[1].len); } - free(m); + xfree(m); dstr_destroy(&d); return (ok); @@ -1498,7 +1494,7 @@ static int twocb(dstr *v) dumpbits("neg", v[1].buf, v[1].len); } - free(m); + xfree(m); dstr_destroy(&d); return (ok); @@ -1519,13 +1515,13 @@ static int lsl(dstr *v) mpx_lsl(d, dl, a, al, n); if (!mpx_ueq(d, dl, c, cl)) { fprintf(stderr, "\n*** lsl(%i) failed\n", n); - dumpmp(" a", a, al); + dumpmp(" a", a, al); dumpmp("expected", c, cl); dumpmp(" result", d, dl); ok = 0; } - free(a); free(c); free(d); + xfree(a); xfree(c); xfree(d); return (ok); } @@ -1544,13 +1540,13 @@ static int lslc(dstr *v) mpx_lslc(d, dl, a, al, n); if (!mpx_ueq(d, dl, c, cl)) { fprintf(stderr, "\n*** lslc(%i) failed\n", n); - dumpmp(" a", a, al); + dumpmp(" a", a, al); dumpmp("expected", c, cl); dumpmp(" result", d, dl); ok = 0; } - free(a); free(c); free(d); + xfree(a); xfree(c); xfree(d); return (ok); } @@ -1569,13 +1565,13 @@ static int lsr(dstr *v) mpx_lsr(d, dl, a, al, n); if (!mpx_ueq(d, dl, c, cl)) { fprintf(stderr, "\n*** lsr(%i) failed\n", n); - dumpmp(" a", a, al); + dumpmp(" a", a, al); dumpmp("expected", c, cl); dumpmp(" result", d, dl); ok = 0; } - free(a); free(c); free(d); + xfree(a); xfree(c); xfree(d); return (ok); } @@ -1595,14 +1591,14 @@ static int uadd(dstr *v) mpx_uadd(d, dl, a, al, b, bl); if (!mpx_ueq(d, dl, c, cl)) { fprintf(stderr, "\n*** uadd failed\n"); - dumpmp(" a", a, al); - dumpmp(" b", b, bl); + dumpmp(" a", a, al); + dumpmp(" b", b, bl); dumpmp("expected", c, cl); dumpmp(" result", d, dl); ok = 0; } - free(a); free(b); free(c); free(d); + xfree(a); xfree(b); xfree(c); xfree(d); return (ok); } @@ -1622,14 +1618,14 @@ static int usub(dstr *v) mpx_usub(d, dl, a, al, b, bl); if (!mpx_ueq(d, dl, c, cl)) { fprintf(stderr, "\n*** usub failed\n"); - dumpmp(" a", a, al); - dumpmp(" b", b, bl); + dumpmp(" a", a, al); + dumpmp(" b", b, bl); dumpmp("expected", c, cl); dumpmp(" result", d, dl); ok = 0; } - free(a); free(b); free(c); free(d); + xfree(a); xfree(b); xfree(c); xfree(d); return (ok); } @@ -1649,14 +1645,14 @@ static int umul(dstr *v) mpx_umul(d, dl, a, al, b, bl); if (!mpx_ueq(d, dl, c, cl)) { fprintf(stderr, "\n*** umul failed\n"); - dumpmp(" a", a, al); - dumpmp(" b", b, bl); + dumpmp(" a", a, al); + dumpmp(" b", b, bl); dumpmp("expected", c, cl); dumpmp(" result", d, dl); ok = 0; } - free(a); free(b); free(c); free(d); + xfree(a); xfree(b); xfree(c); xfree(d); return (ok); } @@ -1674,13 +1670,13 @@ static int usqr(dstr *v) mpx_usqr(d, dl, a, al); if (!mpx_ueq(d, dl, c, cl)) { fprintf(stderr, "\n*** usqr failed\n"); - dumpmp(" a", a, al); + dumpmp(" a", a, al); dumpmp("expected", c, cl); dumpmp(" result", d, dl); ok = 0; } - free(a); free(c); free(d); + xfree(a); xfree(c); xfree(d); return (ok); } @@ -1713,7 +1709,7 @@ static int udiv(dstr *v) ok = 0; } - free(a); free(b); free(r); free(q); free(s); free(qq); + xfree(a); xfree(b); xfree(r); xfree(q); xfree(s); xfree(qq); return (ok); }