lane_count.rs - source
Description: Source of the Rust file `library/core/src/../../portable-simd/crates/core_simd/src/lane_count.rs`.

#
core/portable-simd/crates/core_simd/src/
lane_count.rs

    1mod sealed {
    2    pub trait Sealed {}
    3}
    4use sealed::Sealed;
    5
    6/// Specifies the number of lanes in a SIMD vector as a type.
    7pub struct LaneCount<const N: usize>;
    8
    9impl<const N: usize> LaneCount<N> {
    10    /// The number of bytes in a bitmask with this many lanes.
    11    pub const BITMASK_LEN: usize = N.div_ceil(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.
    19pub trait SupportedLaneCount: Sealed {
    20    #[doc(hidden)]
    21    type BitMask: Copy + Default + AsRef<[u8]> + AsMut<[u8]>;
    22}
    23
    24impl<const N: usize> Sealed for LaneCount<N> {}
    25
    26macro_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
    36supported_lane_count!(
    37    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
    38    27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
    39    51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64
    40);