///
/// The layout of this type is unspecified.
#[repr(transparent)]
-pub struct Mask<Element, const LANES: usize>(mask_impl::Mask<Element, LANES>)
+pub struct Mask<T, const LANES: usize>(mask_impl::Mask<T, LANES>)
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount;
-impl<Element, const LANES: usize> Copy for Mask<Element, LANES>
+impl<T, const LANES: usize> Copy for Mask<T, LANES>
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
}
-impl<Element, const LANES: usize> Clone for Mask<Element, LANES>
+impl<T, const LANES: usize> Clone for Mask<T, LANES>
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
fn clone(&self) -> Self {
}
}
-impl<Element, const LANES: usize> Mask<Element, LANES>
+impl<T, const LANES: usize> Mask<T, LANES>
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
/// Construct a mask by setting all lanes to the given value.
/// # Safety
/// All lanes must be either 0 or -1.
#[inline]
- pub unsafe fn from_int_unchecked(value: Simd<Element, LANES>) -> Self {
+ pub unsafe fn from_int_unchecked(value: Simd<T, LANES>) -> Self {
Self(mask_impl::Mask::from_int_unchecked(value))
}
/// # Panics
/// Panics if any lane is not 0 or -1.
#[inline]
- pub fn from_int(value: Simd<Element, LANES>) -> Self {
- assert!(Element::valid(value), "all values must be either 0 or -1",);
+ pub fn from_int(value: Simd<T, LANES>) -> Self {
+ assert!(T::valid(value), "all values must be either 0 or -1",);
unsafe { Self::from_int_unchecked(value) }
}
/// Converts the mask to a vector of integers, where 0 represents `false` and -1
/// represents `true`.
#[inline]
- pub fn to_int(self) -> Simd<Element, LANES> {
+ pub fn to_int(self) -> Simd<T, LANES> {
self.0.to_int()
}
}
/// Convert this mask to a bitmask, with one bit set per lane.
+ #[cfg(feature = "generic_const_exprs")]
pub fn to_bitmask(self) -> [u8; LaneCount::<LANES>::BITMASK_LEN] {
self.0.to_bitmask()
}
/// Convert a bitmask to a mask.
+ #[cfg(feature = "generic_const_exprs")]
pub fn from_bitmask(bitmask: [u8; LaneCount::<LANES>::BITMASK_LEN]) -> Self {
Self(mask_impl::Mask::from_bitmask(bitmask))
}
}
// vector/array conversion
-impl<Element, const LANES: usize> From<[bool; LANES]> for Mask<Element, LANES>
+impl<T, const LANES: usize> From<[bool; LANES]> for Mask<T, LANES>
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
fn from(array: [bool; LANES]) -> Self {
}
}
-impl<Element, const LANES: usize> From<Mask<Element, LANES>> for [bool; LANES]
+impl<T, const LANES: usize> From<Mask<T, LANES>> for [bool; LANES]
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
- fn from(vector: Mask<Element, LANES>) -> Self {
+ fn from(vector: Mask<T, LANES>) -> Self {
vector.to_array()
}
}
-impl<Element, const LANES: usize> Default for Mask<Element, LANES>
+impl<T, const LANES: usize> Default for Mask<T, LANES>
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
#[inline]
}
}
-impl<Element, const LANES: usize> PartialEq for Mask<Element, LANES>
+impl<T, const LANES: usize> PartialEq for Mask<T, LANES>
where
- Element: MaskElement + PartialEq,
+ T: MaskElement + PartialEq,
LaneCount<LANES>: SupportedLaneCount,
{
#[inline]
}
}
-impl<Element, const LANES: usize> PartialOrd for Mask<Element, LANES>
+impl<T, const LANES: usize> PartialOrd for Mask<T, LANES>
where
- Element: MaskElement + PartialOrd,
+ T: MaskElement + PartialOrd,
LaneCount<LANES>: SupportedLaneCount,
{
#[inline]
}
}
-impl<Element, const LANES: usize> core::fmt::Debug for Mask<Element, LANES>
+impl<T, const LANES: usize> core::fmt::Debug for Mask<T, LANES>
where
- Element: MaskElement + core::fmt::Debug,
+ T: MaskElement + core::fmt::Debug,
LaneCount<LANES>: SupportedLaneCount,
{
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
}
}
-impl<Element, const LANES: usize> core::ops::BitAnd for Mask<Element, LANES>
+impl<T, const LANES: usize> core::ops::BitAnd for Mask<T, LANES>
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Self;
}
}
-impl<Element, const LANES: usize> core::ops::BitAnd<bool> for Mask<Element, LANES>
+impl<T, const LANES: usize> core::ops::BitAnd<bool> for Mask<T, LANES>
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Self;
}
}
-impl<Element, const LANES: usize> core::ops::BitAnd<Mask<Element, LANES>> for bool
+impl<T, const LANES: usize> core::ops::BitAnd<Mask<T, LANES>> for bool
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
- type Output = Mask<Element, LANES>;
+ type Output = Mask<T, LANES>;
#[inline]
- fn bitand(self, rhs: Mask<Element, LANES>) -> Mask<Element, LANES> {
+ fn bitand(self, rhs: Mask<T, LANES>) -> Mask<T, LANES> {
Mask::splat(self) & rhs
}
}
-impl<Element, const LANES: usize> core::ops::BitOr for Mask<Element, LANES>
+impl<T, const LANES: usize> core::ops::BitOr for Mask<T, LANES>
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Self;
}
}
-impl<Element, const LANES: usize> core::ops::BitOr<bool> for Mask<Element, LANES>
+impl<T, const LANES: usize> core::ops::BitOr<bool> for Mask<T, LANES>
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Self;
}
}
-impl<Element, const LANES: usize> core::ops::BitOr<Mask<Element, LANES>> for bool
+impl<T, const LANES: usize> core::ops::BitOr<Mask<T, LANES>> for bool
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
- type Output = Mask<Element, LANES>;
+ type Output = Mask<T, LANES>;
#[inline]
- fn bitor(self, rhs: Mask<Element, LANES>) -> Mask<Element, LANES> {
+ fn bitor(self, rhs: Mask<T, LANES>) -> Mask<T, LANES> {
Mask::splat(self) | rhs
}
}
-impl<Element, const LANES: usize> core::ops::BitXor for Mask<Element, LANES>
+impl<T, const LANES: usize> core::ops::BitXor for Mask<T, LANES>
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Self;
}
}
-impl<Element, const LANES: usize> core::ops::BitXor<bool> for Mask<Element, LANES>
+impl<T, const LANES: usize> core::ops::BitXor<bool> for Mask<T, LANES>
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Self;
}
}
-impl<Element, const LANES: usize> core::ops::BitXor<Mask<Element, LANES>> for bool
+impl<T, const LANES: usize> core::ops::BitXor<Mask<T, LANES>> for bool
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
- type Output = Mask<Element, LANES>;
+ type Output = Mask<T, LANES>;
#[inline]
- fn bitxor(self, rhs: Mask<Element, LANES>) -> Self::Output {
+ fn bitxor(self, rhs: Mask<T, LANES>) -> Self::Output {
Mask::splat(self) ^ rhs
}
}
-impl<Element, const LANES: usize> core::ops::Not for Mask<Element, LANES>
+impl<T, const LANES: usize> core::ops::Not for Mask<T, LANES>
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
- type Output = Mask<Element, LANES>;
+ type Output = Mask<T, LANES>;
#[inline]
fn not(self) -> Self::Output {
Self(!self.0)
}
}
-impl<Element, const LANES: usize> core::ops::BitAndAssign for Mask<Element, LANES>
+impl<T, const LANES: usize> core::ops::BitAndAssign for Mask<T, LANES>
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
#[inline]
}
}
-impl<Element, const LANES: usize> core::ops::BitAndAssign<bool> for Mask<Element, LANES>
+impl<T, const LANES: usize> core::ops::BitAndAssign<bool> for Mask<T, LANES>
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
#[inline]
}
}
-impl<Element, const LANES: usize> core::ops::BitOrAssign for Mask<Element, LANES>
+impl<T, const LANES: usize> core::ops::BitOrAssign for Mask<T, LANES>
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
#[inline]
}
}
-impl<Element, const LANES: usize> core::ops::BitOrAssign<bool> for Mask<Element, LANES>
+impl<T, const LANES: usize> core::ops::BitOrAssign<bool> for Mask<T, LANES>
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
#[inline]
}
}
-impl<Element, const LANES: usize> core::ops::BitXorAssign for Mask<Element, LANES>
+impl<T, const LANES: usize> core::ops::BitXorAssign for Mask<T, LANES>
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
#[inline]
}
}
-impl<Element, const LANES: usize> core::ops::BitXorAssign<bool> for Mask<Element, LANES>
+impl<T, const LANES: usize> core::ops::BitXorAssign<bool> for Mask<T, LANES>
where
- Element: MaskElement,
+ T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
#[inline]
}
}
-/// A SIMD mask of `LANES` 8-bit values.
-pub type Mask8<const LANES: usize> = Mask<i8, LANES>;
-
-/// A SIMD mask of `LANES` 16-bit values.
-pub type Mask16<const LANES: usize> = Mask<i16, LANES>;
-
-/// A SIMD mask of `LANES` 32-bit values.
-pub type Mask32<const LANES: usize> = Mask<i32, LANES>;
-
-/// A SIMD mask of `LANES` 64-bit values.
-pub type Mask64<const LANES: usize> = Mask<i64, LANES>;
-
-/// A SIMD mask of `LANES` pointer-width values.
-pub type MaskSize<const LANES: usize> = Mask<isize, LANES>;
-
/// Vector of eight 8-bit masks
-pub type mask8x8 = Mask8<8>;
+pub type mask8x8 = Mask<i8, 8>;
/// Vector of 16 8-bit masks
-pub type mask8x16 = Mask8<16>;
+pub type mask8x16 = Mask<i8, 16>;
/// Vector of 32 8-bit masks
-pub type mask8x32 = Mask8<32>;
+pub type mask8x32 = Mask<i8, 32>;
/// Vector of 16 8-bit masks
-pub type mask8x64 = Mask8<64>;
+pub type mask8x64 = Mask<i8, 64>;
/// Vector of four 16-bit masks
-pub type mask16x4 = Mask16<4>;
+pub type mask16x4 = Mask<i16, 4>;
/// Vector of eight 16-bit masks
-pub type mask16x8 = Mask16<8>;
+pub type mask16x8 = Mask<i16, 8>;
/// Vector of 16 16-bit masks
-pub type mask16x16 = Mask16<16>;
+pub type mask16x16 = Mask<i16, 16>;
/// Vector of 32 16-bit masks
-pub type mask16x32 = Mask32<32>;
+pub type mask16x32 = Mask<i32, 32>;
/// Vector of two 32-bit masks
-pub type mask32x2 = Mask32<2>;
+pub type mask32x2 = Mask<i32, 2>;
/// Vector of four 32-bit masks
-pub type mask32x4 = Mask32<4>;
+pub type mask32x4 = Mask<i32, 4>;
/// Vector of eight 32-bit masks
-pub type mask32x8 = Mask32<8>;
+pub type mask32x8 = Mask<i32, 8>;
/// Vector of 16 32-bit masks
-pub type mask32x16 = Mask32<16>;
+pub type mask32x16 = Mask<i32, 16>;
/// Vector of two 64-bit masks
-pub type mask64x2 = Mask64<2>;
+pub type mask64x2 = Mask<i64, 2>;
/// Vector of four 64-bit masks
-pub type mask64x4 = Mask64<4>;
+pub type mask64x4 = Mask<i64, 4>;
/// Vector of eight 64-bit masks
-pub type mask64x8 = Mask64<8>;
+pub type mask64x8 = Mask<i64, 8>;
/// Vector of two pointer-width masks
-pub type masksizex2 = MaskSize<2>;
+pub type masksizex2 = Mask<isize, 2>;
/// Vector of four pointer-width masks
-pub type masksizex4 = MaskSize<4>;
+pub type masksizex4 = Mask<isize, 4>;
/// Vector of eight pointer-width masks
-pub type masksizex8 = MaskSize<8>;
+pub type masksizex8 = Mask<isize, 8>;
macro_rules! impl_from {
- { $from:ident ($from_inner:ident) => $($to:ident ($to_inner:ident)),* } => {
+ { $from:ty => $($to:ty),* } => {
$(
- impl<const LANES: usize> From<$from<LANES>> for $to<LANES>
+ impl<const LANES: usize> From<Mask<$from, LANES>> for Mask<$to, LANES>
where
- crate::LaneCount<LANES>: crate::SupportedLaneCount,
+ LaneCount<LANES>: SupportedLaneCount,
{
- fn from(value: $from<LANES>) -> Self {
+ fn from(value: Mask<$from, LANES>) -> Self {
Self(value.0.convert())
}
}
)*
}
}
-impl_from! { Mask8 (SimdI8) => Mask16 (SimdI16), Mask32 (SimdI32), Mask64 (SimdI64), MaskSize (SimdIsize) }
-impl_from! { Mask16 (SimdI16) => Mask32 (SimdI32), Mask64 (SimdI64), MaskSize (SimdIsize), Mask8 (SimdI8) }
-impl_from! { Mask32 (SimdI32) => Mask64 (SimdI64), MaskSize (SimdIsize), Mask8 (SimdI8), Mask16 (SimdI16) }
-impl_from! { Mask64 (SimdI64) => MaskSize (SimdIsize), Mask8 (SimdI8), Mask16 (SimdI16), Mask32 (SimdI32) }
-impl_from! { MaskSize (SimdIsize) => Mask8 (SimdI8), Mask16 (SimdI16), Mask32 (SimdI32), Mask64 (SimdI64) }
+impl_from! { i8 => i16, i32, i64, isize }
+impl_from! { i16 => i32, i64, isize, i8 }
+impl_from! { i32 => i64, isize, i8, i16 }
+impl_from! { i64 => isize, i8, i16, i32 }
+impl_from! { isize => i8, i16, i32, i64 }