diff --git a/crates/core_simd/src/vector.rs b/crates/core_simd/src/vector.rs index 95534384b70..95214ea8864 100644 --- a/crates/core_simd/src/vector.rs +++ b/crates/core_simd/src/vector.rs @@ -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; diff --git a/crates/core_simd/src/vector/ptr.rs b/crates/core_simd/src/vector/ptr.rs new file mode 100644 index 00000000000..30bef038b33 --- /dev/null +++ b/crates/core_simd/src/vector/ptr.rs @@ -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([*const T; LANES]); + +impl SimdConstPtr +where + SimdUsize: 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) -> Self { + unsafe { + let x: SimdUsize = mem::transmute_copy(&self); + mem::transmute_copy(&{ x + (addend * mem::size_of::()) }) + } + } +} + +/// A vector of *mut T. Be very careful around potential aliasing. +#[derive(Debug, Copy, Clone)] +#[repr(simd)] +pub(crate) struct SimdMutPtr([*mut T; LANES]); + +impl SimdMutPtr +where + SimdUsize: 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) -> Self { + unsafe { + let x: SimdUsize = mem::transmute_copy(&self); + mem::transmute_copy(&{ x + (addend * mem::size_of::()) }) + } + } +}