-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Another approach that fixes #223, as an alternative to #238. This adds the `ToBitMask` trait, which is implemented on a vector for each bitmask type it supports. This includes all unsigned integers with enough bits to contain it. The byte array variant has been separated out for now into #246 and still requires `generic_const_exprs`, but the integer variants no longer require it and can make it to nightly.
- Loading branch information
Showing
5 changed files
with
115 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use super::{mask_impl, Mask, MaskElement}; | ||
use crate::simd::{LaneCount, SupportedLaneCount}; | ||
|
||
mod sealed { | ||
pub trait Sealed {} | ||
} | ||
pub use sealed::Sealed; | ||
|
||
impl<T, const LANES: usize> Sealed for Mask<T, LANES> | ||
where | ||
T: MaskElement, | ||
LaneCount<LANES>: SupportedLaneCount, | ||
{ | ||
} | ||
|
||
/// Converts masks to and from integer bitmasks. | ||
/// | ||
/// Each bit of the bitmask corresponds to a mask lane, starting with the LSB. | ||
/// | ||
/// # Safety | ||
/// This trait is `unsafe` and sealed, since the `BitMask` type must match the number of lanes in | ||
/// the mask. | ||
pub unsafe trait ToBitMask: Sealed { | ||
/// The integer bitmask type. | ||
type BitMask; | ||
|
||
/// Converts a mask to a bitmask. | ||
fn to_bitmask(self) -> Self::BitMask; | ||
|
||
/// Converts a bitmask to a mask. | ||
fn from_bitmask(bitmask: Self::BitMask) -> Self; | ||
} | ||
|
||
macro_rules! impl_integer_intrinsic { | ||
{ $(unsafe impl ToBitMask<BitMask=$int:ty> for Mask<_, $lanes:literal>)* } => { | ||
$( | ||
unsafe impl<T: MaskElement> ToBitMask for Mask<T, $lanes> { | ||
type BitMask = $int; | ||
|
||
fn to_bitmask(self) -> $int { | ||
self.0.to_bitmask_integer() | ||
} | ||
|
||
fn from_bitmask(bitmask: $int) -> Self { | ||
Self(mask_impl::Mask::from_bitmask_integer(bitmask)) | ||
} | ||
} | ||
)* | ||
} | ||
} | ||
|
||
impl_integer_intrinsic! { | ||
unsafe impl ToBitMask<BitMask=u8> for Mask<_, 8> | ||
unsafe impl ToBitMask<BitMask=u16> for Mask<_, 16> | ||
unsafe impl ToBitMask<BitMask=u32> for Mask<_, 32> | ||
unsafe impl ToBitMask<BitMask=u64> for Mask<_, 64> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters