1 use crate::simd::{intrinsics, LaneCount, Mask, Simd, SimdElement, SupportedLaneCount};
3 /// Parallel `PartialEq`.
4 pub trait SimdPartialEq {
5 /// The mask type returned by each comparison.
8 /// Test if each lane is equal to the corresponding lane in `other`.
9 #[must_use = "method returns a new mask and does not mutate the original value"]
10 fn simd_eq(self, other: Self) -> Self::Mask;
12 /// Test if each lane is equal to the corresponding lane in `other`.
13 #[must_use = "method returns a new mask and does not mutate the original value"]
14 fn simd_ne(self, other: Self) -> Self::Mask;
17 macro_rules! impl_number {
18 { $($number:ty),* } => {
20 impl<const LANES: usize> SimdPartialEq for Simd<$number, LANES>
22 LaneCount<LANES>: SupportedLaneCount,
24 type Mask = Mask<<$number as SimdElement>::Mask, LANES>;
27 fn simd_eq(self, other: Self) -> Self::Mask {
28 // Safety: `self` is a vector, and the result of the comparison
29 // is always a valid mask.
30 unsafe { Mask::from_int_unchecked(intrinsics::simd_eq(self, other)) }
34 fn simd_ne(self, other: Self) -> Self::Mask {
35 // Safety: `self` is a vector, and the result of the comparison
36 // is always a valid mask.
37 unsafe { Mask::from_int_unchecked(intrinsics::simd_ne(self, other)) }
44 impl_number! { f32, f64, u8, u16, u32, u64, usize, i8, i16, i32, i64, isize }
46 macro_rules! impl_mask {
47 { $($integer:ty),* } => {
49 impl<const LANES: usize> SimdPartialEq for Mask<$integer, LANES>
51 LaneCount<LANES>: SupportedLaneCount,
56 fn simd_eq(self, other: Self) -> Self::Mask {
57 // Safety: `self` is a vector, and the result of the comparison
58 // is always a valid mask.
59 unsafe { Self::from_int_unchecked(intrinsics::simd_eq(self.to_int(), other.to_int())) }
63 fn simd_ne(self, other: Self) -> Self::Mask {
64 // Safety: `self` is a vector, and the result of the comparison
65 // is always a valid mask.
66 unsafe { Self::from_int_unchecked(intrinsics::simd_ne(self.to_int(), other.to_int())) }
73 impl_mask! { i8, i16, i32, i64, isize }