use super::Encoding::{self, T1};
use super::Instruction;
use super::{
ArmVersion::{V7EM, V7M, V8M},
Pattern,
};
use crate::{
core::ItState,
core::{Effect, Processor, RunError},
decoder::DecodeError,
instructions::{unpredictable, DecodeHelper},
registers::RegisterIndex,
};
pub struct Sdiv {
rd: RegisterIndex,
rn: RegisterIndex,
rm: RegisterIndex,
}
impl Instruction for Sdiv {
fn patterns() -> &'static [Pattern] {
&[Pattern {
encoding: T1,
versions: &[V7M, V7EM, V8M],
expression: "111110111001xxxx(1)(1)(1)(1)xxxx1111xxxx",
}]
}
fn try_decode(encoding: Encoding, ins: u32, _state: ItState) -> Result<Self, DecodeError> {
debug_assert_eq!(encoding, T1);
let rd = ins.reg4(8);
let rn = ins.reg4(16);
let rm = ins.reg4(0);
unpredictable(rd.is_sp_or_pc() || rn.is_sp_or_pc() || rm.is_sp_or_pc())?;
Ok(Self { rd, rn, rm })
}
fn execute(&self, proc: &mut Processor) -> Result<Effect, RunError> {
let rm = proc[self.rm];
let result = if rm == 0 {
todo!()
} else {
(proc[self.rn] as i32 / rm as i32) as u32
};
proc.set(self.rd, result);
Ok(Effect::None)
}
fn name(&self) -> String {
"sdiv".into()
}
fn args(&self, _pc: u32) -> String {
format!("{}, {}, {}", self.rd, self.rn, self.rm)
}
}