]> git.lizzy.rs Git - rust.git/blob - library/portable-simd/crates/core_simd/src/comparisons.rs
Rollup merge of #91610 - aDotInTheVoid:patch-2, r=GuillaumeGomez
[rust.git] / library / portable-simd / crates / core_simd / src / comparisons.rs
1 use crate::simd::intrinsics;
2 use crate::simd::{LaneCount, Mask, Simd, SimdElement, SupportedLaneCount};
3
4 impl<T, const LANES: usize> Simd<T, LANES>
5 where
6     T: SimdElement + PartialEq,
7     LaneCount<LANES>: SupportedLaneCount,
8 {
9     /// Test if each lane is equal to the corresponding lane in `other`.
10     #[inline]
11     #[must_use = "method returns a new mask and does not mutate the original value"]
12     pub fn lanes_eq(self, other: Self) -> Mask<T::Mask, LANES> {
13         unsafe { Mask::from_int_unchecked(intrinsics::simd_eq(self, other)) }
14     }
15
16     /// Test if each lane is not equal to the corresponding lane in `other`.
17     #[inline]
18     #[must_use = "method returns a new mask and does not mutate the original value"]
19     pub fn lanes_ne(self, other: Self) -> Mask<T::Mask, LANES> {
20         unsafe { Mask::from_int_unchecked(intrinsics::simd_ne(self, other)) }
21     }
22 }
23
24 impl<T, const LANES: usize> Simd<T, LANES>
25 where
26     T: SimdElement + PartialOrd,
27     LaneCount<LANES>: SupportedLaneCount,
28 {
29     /// Test if each lane is less than the corresponding lane in `other`.
30     #[inline]
31     #[must_use = "method returns a new mask and does not mutate the original value"]
32     pub fn lanes_lt(self, other: Self) -> Mask<T::Mask, LANES> {
33         unsafe { Mask::from_int_unchecked(intrinsics::simd_lt(self, other)) }
34     }
35
36     /// Test if each lane is greater than the corresponding lane in `other`.
37     #[inline]
38     #[must_use = "method returns a new mask and does not mutate the original value"]
39     pub fn lanes_gt(self, other: Self) -> Mask<T::Mask, LANES> {
40         unsafe { Mask::from_int_unchecked(intrinsics::simd_gt(self, other)) }
41     }
42
43     /// Test if each lane is less than or equal to the corresponding lane in `other`.
44     #[inline]
45     #[must_use = "method returns a new mask and does not mutate the original value"]
46     pub fn lanes_le(self, other: Self) -> Mask<T::Mask, LANES> {
47         unsafe { Mask::from_int_unchecked(intrinsics::simd_le(self, other)) }
48     }
49
50     /// Test if each lane is greater than or equal to the corresponding lane in `other`.
51     #[inline]
52     #[must_use = "method returns a new mask and does not mutate the original value"]
53     pub fn lanes_ge(self, other: Self) -> Mask<T::Mask, LANES> {
54         unsafe { Mask::from_int_unchecked(intrinsics::simd_ge(self, other)) }
55     }
56 }