Skip to content

Commit

Permalink
test sub
Browse files Browse the repository at this point in the history
  • Loading branch information
ekiwi committed May 24, 2024
1 parent 3c02a31 commit bd8a064
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ pub(crate) fn sub(dst: &mut [Word], a: &[Word], b: &[Word], width: WidthInt) {
#[inline]
pub(crate) fn mul(dst: &mut [Word], a: &[Word], b: &[Word], width: WidthInt) {
if width <= Word::BITS {
dst[0] = (a[0] * b[0]) & mask(width);
let (res, _) = a[0].overflowing_mul(b[0]);
dst[0] = res & mask(width);
} else {
todo!(
"implement multiplication for bit vectors larger {}",
Expand Down Expand Up @@ -656,6 +657,15 @@ mod tests {
do_test_arith(a, b, width, mul, |a, b| a * b)
}

#[test]
fn test_mul_regressions() {
do_test_mul(
BigInt::from(1099511627776i64),
BigInt::from(1099511627776i64),
50,
);
}

proptest! {
#![proptest_config(ProptestConfig::with_cases(2000))]
#[test]
Expand Down Expand Up @@ -697,6 +707,17 @@ mod tests {
fn test_add((a, b, width) in gen_big_int_pair()) {
do_test_add(a, b, width);
}

#[test]
fn test_sub((a, b, width) in gen_big_int_pair()) {
do_test_sub(a, b, width);
}

#[ignore] // TODO: implement mul for bitwidths > 64
#[test]
fn test_mul((a, b, width) in gen_big_int_pair()) {
do_test_mul(a, b, width);
}
}
}

Expand Down

0 comments on commit bd8a064

Please sign in to comment.