hpt_common/utils/
simd_ref.rs

1use std::marker::PhantomData;
2
3use crate::utils::pointer::Pointer;
4
5/// A struct contains a mutable simd vector, this struct force the user to use write unaligned and read unaligned when they use simd iterator
6#[derive(Debug)]
7pub struct MutVec<'a, T> {
8    ptr: Pointer<T>,
9    _phantom: PhantomData<&'a mut T>,
10}
11
12impl<'a, T> MutVec<'a, T> {
13    /// create a new MutVec
14    #[inline(always)]
15    pub fn new(ptr: Pointer<T>) -> Self {
16        Self {
17            ptr,
18            _phantom: PhantomData,
19        }
20    }
21
22    /// perform write unaligned operation
23    #[inline(always)]
24    pub fn write_unaligned(&self, value: T) {
25        unsafe {
26            self.ptr.ptr.write_unaligned(value);
27        }
28    }
29
30    #[inline(always)]
31    /// perform read unaligned operation
32    pub fn read_unaligned(&self) -> T {
33        unsafe { self.ptr.ptr.read_unaligned() }
34    }
35}