working on add[o][.] implementation
[power-instruction-analyzer.git] / src / instr_models.rs
index df034e1e97366c0a513a0e08a9712b1060fbf8f7..8711e22b0deca9afaf55d7a0a2bbeed7176190a7 100644 (file)
@@ -38,19 +38,20 @@ macro_rules! create_instr_variants_cr {
     };
 }
 
-// create_instr_variants_ov_cr!(add, addo, add_, addo_, i64);
-//
-// pub fn addo(inputs: InstructionInput) -> InstructionResult {
-//     let ra = inputs.ra as i64;
-//     let rb = inputs.rb as i64;
-//     let (result, overflow) = ra.overflowing_add(rb);
-//     let result = result as u64;
-//     InstructionResult {
-//         rt: Some(result),
-//         overflow: Some(OverflowFlags::from_overflow(overflow)),
-//         ..InstructionResult::default()
-//     }
-// }
+create_instr_variants_ov_cr!(add, addo, add_, addo_, i64);
+
+pub fn addo(inputs: InstructionInput) -> InstructionResult {
+    let ra = inputs.ra as i64;
+    let rb = inputs.rb as i64;
+    let (result, ov) = ra.overflowing_add(rb);
+    let result = result as u64;
+    let ov32 = (ra as i32).overflowing_add(rb as i32).1;
+    InstructionResult {
+        rt: Some(result),
+        overflow: Some(OverflowFlags { so: ov, ov, ov32 }),
+        ..InstructionResult::default()
+    }
+}
 
 create_instr_variants_ov_cr!(divde, divdeo, divde_, divdeo_, i64);