]> git.lizzy.rs Git - rust.git/blobdiff - crates/core_simd/src/masks.rs
Fix cargo features for nightly (#155)
[rust.git] / crates / core_simd / src / masks.rs
index b7bde44b384f9bf835809a921e775d680fea2930..ebd394cd0408af2895cc88493439219c925a491a 100644 (file)
@@ -59,21 +59,21 @@ fn eq(self, other: Self) -> bool { self == other }
 ///
 /// 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 {
@@ -81,9 +81,9 @@ 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.
@@ -115,7 +115,7 @@ pub fn splat(value: bool) -> Self {
     /// # 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))
     }
 
@@ -125,15 +125,15 @@ pub unsafe fn from_int_unchecked(value: Simd<Element, LANES>) -> Self {
     /// # 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()
     }
 
@@ -178,11 +178,13 @@ pub fn set(&mut self, lane: usize, value: bool) {
     }
 
     /// 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))
     }
@@ -201,9 +203,9 @@ pub fn all(self) -> bool {
 }
 
 // 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 {
@@ -211,19 +213,19 @@ pub fn all(self) -> bool {
     }
 }
 
-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]
@@ -232,9 +234,9 @@ fn default() -> Self {
     }
 }
 
-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]
@@ -243,9 +245,9 @@ fn eq(&self, other: &Self) -> bool {
     }
 }
 
-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]
@@ -254,9 +256,9 @@ fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
     }
 }
 
-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 {
@@ -266,9 +268,9 @@ 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;
@@ -278,9 +280,9 @@ fn bitand(self, rhs: Self) -> 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;
@@ -290,21 +292,21 @@ fn bitand(self, rhs: bool) -> 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;
@@ -314,9 +316,9 @@ fn bitor(self, rhs: Self) -> 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;
@@ -326,21 +328,21 @@ fn bitor(self, rhs: bool) -> 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;
@@ -350,9 +352,9 @@ fn bitxor(self, rhs: Self) -> Self::Output {
     }
 }
 
-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;
@@ -362,33 +364,33 @@ fn bitxor(self, rhs: bool) -> Self::Output {
     }
 }
 
-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]
@@ -397,9 +399,9 @@ fn bitand_assign(&mut self, rhs: Self) {
     }
 }
 
-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]
@@ -408,9 +410,9 @@ fn bitand_assign(&mut self, rhs: bool) {
     }
 }
 
-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]
@@ -419,9 +421,9 @@ fn bitor_assign(&mut self, rhs: Self) {
     }
 }
 
-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]
@@ -430,9 +432,9 @@ fn bitor_assign(&mut self, rhs: bool) {
     }
 }
 
-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]
@@ -441,9 +443,9 @@ fn bitxor_assign(&mut self, rhs: Self) {
     }
 }
 
-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]
@@ -452,74 +454,59 @@ fn bitxor_assign(&mut self, rhs: bool) {
     }
 }
 
-/// 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:ty  => $($to:ty),* } => {