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