]> git.lizzy.rs Git - rust.git/blobdiff - crates/core_simd/src/masks/full_masks.rs
Limit all types to 64 lanes
[rust.git] / crates / core_simd / src / masks / full_masks.rs
index d7c4af47727caa92b0c5faed174b5105687e3536..fa93d252df464cbfbfb2cca8730dd9024903dc60 100644 (file)
@@ -16,11 +16,31 @@ fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
 macro_rules! define_mask {
     { $(#[$attr:meta])* struct $name:ident<const $lanes:ident: usize>($type:ty); } => {
         $(#[$attr])*
-        #[derive(Copy, Clone, Default, PartialEq, PartialOrd, Eq, Ord, Hash)]
+        #[derive(Default, PartialEq, PartialOrd, Eq, Ord, Hash)]
         #[repr(transparent)]
-        pub struct $name<const $lanes: usize>($type);
+        pub struct $name<const $lanes: usize>($type)
+        where
+            $type: crate::LanesAtMost64;
+
+        impl<const LANES: usize> Copy for $name<LANES>
+        where
+            $type: crate::LanesAtMost64,
+        {}
 
-        impl<const $lanes: usize> $name<$lanes> {
+        impl<const LANES: usize> Clone for $name<LANES>
+        where
+            $type: crate::LanesAtMost64,
+        {
+            #[inline]
+            fn clone(&self) -> Self {
+                *self
+            }
+        }
+
+        impl<const $lanes: usize> $name<$lanes>
+        where
+            $type: crate::LanesAtMost64,
+        {
             /// Construct a mask by setting all lanes to the given value.
             pub fn splat(value: bool) -> Self {
                 Self(<$type>::splat(
@@ -57,13 +77,19 @@ pub fn set(&mut self, lane: usize, value: bool) {
             }
         }
 
-        impl<const $lanes: usize> core::convert::From<bool> for $name<$lanes> {
+        impl<const $lanes: usize> core::convert::From<bool> for $name<$lanes>
+        where
+            $type: crate::LanesAtMost64,
+        {
             fn from(value: bool) -> Self {
                 Self::splat(value)
             }
         }
 
-        impl<const $lanes: usize> core::convert::TryFrom<$type> for $name<$lanes> {
+        impl<const $lanes: usize> core::convert::TryFrom<$type> for $name<$lanes>
+        where
+            $type: crate::LanesAtMost64,
+        {
             type Error = TryFromMaskError;
             fn try_from(value: $type) -> Result<Self, Self::Error> {
                 if value.as_slice().iter().all(|x| *x == 0 || *x == -1) {
@@ -74,7 +100,10 @@ fn try_from(value: $type) -> Result<Self, Self::Error> {
             }
         }
 
-        impl<const $lanes: usize> core::convert::From<$name<$lanes>> for $type {
+        impl<const $lanes: usize> core::convert::From<$name<$lanes>> for $type
+        where
+            $type: crate::LanesAtMost64,
+        {
             fn from(value: $name<$lanes>) -> Self {
                 value.0
             }
@@ -82,6 +111,7 @@ fn from(value: $name<$lanes>) -> Self {
 
         impl<const $lanes: usize> core::convert::From<crate::BitMask<$lanes>> for $name<$lanes>
         where
+            $type: crate::LanesAtMost64,
             crate::BitMask<$lanes>: crate::LanesAtMost64,
         {
             fn from(value: crate::BitMask<$lanes>) -> Self {
@@ -96,6 +126,7 @@ fn from(value: crate::BitMask<$lanes>) -> Self {
 
         impl<const $lanes: usize> core::convert::From<$name<$lanes>> for crate::BitMask<$lanes>
         where
+            $type: crate::LanesAtMost64,
             crate::BitMask<$lanes>: crate::LanesAtMost64,
         {
             fn from(value: $name<$lanes>) -> Self {
@@ -108,7 +139,10 @@ fn from(value: $name<$lanes>) -> Self {
             }
         }
 
-        impl<const $lanes: usize> core::fmt::Debug for $name<$lanes> {
+        impl<const $lanes: usize> core::fmt::Debug for $name<$lanes>
+        where
+            $type: crate::LanesAtMost64,
+        {
             fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
                 f.debug_list()
                     .entries((0..LANES).map(|lane| self.test(lane)))
@@ -116,31 +150,46 @@ fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
             }
         }
 
-        impl<const $lanes: usize> core::fmt::Binary for $name<$lanes> {
+        impl<const $lanes: usize> core::fmt::Binary for $name<$lanes>
+        where
+            $type: crate::LanesAtMost64,
+        {
             fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
                 core::fmt::Binary::fmt(&self.0, f)
             }
         }
 
-        impl<const $lanes: usize> core::fmt::Octal for $name<$lanes> {
+        impl<const $lanes: usize> core::fmt::Octal for $name<$lanes>
+        where
+            $type: crate::LanesAtMost64,
+        {
             fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
                 core::fmt::Octal::fmt(&self.0, f)
             }
         }
 
-        impl<const $lanes: usize> core::fmt::LowerHex for $name<$lanes> {
+        impl<const $lanes: usize> core::fmt::LowerHex for $name<$lanes>
+        where
+            $type: crate::LanesAtMost64,
+        {
             fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
                 core::fmt::LowerHex::fmt(&self.0, f)
             }
         }
 
-        impl<const $lanes: usize> core::fmt::UpperHex for $name<$lanes> {
+        impl<const $lanes: usize> core::fmt::UpperHex for $name<$lanes>
+        where
+            $type: crate::LanesAtMost64,
+        {
             fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
                 core::fmt::UpperHex::fmt(&self.0, f)
             }
         }
 
-        impl<const LANES: usize> core::ops::BitAnd for $name<LANES> {
+        impl<const LANES: usize> core::ops::BitAnd for $name<LANES>
+        where
+            $type: crate::LanesAtMost64,
+        {
             type Output = Self;
             #[inline]
             fn bitand(self, rhs: Self) -> Self {
@@ -148,7 +197,10 @@ fn bitand(self, rhs: Self) -> Self {
             }
         }
 
-        impl<const LANES: usize> core::ops::BitAnd<bool> for $name<LANES> {
+        impl<const LANES: usize> core::ops::BitAnd<bool> for $name<LANES>
+        where
+            $type: crate::LanesAtMost64,
+        {
             type Output = Self;
             #[inline]
             fn bitand(self, rhs: bool) -> Self {
@@ -156,7 +208,10 @@ fn bitand(self, rhs: bool) -> Self {
             }
         }
 
-        impl<const LANES: usize> core::ops::BitAnd<$name<LANES>> for bool {
+        impl<const LANES: usize> core::ops::BitAnd<$name<LANES>> for bool
+        where
+            $type: crate::LanesAtMost64,
+        {
             type Output = $name<LANES>;
             #[inline]
             fn bitand(self, rhs: $name<LANES>) -> $name<LANES> {
@@ -164,7 +219,10 @@ fn bitand(self, rhs: $name<LANES>) -> $name<LANES> {
             }
         }
 
-        impl<const LANES: usize> core::ops::BitOr for $name<LANES> {
+        impl<const LANES: usize> core::ops::BitOr for $name<LANES>
+        where
+            $type: crate::LanesAtMost64,
+        {
             type Output = Self;
             #[inline]
             fn bitor(self, rhs: Self) -> Self {
@@ -172,7 +230,10 @@ fn bitor(self, rhs: Self) -> Self {
             }
         }
 
-        impl<const LANES: usize> core::ops::BitOr<bool> for $name<LANES> {
+        impl<const LANES: usize> core::ops::BitOr<bool> for $name<LANES>
+        where
+            $type: crate::LanesAtMost64,
+        {
             type Output = Self;
             #[inline]
             fn bitor(self, rhs: bool) -> Self {
@@ -180,7 +241,10 @@ fn bitor(self, rhs: bool) -> Self {
             }
         }
 
-        impl<const LANES: usize> core::ops::BitOr<$name<LANES>> for bool {
+        impl<const LANES: usize> core::ops::BitOr<$name<LANES>> for bool
+        where
+            $type: crate::LanesAtMost64,
+        {
             type Output = $name<LANES>;
             #[inline]
             fn bitor(self, rhs: $name<LANES>) -> $name<LANES> {
@@ -188,7 +252,10 @@ fn bitor(self, rhs: $name<LANES>) -> $name<LANES> {
             }
         }
 
-        impl<const LANES: usize> core::ops::BitXor for $name<LANES> {
+        impl<const LANES: usize> core::ops::BitXor for $name<LANES>
+        where
+            $type: crate::LanesAtMost64,
+        {
             type Output = Self;
             #[inline]
             fn bitxor(self, rhs: Self) -> Self::Output {
@@ -196,7 +263,10 @@ fn bitxor(self, rhs: Self) -> Self::Output {
             }
         }
 
-        impl<const LANES: usize> core::ops::BitXor<bool> for $name<LANES> {
+        impl<const LANES: usize> core::ops::BitXor<bool> for $name<LANES>
+        where
+            $type: crate::LanesAtMost64,
+        {
             type Output = Self;
             #[inline]
             fn bitxor(self, rhs: bool) -> Self::Output {
@@ -204,7 +274,10 @@ fn bitxor(self, rhs: bool) -> Self::Output {
             }
         }
 
-        impl<const LANES: usize> core::ops::BitXor<$name<LANES>> for bool {
+        impl<const LANES: usize> core::ops::BitXor<$name<LANES>> for bool
+        where
+            $type: crate::LanesAtMost64,
+        {
             type Output = $name<LANES>;
             #[inline]
             fn bitxor(self, rhs: $name<LANES>) -> Self::Output {
@@ -212,7 +285,10 @@ fn bitxor(self, rhs: $name<LANES>) -> Self::Output {
             }
         }
 
-        impl<const LANES: usize> core::ops::Not for $name<LANES> {
+        impl<const LANES: usize> core::ops::Not for $name<LANES>
+        where
+            $type: crate::LanesAtMost64,
+        {
             type Output = $name<LANES>;
             #[inline]
             fn not(self) -> Self::Output {
@@ -220,42 +296,60 @@ fn not(self) -> Self::Output {
             }
         }
 
-        impl<const LANES: usize> core::ops::BitAndAssign for $name<LANES> {
+        impl<const LANES: usize> core::ops::BitAndAssign for $name<LANES>
+        where
+            $type: crate::LanesAtMost64,
+        {
             #[inline]
             fn bitand_assign(&mut self, rhs: Self) {
                 self.0 &= rhs.0;
             }
         }
 
-        impl<const LANES: usize> core::ops::BitAndAssign<bool> for $name<LANES> {
+        impl<const LANES: usize> core::ops::BitAndAssign<bool> for $name<LANES>
+        where
+            $type: crate::LanesAtMost64,
+        {
             #[inline]
             fn bitand_assign(&mut self, rhs: bool) {
                 *self &= Self::splat(rhs);
             }
         }
 
-        impl<const LANES: usize> core::ops::BitOrAssign for $name<LANES> {
+        impl<const LANES: usize> core::ops::BitOrAssign for $name<LANES>
+        where
+            $type: crate::LanesAtMost64,
+        {
             #[inline]
             fn bitor_assign(&mut self, rhs: Self) {
                 self.0 |= rhs.0;
             }
         }
 
-        impl<const LANES: usize> core::ops::BitOrAssign<bool> for $name<LANES> {
+        impl<const LANES: usize> core::ops::BitOrAssign<bool> for $name<LANES>
+        where
+            $type: crate::LanesAtMost64,
+        {
             #[inline]
             fn bitor_assign(&mut self, rhs: bool) {
                 *self |= Self::splat(rhs);
             }
         }
 
-        impl<const LANES: usize> core::ops::BitXorAssign for $name<LANES> {
+        impl<const LANES: usize> core::ops::BitXorAssign for $name<LANES>
+        where
+            $type: crate::LanesAtMost64,
+        {
             #[inline]
             fn bitxor_assign(&mut self, rhs: Self) {
                 self.0 ^= rhs.0;
             }
         }
 
-        impl<const LANES: usize> core::ops::BitXorAssign<bool> for $name<LANES> {
+        impl<const LANES: usize> core::ops::BitXorAssign<bool> for $name<LANES>
+        where
+            $type: crate::LanesAtMost64,
+        {
             #[inline]
             fn bitxor_assign(&mut self, rhs: bool) {
                 *self ^= Self::splat(rhs);
@@ -291,11 +385,11 @@ fn bitxor_assign(&mut self, rhs: bool) {
 define_mask! {
     /// A mask equivalent to [SimdI128](crate::SimdI128), where all bits in the lane must be either set
     /// or unset.
-    struct SimdMask128<const LANES: usize>(crate::SimdI64<LANES>);
+    struct SimdMask128<const LANES: usize>(crate::SimdI128<LANES>);
 }
 
 define_mask! {
     /// A mask equivalent to [SimdIsize](crate::SimdIsize), where all bits in the lane must be either set
     /// or unset.
-    struct SimdMaskSize<const LANES: usize>(crate::SimdI64<LANES>);
+    struct SimdMaskSize<const LANES: usize>(crate::SimdIsize<LANES>);
 }