add cmpi
authorJacob Lifshay <programmerjake@gmail.com>
Fri, 16 Oct 2020 22:20:40 +0000 (15:20 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Fri, 16 Oct 2020 22:20:40 +0000 (15:20 -0700)
src/instr_models.rs
src/lib.rs

index 5eee17784bfb971306e95f5fc32d2141c514f526..ae3c23cfb694497b96b680de7458a25f33437f28 100644 (file)
@@ -762,3 +762,25 @@ pub fn maddld(inputs: InstructionInput) -> InstructionResult {
         ..InstructionOutput::default()
     })
 }
+
+pub fn cmpdi(inputs: InstructionInput) -> InstructionResult {
+    let ra = inputs.try_get_ra()? as i64;
+    let immediate = inputs.try_get_immediate_s16()? as i64;
+    let so = inputs.try_get_overflow()?.so;
+    let cr0 = ConditionRegister::from_ordering(ra.cmp(&immediate), so);
+    Ok(InstructionOutput {
+        cr0: Some(cr0),
+        ..InstructionOutput::default()
+    })
+}
+
+pub fn cmpwi(inputs: InstructionInput) -> InstructionResult {
+    let ra = inputs.try_get_ra()? as i32;
+    let immediate = inputs.try_get_immediate_s16()? as i32;
+    let so = inputs.try_get_overflow()?.so;
+    let cr0 = ConditionRegister::from_ordering(ra.cmp(&immediate), so);
+    Ok(InstructionOutput {
+        cr0: Some(cr0),
+        ..InstructionOutput::default()
+    })
+}
index e5d26e417ad47a0dd5be610d79b454e67e360d67..0e855624de644012ec79db4bc7e68ae8bf86ffe7 100644 (file)
@@ -130,6 +130,14 @@ impl ConditionRegister {
             so,
         }
     }
+    pub fn from_ordering(ordering: Ordering, so: bool) -> Self {
+        Self {
+            lt: ordering == Ordering::Less,
+            gt: ordering == Ordering::Greater,
+            eq: ordering == Ordering::Equal,
+            so,
+        }
+    }
 }
 
 #[derive(Copy, Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
@@ -789,6 +797,16 @@ instructions! {
     fn maddld(Ra, Rb, Rc) -> (Rt) {
         "maddld"
     }
+
+    // cmpi
+    #[enumerant = CmpDI]
+    fn cmpdi(Ra, ImmediateS16, Overflow) -> (CR0) {
+        "cmpdi"
+    }
+    #[enumerant = CmpWI]
+    fn cmpwi(Ra, ImmediateS16, Overflow) -> (CR0) {
+        "cmpwi"
+    }
 }
 
 // must be after instrs macro call since it uses a macro definition