From 6ec6589bd8d4415d0e78653a0c497981ee69b09d Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 5 Jan 2017 00:59:37 -0500 Subject: IR: pass MT19937_64 test --- src/bignum.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/bignum.cpp') diff --git a/src/bignum.cpp b/src/bignum.cpp index 192c16e636..e3b661e81a 100644 --- a/src/bignum.cpp +++ b/src/bignum.cpp @@ -88,7 +88,10 @@ bool bignum_fits_in_bits(BigNum *bn, int bit_count, bool is_signed) { void bignum_truncate(BigNum *bn, int bit_count) { assert(bn->kind == BigNumKindInt); - bn->data.x_uint &= (1LL << bit_count) - 1; + // TODO handle case when negative = true + if (bit_count < 64) { + bn->data.x_uint &= (1LL << bit_count) - 1; + } } uint64_t bignum_to_twos_complement(BigNum *bn) { @@ -142,11 +145,16 @@ void bignum_negate(BigNum *dest, BigNum *op) { } } -void bignum_not(BigNum *dest, BigNum *op, int bit_count) { +void bignum_not(BigNum *dest, BigNum *op, int bit_count, bool is_signed) { assert(op->kind == BigNumKindInt); uint64_t bits = ~bignum_to_twos_complement(op); - bits &= (1LL << bit_count) - 1; - bignum_init_signed(dest, bits); + if (bit_count < 64) { + bits &= (1LL << bit_count) - 1; + } + if (is_signed) + bignum_init_signed(dest, bits); + else + bignum_init_unsigned(dest, bits); } void bignum_cast_to_float(BigNum *dest, BigNum *op) { -- cgit v1.2.3