From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/packed_simd_2/src/masks.rs | 130 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 vendor/packed_simd_2/src/masks.rs (limited to 'vendor/packed_simd_2/src/masks.rs') 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 { + 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(&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. +); -- cgit v1.2.3