Skip to content

test: Add exec tests for widen op #2043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions hugr-llvm/src/extension/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,46 @@ mod test {
assert_eq!(int_exec_ctx.exec_hugr_u64(hugr, "main"), result);
}

#[rstest]
#[case(-127)]
#[case(-1)]
#[case(0)]
#[case(1)]
#[case(127)]
fn test_exec_widen(int_exec_ctx: TestContext, #[case] num: i16) {
let from: u8 = 3;
let to: u8 = 6;
let ty = INT_TYPES[to as usize].clone();

if num >= 0 {
let input = ConstInt::new_u(from, num as u64).unwrap();

let ext_op = int_ops::EXTENSION
.instantiate_extension_op(
"iwiden_u".as_ref(),
[(from as u64).into(), (to as u64).into()],
)
.unwrap();

let hugr = test_int_op_with_results::<1>(ext_op, to, Some([input]), ty.clone());

assert_eq!(int_exec_ctx.exec_hugr_u64(hugr, "main"), num as u64);
}

let input = ConstInt::new_s(from, num as i64).unwrap();

let ext_op = int_ops::EXTENSION
.instantiate_extension_op(
"iwiden_s".as_ref(),
[(from as u64).into(), (to as u64).into()],
)
.unwrap();

let hugr = test_int_op_with_results::<1>(ext_op, to, Some([input]), ty.clone());

assert_eq!(int_exec_ctx.exec_hugr_i64(hugr, "main"), num as i64);
}

#[rstest]
#[case("inarrow_s", 6, 2, 4)]
#[case("inarrow_s", 6, 5, (1 << 5) - 1)]
Expand Down
Loading