From: Jacob Lifshay Date: Fri, 4 Sep 2020 03:37:49 +0000 (-0700) Subject: add neg* instructions X-Git-Tag: v0.2.0~15 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4aab893fde737f0f19fc9a1cc98f90e83a93dc0a;p=power-instruction-analyzer.git add neg* instructions --- diff --git a/src/instr_models.rs b/src/instr_models.rs index 2fee3db..5389383 100644 --- a/src/instr_models.rs +++ b/src/instr_models.rs @@ -284,6 +284,20 @@ pub fn addex(inputs: InstructionInput) -> InstructionResult { }) } +create_instr_variants_ov_cr!(neg, nego, neg_, nego_, i64); + +pub fn nego(inputs: InstructionInput) -> InstructionResult { + let ra = inputs.try_get_ra()? as i64; + let result = ra.wrapping_neg() as u64; + let ov = ra.checked_neg().is_none(); + let ov32 = (ra as i32).checked_neg().is_none(); + Ok(InstructionOutput { + rt: Some(result), + overflow: Some(propagate_so(OverflowFlags { so: ov, ov, ov32 }, inputs)?), + ..InstructionOutput::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 7d85cd8..81d8fed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -465,6 +465,24 @@ instructions! { "addex" : ".long 0x7CA32154 # addex r5, r3, r4, 0" } + // neg + #[enumerant = Neg] + fn neg(Ra) -> (Rt) { + "neg" + } + #[enumerant = NegO] + fn nego(Ra, Overflow) -> (Rt, Overflow) { + "nego" + } + #[enumerant = Neg_] + fn neg_(Ra, Overflow) -> (Rt, CR0) { + "neg." + } + #[enumerant = NegO_] + fn nego_(Ra, Overflow) -> (Rt, Overflow, CR0) { + "nego." + } + // divde #[enumerant = DivDE] fn divde(Ra, Rb) -> (Rt) {