From: Jacob Lifshay Date: Wed, 14 Oct 2020 23:13:26 +0000 (-0700) Subject: add addis and addic[.] X-Git-Tag: v0.2.0~11 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e3403e87d302557a7c6498cf39d1d7934b1ee42d;p=power-instruction-analyzer.git add addis and addic[.] --- diff --git a/src/instr_models.rs b/src/instr_models.rs index 446e850..cdb3d18 100644 --- a/src/instr_models.rs +++ b/src/instr_models.rs @@ -66,6 +66,16 @@ pub fn addi(inputs: InstructionInput) -> InstructionResult { }) } +pub fn addis(inputs: InstructionInput) -> InstructionResult { + let ra = inputs.try_get_ra()? as i64; + let immediate = inputs.try_get_immediate_s16()? as i64; + let result = ra.wrapping_add(immediate << 16) as u64; + Ok(InstructionOutput { + rt: Some(result), + ..InstructionOutput::default() + }) +} + create_instr_variants_ov_cr!(add, addo, add_, addo_, i64); pub fn addo(inputs: InstructionInput) -> InstructionResult { @@ -81,6 +91,21 @@ pub fn addo(inputs: InstructionInput) -> InstructionResult { }) } +create_instr_variants_cr!(addic, addic_, i64); + +pub fn addic(inputs: InstructionInput) -> InstructionResult { + let ra = inputs.try_get_ra()? as i64; + let immediate = inputs.try_get_immediate_s16()? as i64; + let result = ra.wrapping_add(immediate) as u64; + let ca = (ra as u64).overflowing_add(immediate as u64).1; + let ca32 = (ra as u32).overflowing_add(immediate as u32).1; + Ok(InstructionOutput { + rt: Some(result), + carry: Some(CarryFlags { ca, ca32 }), + ..InstructionOutput::default() + }) +} + create_instr_variants_ov_cr!(subf, subfo, subf_, subfo_, i64); pub fn subfo(inputs: InstructionInput) -> InstructionResult { diff --git a/src/lib.rs b/src/lib.rs index 4cbfad9..5c67b24 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -309,6 +309,11 @@ instructions! { "addi" } + #[enumerant = AddIS] + fn addis(Ra, ImmediateS16) -> (Rt) { + "addis" + } + // add #[enumerant = Add] fn add(Ra, Rb) -> (Rt) { @@ -327,6 +332,16 @@ instructions! { "addo." } + // addic + #[enumerant = AddIC] + fn addic(Ra, ImmediateS16) -> (Rt, Carry) { + "addic" + } + #[enumerant = AddIC_] + fn addic_(Ra, ImmediateS16, Overflow) -> (Rt, Carry, CR0) { + "addic." + } + // subf #[enumerant = SubF] fn subf(Ra, Rb) -> (Rt) {