]> git.lizzy.rs Git - rust.git/blob - library/portable-simd/crates/core_simd/src/vector/ptr.rs
Auto merge of #107843 - bjorn3:sync_cg_clif-2023-02-09, r=bjorn3
[rust.git] / library / portable-simd / crates / core_simd / src / vector / ptr.rs
1 //! Private implementation details of public gather/scatter APIs.
2 use crate::simd::intrinsics;
3 use crate::simd::{LaneCount, Simd, SupportedLaneCount};
4
5 /// A vector of *const T.
6 #[derive(Debug, Copy, Clone)]
7 #[repr(simd)]
8 pub(crate) struct SimdConstPtr<T, const LANES: usize>([*const T; LANES]);
9
10 impl<T, const LANES: usize> SimdConstPtr<T, LANES>
11 where
12     LaneCount<LANES>: SupportedLaneCount,
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: Simd<usize, LANES>) -> Self {
24         // Safety: this intrinsic doesn't have a precondition
25         unsafe { intrinsics::simd_arith_offset(self, addend) }
26     }
27 }
28
29 /// A vector of *mut T. Be very careful around potential aliasing.
30 #[derive(Debug, Copy, Clone)]
31 #[repr(simd)]
32 pub(crate) struct SimdMutPtr<T, const LANES: usize>([*mut T; LANES]);
33
34 impl<T, const LANES: usize> SimdMutPtr<T, LANES>
35 where
36     LaneCount<LANES>: SupportedLaneCount,
37     T: Sized,
38 {
39     #[inline]
40     #[must_use]
41     pub fn splat(ptr: *mut T) -> Self {
42         Self([ptr; LANES])
43     }
44
45     #[inline]
46     #[must_use]
47     pub fn wrapping_add(self, addend: Simd<usize, LANES>) -> Self {
48         // Safety: this intrinsic doesn't have a precondition
49         unsafe { intrinsics::simd_arith_offset(self, addend) }
50     }
51 }