diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-06-26 08:17:45 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-06-26 08:17:45 -0700 |
commit | 4c581811e5370fd868a64e870d7ac046a606377b (patch) | |
tree | 852db519a15d7530072d91945562fca299face68 | |
parent | 4a9df6afcc6fe8ce8d7bac2d28b914a917d002f7 (diff) | |
download | txr-4c581811e5370fd868a64e870d7ac046a606377b.tar.gz txr-4c581811e5370fd868a64e870d7ac046a606377b.tar.bz2 txr-4c581811e5370fd868a64e870d7ac046a606377b.zip |
Fixes to bignum bit operations affecting pretty much all bit operations
when bit field operands are negative, affecting logand, logor, logxor,
lognot, logtrunc, logtest and ash. In addition, logtest was found to
return the logical inverse of its correct value.
* arith.c (logtest): Fix broken boolean polarity
of return value.
* mpi-patches/add-bitops (mp_2comp): Fix incorrect
treatment of negative values.
(mp_and): Fix incorrectly ordered statements, which
cause failure when operands are negative.
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | arith.c | 2 | ||||
-rw-r--r-- | mpi-patches/add-bitops | 14 |
3 files changed, 23 insertions, 8 deletions
@@ -1,3 +1,18 @@ +2014-06-26 Kaz Kylheku <kaz@kylheku.com> + + Fixes to bignum bit operations affecting pretty much all bit operations + when bit field operands are negative, affecting logand, logor, logxor, + lognot, logtrunc, logtest and ash. In addition, logtest was found to + return the logical inverse of its correct value. + + * arith.c (logtest): Fix broken boolean polarity + of return value. + + * mpi-patches/add-bitops (mp_2comp): Fix incorrect + treatment of negative values. + (mp_and): Fix incorrectly ordered statements, which + cause failure when operands are negative. + 2014-06-26 kaz kylheku <kaz@kylheku.com> * eval.c (iapply_s): new global variable. @@ -1655,7 +1655,7 @@ bad: val logtest(val a, val b) { /* TODO: optimize */ - return logand(a, b) == zero ? t : nil; + return logand(a, b) == zero ? nil : t; } static val comp_trunc(val a, val bits) diff --git a/mpi-patches/add-bitops b/mpi-patches/add-bitops index 2019aa50..64129b83 100644 --- a/mpi-patches/add-bitops +++ b/mpi-patches/add-bitops @@ -1,7 +1,7 @@ Index: mpi-1.8.6/mpi.c =================================================================== ---- mpi-1.8.6.orig/mpi.c 2014-02-19 19:01:39.562347737 -0800 -+++ mpi-1.8.6/mpi.c 2014-02-19 19:01:43.174297255 -0800 +--- mpi-1.8.6.orig/mpi.c 2014-06-16 11:22:15.632802821 -0700 ++++ mpi-1.8.6/mpi.c 2014-06-26 14:09:52.178356697 -0700 @@ -16,6 +16,9 @@ #include <ctype.h> #include <math.h> @@ -51,7 +51,7 @@ Index: mpi-1.8.6/mpi.c + + for (pa = DIGITS(a), pb = DIGITS(b), w = 0, ix = 0; ix < dig; ix++) { + w += (ix == 0); -+ w += (ix < adig) ? ~pa[ix] : ~padding; ++ w += (ix < adig) ? ~pa[ix] : padding; + pb[ix] = ACCUM(w); + w = CARRYOUT(w); + } @@ -74,16 +74,16 @@ Index: mpi-1.8.6/mpi.c + return mp_copy(a, c); + + if (ISNEG(a)) { -+ mp_init_size(&tmp_a, extent); + extent = USED(b); ++ mp_init_size(&tmp_a, extent); + if ((res = mp_2comp(a, &tmp_a, extent)) != MP_OKAY) + return res; + a = &tmp_a; + } + + if (ISNEG(b)) { -+ mp_init_size(&tmp_b, extent); + extent = USED(a); ++ mp_init_size(&tmp_b, extent); + if ((res = mp_2comp(b, &tmp_b, extent)) != MP_OKAY) { + if (ISNEG(a)) + mp_clear(&tmp_a); @@ -437,8 +437,8 @@ Index: mpi-1.8.6/mpi.c int ix; Index: mpi-1.8.6/mpi.h =================================================================== ---- mpi-1.8.6.orig/mpi.h 2014-02-19 19:01:29.302491325 -0800 -+++ mpi-1.8.6/mpi.h 2014-02-19 19:01:43.178297199 -0800 +--- mpi-1.8.6.orig/mpi.h 2014-06-16 11:22:15.620803044 -0700 ++++ mpi-1.8.6/mpi.h 2014-06-16 11:22:15.648802523 -0700 @@ -54,6 +54,7 @@ /* Macros for accessing the mp_int internals */ |