From c5c8d23470be6bb85c80c85967ba230c47e9a197 Mon Sep 17 00:00:00 2001 From: Erin Date: Mon, 13 Nov 2023 00:12:18 +0100 Subject: [PATCH] Fixed immediate ops --- hbvm/src/vmrun.rs | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/hbvm/src/vmrun.rs b/hbvm/src/vmrun.rs index 5dac0a69e..21525a915 100644 --- a/hbvm/src/vmrun.rs +++ b/hbvm/src/vmrun.rs @@ -19,7 +19,7 @@ macro_rules! handler { ($self:expr, |$ty:ident ($($ident:pat),* $(,)?)| $expr:expr) => {{ let $ty($($ident),*) = $self.decode::<$ty>(); #[allow(clippy::no_effect)] let e = $expr; - $self.bump_pc::<$ty, true>(); + $self.bump_pc::<$ty>(); e }}; } @@ -57,11 +57,11 @@ where unsafe { match self.memory.prog_read::(self.pc as _) { UN => { - self.bump_pc::(); + self.bump_pc::(); return Err(VmRunError::Unreachable); } TX => { - self.bump_pc::(); + self.bump_pc::(); return Ok(VmRunOk::End); } NOP => handler!(self, |OpsN()| ()), @@ -217,7 +217,7 @@ where // We are done, shift program counter core::task::Poll::Ready(Ok(())) => { self.copier = None; - self.bump_pc::(); + self.bump_pc::(); } // Error, shift program counter (for consistency) // and yield error @@ -270,7 +270,7 @@ where if self.read_reg(a0).cast::() != self.read_reg(a1).cast::() { self.pc = self.pcrel(ja, 3); } else { - self.bump_pc::(); + self.bump_pc::(); } } JLTS => self.cond_jmp::(Ordering::Less), @@ -283,11 +283,11 @@ where self.timer = self.timer.wrapping_add(1); } - self.bump_pc::(); + self.bump_pc::(); return Ok(VmRunOk::Ecall); } EBP => { - self.bump_pc::(); + self.bump_pc::(); return Ok(VmRunOk::Breakpoint); } FADD32 => self.binary_op::(ops::Add::add), @@ -373,10 +373,8 @@ where /// Bump instruction pointer #[inline(always)] - fn bump_pc(&mut self) { - self.pc = self - .pc - .wrapping_add(core::mem::size_of::() + PAST_OP as usize); + fn bump_pc(&mut self) { + self.pc = self.pc.wrapping_add(core::mem::size_of::()); } /// Decode instruction operands @@ -442,17 +440,19 @@ where tg, op(self.read_reg(a0).cast::(), self.read_reg(a1).cast::()), ); - self.bump_pc::(); + self.bump_pc::(); } /// Perform binary operation over register and immediate #[inline(always)] unsafe fn binary_op_imm(&mut self, op: impl Fn(T, T) -> T) { - let OpsRR(tg, reg) = self.decode(); - let imm: T = self.decode(); + #[derive(Clone, Copy)] + #[repr(packed)] + struct OpsRRImm(OpsRR, I); + + let OpsRRImm::(OpsRR(tg, reg), imm) = self.decode(); self.write_reg(tg, op(self.read_reg(reg).cast::(), imm)); - self.bump_pc::(); - self.bump_pc::(); + self.bump_pc::>(); } /// Perform binary operation over register and shift immediate @@ -466,7 +466,7 @@ where self.read_reg(a1).cast::(), ), ); - self.bump_pc::(); + self.bump_pc::(); } /// Perform binary operation over register and shift immediate @@ -474,7 +474,7 @@ where unsafe fn binary_op_ims(&mut self, op: impl Fn(T, u32) -> T) { let OpsRRB(tg, reg, imm) = self.decode(); self.write_reg(tg, op(self.read_reg(reg).cast::(), imm.into())); - self.bump_pc::(); + self.bump_pc::(); } /// Fused division-remainder @@ -540,7 +540,7 @@ where { self.pc = self.pcrel(ja, 3); } else { - self.bump_pc::(); + self.bump_pc::(); } }