diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/packed_simd_2/src/masks.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/packed_simd_2/src/masks.rs')
-rw-r--r-- | vendor/packed_simd_2/src/masks.rs | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/vendor/packed_simd_2/src/masks.rs b/vendor/packed_simd_2/src/masks.rs new file mode 100644 index 000000000..aeb36d232 --- /dev/null +++ b/vendor/packed_simd_2/src/masks.rs @@ -0,0 +1,130 @@ +//! Mask types + +macro_rules! impl_mask_ty { + ($id:ident : $elem_ty:ident | #[$doc:meta]) => { + #[$doc] + #[derive(Copy, Clone)] + pub struct $id($elem_ty); + + impl crate::sealed::Seal for $id {} + impl crate::sealed::Mask for $id { + #[inline] + fn test(&self) -> bool { + $id::test(self) + } + } + + impl $id { + /// Instantiate a mask with `value` + #[inline] + pub fn new(x: bool) -> Self { + if x { + $id(!0) + } else { + $id(0) + } + } + /// Test if the mask is set + #[inline] + pub fn test(&self) -> bool { + self.0 != 0 + } + } + + impl Default for $id { + #[inline] + fn default() -> Self { + $id(0) + } + } + + #[allow(clippy::partialeq_ne_impl)] + impl PartialEq<$id> for $id { + #[inline] + fn eq(&self, other: &Self) -> bool { + self.0 == other.0 + } + #[inline] + fn ne(&self, other: &Self) -> bool { + self.0 != other.0 + } + } + + impl Eq for $id {} + + impl PartialOrd<$id> for $id { + #[inline] + fn partial_cmp( + &self, other: &Self, + ) -> Option<crate::cmp::Ordering> { + use crate::cmp::Ordering; + if self == other { + Some(Ordering::Equal) + } else if self.0 > other.0 { + // Note: + // * false = 0_i + // * true == !0_i == -1_i + Some(Ordering::Less) + } else { + Some(Ordering::Greater) + } + } + + #[inline] + fn lt(&self, other: &Self) -> bool { + self.0 > other.0 + } + #[inline] + fn gt(&self, other: &Self) -> bool { + self.0 < other.0 + } + #[inline] + fn le(&self, other: &Self) -> bool { + self.0 >= other.0 + } + #[inline] + fn ge(&self, other: &Self) -> bool { + self.0 <= other.0 + } + } + + impl Ord for $id { + #[inline] + fn cmp(&self, other: &Self) -> crate::cmp::Ordering { + match self.partial_cmp(other) { + Some(x) => x, + None => unsafe { crate::hint::unreachable_unchecked() }, + } + } + } + + impl crate::hash::Hash for $id { + #[inline] + fn hash<H: crate::hash::Hasher>(&self, state: &mut H) { + (self.0 != 0).hash(state); + } + } + + impl crate::fmt::Debug for $id { + #[inline] + fn fmt( + &self, fmtter: &mut crate::fmt::Formatter<'_>, + ) -> Result<(), crate::fmt::Error> { + write!(fmtter, "{}({})", stringify!($id), self.0 != 0) + } + } + }; +} + +impl_mask_ty!(m8: i8 | /// 8-bit wide mask. +); +impl_mask_ty!(m16: i16 | /// 16-bit wide mask. +); +impl_mask_ty!(m32: i32 | /// 32-bit wide mask. +); +impl_mask_ty!(m64: i64 | /// 64-bit wide mask. +); +impl_mask_ty!(m128: i128 | /// 128-bit wide mask. +); +impl_mask_ty!(msize: isize | /// isize-wide mask. +); |