From: Jacob Lifshay Date: Fri, 16 Oct 2020 22:50:08 +0000 (-0700) Subject: add cmp and cmpl X-Git-Tag: v0.2.0~5 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=de665083a9d36e6ed82890c23272c3c7c046ccbe;p=power-instruction-analyzer.git add cmp and cmpl --- diff --git a/src/instr_models.rs b/src/instr_models.rs index 5d005de..dd8c037 100644 --- a/src/instr_models.rs +++ b/src/instr_models.rs @@ -806,3 +806,47 @@ pub fn cmplwi(inputs: InstructionInput) -> InstructionResult { ..InstructionOutput::default() }) } + +pub fn cmpd(inputs: InstructionInput) -> InstructionResult { + let ra = inputs.try_get_ra()? as i64; + let rb = inputs.try_get_rb()? as i64; + let so = inputs.try_get_overflow()?.so; + let cr0 = ConditionRegister::from_ordering(ra.cmp(&rb), so); + Ok(InstructionOutput { + cr0: Some(cr0), + ..InstructionOutput::default() + }) +} + +pub fn cmpw(inputs: InstructionInput) -> InstructionResult { + let ra = inputs.try_get_ra()? as i32; + let rb = inputs.try_get_rb()? as i32; + let so = inputs.try_get_overflow()?.so; + let cr0 = ConditionRegister::from_ordering(ra.cmp(&rb), so); + Ok(InstructionOutput { + cr0: Some(cr0), + ..InstructionOutput::default() + }) +} + +pub fn cmpld(inputs: InstructionInput) -> InstructionResult { + let ra = inputs.try_get_ra()? as u64; + let rb = inputs.try_get_rb()? as u64; + let so = inputs.try_get_overflow()?.so; + let cr0 = ConditionRegister::from_ordering(ra.cmp(&rb), so); + Ok(InstructionOutput { + cr0: Some(cr0), + ..InstructionOutput::default() + }) +} + +pub fn cmplw(inputs: InstructionInput) -> InstructionResult { + let ra = inputs.try_get_ra()? as u32; + let rb = inputs.try_get_rb()? as u32; + let so = inputs.try_get_overflow()?.so; + let cr0 = ConditionRegister::from_ordering(ra.cmp(&rb), so); + Ok(InstructionOutput { + cr0: Some(cr0), + ..InstructionOutput::default() + }) +} diff --git a/src/lib.rs b/src/lib.rs index 8fa9eec..940dfde 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -817,6 +817,26 @@ instructions! { fn cmplwi(Ra, ImmediateU16, Overflow) -> (CR0) { "cmplwi" } + + // cmp + #[enumerant = CmpD] + fn cmpd(Ra, Rb, Overflow) -> (CR0) { + "cmpd" + } + #[enumerant = CmpW] + fn cmpw(Ra, Rb, Overflow) -> (CR0) { + "cmpw" + } + + // cmpl + #[enumerant = CmpLD] + fn cmpld(Ra, Rb, Overflow) -> (CR0) { + "cmpld" + } + #[enumerant = CmpLW] + fn cmplw(Ra, Rb, Overflow) -> (CR0) { + "cmplw" + } } // must be after instrs macro call since it uses a macro definition