1 use super::{mask_impl, Mask, MaskElement};
3 /// Converts masks to and from integer bitmasks.
5 /// Each bit of the bitmask corresponds to a mask lane, starting with the LSB.
7 /// The integer bitmask type.
10 /// Converts a mask to a bitmask.
11 fn to_bitmask(self) -> Self::BitMask;
13 /// Converts a bitmask to a mask.
14 fn from_bitmask(bitmask: Self::BitMask) -> Self;
17 /// Converts masks to and from byte array bitmasks.
19 /// Each bit of the bitmask corresponds to a mask lane, starting with the LSB of the first byte.
20 pub trait ToBitMaskArray {
21 /// The length of the bitmask array.
24 /// Converts a mask to a bitmask.
25 fn to_bitmask_array(self) -> [u8; Self::BYTES];
27 /// Converts a bitmask to a mask.
28 fn from_bitmask_array(bitmask: [u8; Self::BYTES]) -> Self;
31 macro_rules! impl_integer_intrinsic {
32 { $(unsafe impl ToBitMask<BitMask=$int:ty> for Mask<_, $lanes:literal>)* } => {
34 impl<T: MaskElement> ToBitMask for Mask<T, $lanes> {
37 fn to_bitmask(self) -> $int {
38 unsafe { self.0.to_bitmask_integer() }
41 fn from_bitmask(bitmask: $int) -> Self {
42 unsafe { Self(mask_impl::Mask::from_bitmask_integer(bitmask)) }
49 impl_integer_intrinsic! {
50 unsafe impl ToBitMask<BitMask=u8> for Mask<_, 8>
51 unsafe impl ToBitMask<BitMask=u16> for Mask<_, 16>
52 unsafe impl ToBitMask<BitMask=u32> for Mask<_, 32>
53 unsafe impl ToBitMask<BitMask=u64> for Mask<_, 64>