From 68a8f6625fe850ec8acca3473233c490e702a11d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 13 Jan 2025 10:15:46 -0800 Subject: [PATCH] Fix debug assertions on 32-bit --- pulley/src/interp.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/pulley/src/interp.rs b/pulley/src/interp.rs index 4e7a35bf6d89..af78735ed1cf 100644 --- a/pulley/src/interp.rs +++ b/pulley/src/interp.rs @@ -973,6 +973,14 @@ impl Interpreter<'_> { self.state[XReg::sp].set_ptr(sp); } + /// Calculates the "g32" address given the inputs to the addressing mode. + fn g32_addr(&self, base: XReg, addr: XReg, offset: u8) -> *mut T { + let addr = self.state[base].get_ptr::() as usize + + self.state[addr].get_u32() as usize + + usize::from(offset); + addr as *mut T + } + unsafe fn load(&self, ptr: XReg, offset: i32) -> T { unsafe { self.state[ptr] @@ -986,13 +994,7 @@ impl Interpreter<'_> { /// always a 32-bit value. Arithmetic is done at the size of the /// host-pointer-width. unsafe fn load_g32(&self, base: XReg, addr: XReg, offset: u8) -> T { - unsafe { - self.state[base] - .get_ptr::() - .byte_offset(self.state[addr].get_u32() as usize as isize) - .byte_offset(offset.into()) - .read_unaligned() - } + unsafe { self.g32_addr::(base, addr, offset).read_unaligned() } } unsafe fn store(&self, ptr: XReg, offset: i32, val: T) { @@ -1005,11 +1007,7 @@ impl Interpreter<'_> { /// Same as `load_g32` but for stores unsafe fn store_g32(&self, base: XReg, addr: XReg, offset: u8, val: T) { unsafe { - self.state[base] - .get_ptr::() - .byte_offset(self.state[addr].get_u32() as usize as isize) - .byte_offset(offset.into()) - .write_unaligned(val) + self.g32_addr::(base, addr, offset).write_unaligned(val); } }