From 7658b9dde8b48bcc61561e34f20b205fea1f85bd Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Fri, 18 Oct 2024 15:30:57 +0200 Subject: [PATCH] regs: add convenience setter methods for `a` registers --- src/reg/core_regs.rs | 72 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/src/reg/core_regs.rs b/src/reg/core_regs.rs index 0887ee6..cb8086a 100644 --- a/src/reg/core_regs.rs +++ b/src/reg/core_regs.rs @@ -222,6 +222,78 @@ impl CoreRegs { /// Get value from `a128` register. pub fn a128(&self, idx: impl Into) -> Option { self.a128[idx.into().to_usize()] } + /// Sets `a8` register to a given value. Returns previous register value. + pub fn set_a8(&mut self, idx: impl Into, val: u8) -> Option { + let idx = idx.into().to_usize(); + let prev = self.a8[idx]; + self.a8[idx] = Some(val); + prev + } + /// Sets `a16` register to a given value. Returns previous register value. + pub fn set_a16(&mut self, idx: impl Into, val: u16) -> Option { + let idx = idx.into().to_usize(); + let prev = self.a16[idx]; + self.a16[idx] = Some(val); + prev + } + /// Sets `a32` register to a given value. Returns previous register value. + pub fn set_a32(&mut self, idx: impl Into, val: u32) -> Option { + let idx = idx.into().to_usize(); + let prev = self.a32[idx]; + self.a32[idx] = Some(val); + prev + } + /// Sets `a64` register to a given value. Returns previous register value. + pub fn set_a64(&mut self, idx: impl Into, val: u64) -> Option { + let idx = idx.into().to_usize(); + let prev = self.a64[idx]; + self.a64[idx] = Some(val); + prev + } + /// Sets `a128` register to a given value. Returns previous register value. + pub fn set_a128(&mut self, idx: impl Into, val: u128) -> Option { + let idx = idx.into().to_usize(); + let prev = self.a128[idx]; + self.a128[idx] = Some(val); + prev + } + + /// Clears `a8` register (sets its value to `None`). Returns previous register value. + pub fn clr_a8(&mut self, idx: impl Into) -> Option { + let idx = idx.into().to_usize(); + let prev = self.a8[idx]; + self.a8[idx] = None; + prev + } + /// Clears `a16` register (sets its value to `None`). Returns previous register value. + pub fn clr_a16(&mut self, idx: impl Into) -> Option { + let idx = idx.into().to_usize(); + let prev = self.a16[idx]; + self.a16[idx] = None; + prev + } + /// Clears `a32` register (sets its value to `None`). Returns previous register value. + pub fn clr_a32(&mut self, idx: impl Into) -> Option { + let idx = idx.into().to_usize(); + let prev = self.a32[idx]; + self.a32[idx] = None; + prev + } + /// Clears `a64` register (sets its value to `None`). Returns previous register value. + pub fn clr_a64(&mut self, idx: impl Into) -> Option { + let idx = idx.into().to_usize(); + let prev = self.a64[idx]; + self.a64[idx] = None; + prev + } + /// Clears `a128` register (sets its value to `None`). Returns previous register value. + pub fn clr_a128(&mut self, idx: impl Into) -> Option { + let idx = idx.into().to_usize(); + let prev = self.a128[idx]; + self.a128[idx] = None; + prev + } + /// Extracts value for any type of registers pub fn get(&self, reg: impl Into) -> RegValue { match reg.into() {