]> git.lizzy.rs Git - rust.git/blob - library/portable-simd/crates/core_simd/src/vector/ptr.rs
Auto merge of #89167 - workingjubilee:use-simd, r=MarkSimulacrum
[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::{LaneCount, Simd, SupportedLaneCount};
3 use core::mem;
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         unsafe {
25             let x: Simd<usize, 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 SimdMutPtr<T, const LANES: usize>([*mut T; LANES]);
35
36 impl<T, const LANES: usize> SimdMutPtr<T, LANES>
37 where
38     LaneCount<LANES>: SupportedLaneCount,
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: Simd<usize, LANES>) -> Self {
50         unsafe {
51             let x: Simd<usize, LANES> = mem::transmute_copy(&self);
52             mem::transmute_copy(&{ x + (addend * mem::size_of::<T>()) })
53         }
54     }
55 }