]> git.lizzy.rs Git - rust.git/blob - library/portable-simd/crates/core_simd/src/eq.rs
Rollup merge of #99544 - dylni:expose-utf8lossy, r=Mark-Simulacrum
[rust.git] / library / portable-simd / crates / core_simd / src / eq.rs
1 use crate::simd::{intrinsics, LaneCount, Mask, Simd, SimdElement, SupportedLaneCount};
2
3 /// Parallel `PartialEq`.
4 pub trait SimdPartialEq {
5     /// The mask type returned by each comparison.
6     type Mask;
7
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;
11
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;
15 }
16
17 macro_rules! impl_number {
18     { $($number:ty),* } => {
19         $(
20         impl<const LANES: usize> SimdPartialEq for Simd<$number, LANES>
21         where
22             LaneCount<LANES>: SupportedLaneCount,
23         {
24             type Mask = Mask<<$number as SimdElement>::Mask, LANES>;
25
26             #[inline]
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)) }
31             }
32
33             #[inline]
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)) }
38             }
39         }
40         )*
41     }
42 }
43
44 impl_number! { f32, f64, u8, u16, u32, u64, usize, i8, i16, i32, i64, isize }
45
46 macro_rules! impl_mask {
47     { $($integer:ty),* } => {
48         $(
49         impl<const LANES: usize> SimdPartialEq for Mask<$integer, LANES>
50         where
51             LaneCount<LANES>: SupportedLaneCount,
52         {
53             type Mask = Self;
54
55             #[inline]
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())) }
60             }
61
62             #[inline]
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())) }
67             }
68         }
69         )*
70     }
71 }
72
73 impl_mask! { i8, i16, i32, i64, isize }