From 84dd11510b10ece9db45ca7d52b7a60df9225d7f Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Wed, 27 May 2020 23:24:56 -0700 Subject: [PATCH] working on instruction models --- src/instr_models.rs | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/instr_models.rs b/src/instr_models.rs index a609bcb..092f359 100644 --- a/src/instr_models.rs +++ b/src/instr_models.rs @@ -10,8 +10,13 @@ pub fn divdeo(inputs: TestDivInput) -> TestDivResult { overflow = true; } else { let result128 = dividend / divisor; - result = result128 as u64; - overflow = result128 as i64 as i128 != result128; + if result128 as i64 as i128 != result128 { + result = 0; + overflow = true; + } else { + result = result128 as u64; + overflow = false; + } } TestDivResult { result, @@ -32,8 +37,13 @@ pub fn divdeuo(inputs: TestDivInput) -> TestDivResult { overflow = true; } else { let resultu128 = dividend / divisor; - result = resultu128 as u64; - overflow = resultu128 > u128::from(u64::max_value()); + if resultu128 > u128::from(u64::max_value()) { + result = 0; + overflow = true; + } else { + result = resultu128 as u64; + overflow = false; + } } TestDivResult { result, @@ -96,8 +106,13 @@ pub fn divweo(inputs: TestDivInput) -> TestDivResult { overflow = true; } else { let result64 = dividend / divisor; - result = result64 as u32 as u64; - overflow = result64 as i32 as i64 != result64; + if result64 as i32 as i64 != result64 { + result = 0; + overflow = true; + } else { + result = result64 as u32 as u64; + overflow = false; + } } TestDivResult { result, @@ -118,8 +133,12 @@ pub fn divweuo(inputs: TestDivInput) -> TestDivResult { overflow = true; } else { let resultu64 = dividend / divisor; - result = resultu64 as u32 as u64; - overflow = resultu64 > u64::from(u32::max_value()); + if resultu64 > u64::from(u32::max_value()) { + result = 0; + } else { + result = resultu64 as u32 as u64; + } + overflow = false; } TestDivResult { result, -- 2.30.2