From 491ec6b1a457f87fc102af885a17b9d831459197 Mon Sep 17 00:00:00 2001 From: Paul Schoenfelder Date: Thu, 16 Nov 2023 20:50:06 -0500 Subject: [PATCH] test: add tests for i32 checked_shr intrinsic --- codegen/masm/src/tests.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/codegen/masm/src/tests.rs b/codegen/masm/src/tests.rs index 39ebec21c..9be37e0fc 100644 --- a/codegen/masm/src/tests.rs +++ b/codegen/masm/src/tests.rs @@ -756,4 +756,31 @@ proptest! { let result = u32::try_from(raw_result).map_err(|_| raw_result).map(|res| res as i32); prop_assert_eq!(result, Ok(a.wrapping_pow(b))); } + + #[test] + fn i32_checked_shr(a: i32, b in 0i32..32i32) { + let mut harness = TestByEmulationHarness::default(); + + harness + .emulator + .load_module( + Box::new( + Module::load_intrinsic("intrinsics::i32", &harness.context.session.codemap) + .expect("parsing failed"), + ) + .freeze(), + ) + .expect("failed to load intrinsics::i32"); + + let a_felt = Felt::new(a as u32 as u64); + let b_felt = Felt::new(b as u32 as u64); + let shr = "intrinsics::i32::checked_shr".parse().unwrap(); + let mut stack = harness.invoke(shr, &[b_felt, a_felt]).expect("execution failed"); + harness.emulator.stop(); + + prop_assert_eq!(stack.len(), 1); + let raw_result = stack.pop().unwrap().as_int(); + let result = u32::try_from(raw_result).map_err(|_| raw_result).map(|res| res as i32); + prop_assert_eq!(result, Ok(a >> b)); + } }