]> git.lizzy.rs Git - rust.git/blob - library/portable-simd/crates/core_simd/src/lane_count.rs
Rollup merge of #99544 - dylni:expose-utf8lossy, r=Mark-Simulacrum
[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 /// Specifies the number of lanes in a SIMD vector as a type.
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 /// 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 LANES: usize> Sealed for LaneCount<LANES> {}
25
26 impl SupportedLaneCount for LaneCount<1> {
27     type BitMask = [u8; 1];
28 }
29 impl SupportedLaneCount for LaneCount<2> {
30     type BitMask = [u8; 1];
31 }
32 impl SupportedLaneCount for LaneCount<4> {
33     type BitMask = [u8; 1];
34 }
35 impl SupportedLaneCount for LaneCount<8> {
36     type BitMask = [u8; 1];
37 }
38 impl SupportedLaneCount for LaneCount<16> {
39     type BitMask = [u8; 2];
40 }
41 impl SupportedLaneCount for LaneCount<32> {
42     type BitMask = [u8; 4];
43 }
44 impl SupportedLaneCount for LaneCount<64> {
45     type BitMask = [u8; 8];
46 }