Skip to content

Commit 048b547

Browse files
Add pointer vectors: SimdConst, SimdMut
1 parent 8ae0818 commit 048b547

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

crates/core_simd/src/vector.rs

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ mod uint;
55
pub use float::*;
66
pub use int::*;
77
pub use uint::*;
8+
9+
// Vectors of pointers are not for public use at the current time.
10+
pub(crate) mod ptr;

crates/core_simd/src/vector/ptr.rs

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//! Private implementation details of public gather/scatter APIs.
2+
use crate::SimdUsize;
3+
use core::mem;
4+
5+
/// A vector of *const T.
6+
#[derive(Debug, Copy, Clone)]
7+
#[repr(simd)]
8+
pub(crate) struct SimdConst<T, const LANES: usize>([*const T; LANES]);
9+
10+
impl<T, const LANES: usize> SimdConst<T, LANES>
11+
where
12+
SimdUsize<LANES>: crate::LanesAtMost32,
13+
T: Sized,
14+
{
15+
#[inline]
16+
#[must_use]
17+
pub fn splat(ptr: *const T) -> Self {
18+
Self([ptr; LANES])
19+
}
20+
21+
#[inline]
22+
#[must_use]
23+
pub fn wrapping_add(self, addend: SimdUsize<LANES>) -> Self {
24+
unsafe {
25+
let x: SimdUsize<LANES> = mem::transmute_copy(&self);
26+
mem::transmute_copy(&{ x + (addend * mem::size_of::<T>()) })
27+
}
28+
}
29+
}
30+
31+
/// A vector of *mut T. Be very careful around potential aliasing.
32+
#[derive(Debug, Copy, Clone)]
33+
#[repr(simd)]
34+
pub(crate) struct SimdMut<T, const LANES: usize>([*mut T; LANES]);
35+
36+
impl<T, const LANES: usize> SimdMut<T, LANES>
37+
where
38+
SimdUsize<LANES>: crate::LanesAtMost32,
39+
T: Sized,
40+
{
41+
#[inline]
42+
#[must_use]
43+
pub fn splat(ptr: *mut T) -> Self {
44+
Self([ptr; LANES])
45+
}
46+
47+
#[inline]
48+
#[must_use]
49+
pub fn wrapping_add(self, addend: SimdUsize<LANES>) -> Self {
50+
unsafe {
51+
let x: SimdUsize<LANES> = mem::transmute_copy(&self);
52+
mem::transmute_copy(&{ x + (addend * mem::size_of::<T>()) })
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)