summaryrefslogtreecommitdiffstats
path: root/third_party/rust/packed_simd/src/masks.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/packed_simd/src/masks.rs
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/packed_simd/src/masks.rs')
-rw-r--r--third_party/rust/packed_simd/src/masks.rs126
1 files changed, 126 insertions, 0 deletions
diff --git a/third_party/rust/packed_simd/src/masks.rs b/third_party/rust/packed_simd/src/masks.rs
new file mode 100644
index 0000000000..04534eab2b
--- /dev/null
+++ b/third_party/rust/packed_simd/src/masks.rs
@@ -0,0 +1,126 @@
+//! 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.
+);