From db23c306ae1e315520677f57eb0a3244e657bcb9 Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Thu, 27 Aug 2020 13:57:43 -0700 Subject: [PATCH] add add[o][.] --- src/instr_models.rs | 14 ++++++++++++++ src/lib.rs | 22 ++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/instr_models.rs b/src/instr_models.rs index c58806e..2547fa3 100644 --- a/src/instr_models.rs +++ b/src/instr_models.rs @@ -38,6 +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!(divde, divdeo, divde_, divdeo_, i64); pub fn divdeo(inputs: InstructionInput) -> InstructionResult { diff --git a/src/lib.rs b/src/lib.rs index 51f0d16..98880c2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -312,8 +312,8 @@ macro_rules! instr { "mfxer $1\n", "mfcr $2\n", ) - : "=&r"(rt), "=&r"(xer), "=&r"(cr) - : "r"(ra), "r"(rb), "r"(rc), "r"(0u64), "r"(!0x8000_0000u64) + : "=&b"(rt), "=&b"(xer), "=&b"(cr) + : "b"(ra), "b"(rb), "b"(rc), "b"(0u64), "b"(!0x8000_0000u64) : "xer", "cr"); } let mut retval = InstructionResult::default(); @@ -405,6 +405,24 @@ macro_rules! instrs { } instrs! { + // add + #[enumerant = Add] + fn add(ra, rb) -> (rt) { + "add" + } + #[enumerant = AddO] + fn addo(ra, rb) -> (rt, ov) { + "addo" + } + #[enumerant = Add_] + fn add_(ra, rb) -> (rt, cr0) { + "add." + } + #[enumerant = AddO_] + fn addo_(ra, rb) -> (rt, ov, cr0) { + "addo." + } + // divde #[enumerant = DivDE] fn divde(ra, rb) -> (rt) { -- 2.30.2