1 | mod sealed { |
2 | pub trait Sealed {} |
3 | } |
4 | use sealed::Sealed; |
5 | |
6 | /// Specifies the number of lanes in a SIMD vector as a type. |
7 | pub struct LaneCount<const N: usize>; |
8 | |
9 | impl<const N: usize> LaneCount<N> { |
10 | /// The number of bytes in a bitmask with this many lanes. |
11 | pub const BITMASK_LEN: usize = (N + 7) / 8; |
12 | } |
13 | |
14 | /// Statically guarantees that a lane count is marked as supported. |
15 | /// |
16 | /// This trait is *sealed*: the list of implementors below is total. |
17 | /// Users do not have the ability to mark additional `LaneCount<N>` values as supported. |
18 | /// Only SIMD vectors with supported lane counts are constructable. |
19 | pub trait SupportedLaneCount: Sealed { |
20 | #[doc (hidden)] |
21 | type BitMask: Copy + Default + AsRef<[u8]> + AsMut<[u8]>; |
22 | } |
23 | |
24 | impl<const N: usize> Sealed for LaneCount<N> {} |
25 | |
26 | macro_rules! supported_lane_count { |
27 | ($($lanes:literal),+) => { |
28 | $( |
29 | impl SupportedLaneCount for LaneCount<$lanes> { |
30 | type BitMask = [u8; ($lanes + 7) / 8]; |
31 | } |
32 | )+ |
33 | }; |
34 | } |
35 | |
36 | supported_lane_count!(1, 2, 4, 8, 16, 32, 64); |
37 | #[cfg (feature = "all_lane_counts" )] |
38 | supported_lane_count!( |
39 | 3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, |
40 | 31, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, |
41 | 56, 57, 58, 59, 60, 61, 62, 63 |
42 | ); |
43 | |