]> git.lizzy.rs Git - rust.git/blob - library/portable-simd/crates/core_simd/src/lane_count.rs
Rollup merge of #90834 - cuviper:android-gnu, r=petrochenkov
[rust.git] / library / portable-simd / crates / core_simd / src / lane_count.rs
1 mod sealed {
2     pub trait Sealed {}
3 }
4 use sealed::Sealed;
5
6 /// A type representing a vector lane count.
7 pub struct LaneCount<const LANES: usize>;
8
9 impl<const LANES: usize> LaneCount<LANES> {
10     /// The number of bytes in a bitmask with this many lanes.
11     pub const BITMASK_LEN: usize = (LANES + 7) / 8;
12 }
13
14 /// Helper trait for vector lane counts.
15 pub trait SupportedLaneCount: Sealed {
16     #[doc(hidden)]
17     type BitMask: Copy + Default + AsRef<[u8]> + AsMut<[u8]>;
18
19     #[doc(hidden)]
20     type IntBitMask;
21 }
22
23 impl<const LANES: usize> Sealed for LaneCount<LANES> {}
24
25 impl SupportedLaneCount for LaneCount<1> {
26     type BitMask = [u8; 1];
27     type IntBitMask = u8;
28 }
29 impl SupportedLaneCount for LaneCount<2> {
30     type BitMask = [u8; 1];
31     type IntBitMask = u8;
32 }
33 impl SupportedLaneCount for LaneCount<4> {
34     type BitMask = [u8; 1];
35     type IntBitMask = u8;
36 }
37 impl SupportedLaneCount for LaneCount<8> {
38     type BitMask = [u8; 1];
39     type IntBitMask = u8;
40 }
41 impl SupportedLaneCount for LaneCount<16> {
42     type BitMask = [u8; 2];
43     type IntBitMask = u16;
44 }
45 impl SupportedLaneCount for LaneCount<32> {
46     type BitMask = [u8; 4];
47     type IntBitMask = u32;
48 }