Add pointer vectors: SimdConstPtr, SimdMutPtr
This commit is contained in:
parent
16765a1021
commit
2f99cc80d8
@ -5,3 +5,6 @@ mod uint;
|
||||
pub use float::*;
|
||||
pub use int::*;
|
||||
pub use uint::*;
|
||||
|
||||
// Vectors of pointers are not for public use at the current time.
|
||||
pub(crate) mod ptr;
|
||||
|
55
crates/core_simd/src/vector/ptr.rs
Normal file
55
crates/core_simd/src/vector/ptr.rs
Normal file
@ -0,0 +1,55 @@
|
||||
//! Private implementation details of public gather/scatter APIs.
|
||||
use crate::SimdUsize;
|
||||
use core::mem;
|
||||
|
||||
/// A vector of *const T.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
#[repr(simd)]
|
||||
pub(crate) struct SimdConstPtr<T, const LANES: usize>([*const T; LANES]);
|
||||
|
||||
impl<T, const LANES: usize> SimdConstPtr<T, LANES>
|
||||
where
|
||||
SimdUsize<LANES>: crate::LanesAtMost32,
|
||||
T: Sized,
|
||||
{
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn splat(ptr: *const T) -> Self {
|
||||
Self([ptr; LANES])
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn wrapping_add(self, addend: SimdUsize<LANES>) -> Self {
|
||||
unsafe {
|
||||
let x: SimdUsize<LANES> = mem::transmute_copy(&self);
|
||||
mem::transmute_copy(&{ x + (addend * mem::size_of::<T>()) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A vector of *mut T. Be very careful around potential aliasing.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
#[repr(simd)]
|
||||
pub(crate) struct SimdMutPtr<T, const LANES: usize>([*mut T; LANES]);
|
||||
|
||||
impl<T, const LANES: usize> SimdMutPtr<T, LANES>
|
||||
where
|
||||
SimdUsize<LANES>: crate::LanesAtMost32,
|
||||
T: Sized,
|
||||
{
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn splat(ptr: *mut T) -> Self {
|
||||
Self([ptr; LANES])
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn wrapping_add(self, addend: SimdUsize<LANES>) -> Self {
|
||||
unsafe {
|
||||
let x: SimdUsize<LANES> = mem::transmute_copy(&self);
|
||||
mem::transmute_copy(&{ x + (addend * mem::size_of::<T>()) })
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user