1
0
Fork 0
forked from koniifer/ableos

Fixed smaller units

This commit is contained in:
Erin 2023-10-29 20:38:57 +01:00
parent d6243fa99f
commit 57f30109c8
2 changed files with 10 additions and 2 deletions

View file

@ -45,6 +45,8 @@ impl Value {
/// # Safety /// # Safety
/// - N/A, not to be implemented manually /// - N/A, not to be implemented manually
pub unsafe trait ValueVariant: private::Sealed + Copy + Into<Value> {} pub unsafe trait ValueVariant: private::Sealed + Copy + Into<Value> {}
impl private::Sealed for Value {}
unsafe impl ValueVariant for Value {}
mod private { mod private {
pub trait Sealed {} pub trait Sealed {}

View file

@ -543,9 +543,15 @@ where
/// Write a register. /// Write a register.
/// Writing to register 0 is no-op. /// Writing to register 0 is no-op.
#[inline(always)] #[inline(always)]
fn write_reg(&mut self, n: u8, value: impl Into<Value>) { fn write_reg<T: ValueVariant>(&mut self, n: u8, value: T) {
if n != 0 { if n != 0 {
unsafe { *self.registers.get_unchecked_mut(n as usize) = value.into() }; unsafe {
core::ptr::copy_nonoverlapping(
(&value as *const T).cast::<u8>(),
self.registers.as_mut_ptr().add(n.into()).cast::<u8>(),
core::mem::size_of::<T>(),
);
};
} }
} }