Fix bigint shift-right partial shift

This commit is contained in:
Marc Tiehuis 2018-05-10 22:26:26 +12:00
parent c3ddf5069e
commit efa39c5343
2 changed files with 9 additions and 1 deletions

View File

@ -1425,7 +1425,7 @@ void bigint_shr(BigInt *dest, const BigInt *op1, const BigInt *op2) {
uint64_t digit = op1_digits[op_digit_index]; uint64_t digit = op1_digits[op_digit_index];
size_t dest_digit_index = op_digit_index - digit_shift_count; size_t dest_digit_index = op_digit_index - digit_shift_count;
dest->data.digits[dest_digit_index] = carry | (digit >> leftover_shift_count); dest->data.digits[dest_digit_index] = carry | (digit >> leftover_shift_count);
carry = digit << leftover_shift_count; carry = digit << (64 - leftover_shift_count);
if (dest_digit_index == 0) { break; } if (dest_digit_index == 0) { break; }
op_digit_index -= 1; op_digit_index -= 1;

View File

@ -366,6 +366,14 @@ test "big number multi-limb shift and mask" {
} }
} }
test "big number multi-limb partial shift right" {
comptime {
var a = 0x1ffffffffeeeeeeee;
a >>= 16;
assert(a == 0x1ffffffffeeee);
}
}
test "xor" { test "xor" {
test_xor(); test_xor();
comptime test_xor(); comptime test_xor();