Skip to content

Commit e6d95e4

Browse files
committed
Implement comparisons generically
1 parent ea02805 commit e6d95e4

File tree

1 file changed

+42
-70
lines changed

1 file changed

+42
-70
lines changed

crates/core_simd/src/comparisons.rs

Lines changed: 42 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,49 @@
1-
use crate::{LaneCount, SupportedLaneCount};
2-
3-
macro_rules! implement_mask_ops {
4-
{ $($vector:ident => $mask:ident ($inner_ty:ident),)* } => {
5-
$(
6-
impl<const LANES: usize> crate::$vector<LANES>
7-
where
8-
LaneCount<LANES>: SupportedLaneCount,
9-
{
10-
/// Test if each lane is equal to the corresponding lane in `other`.
11-
#[inline]
12-
pub fn lanes_eq(self, other: Self) -> crate::$mask<LANES> {
13-
unsafe {
14-
crate::$mask::from_int_unchecked(crate::intrinsics::simd_eq(self, other))
15-
}
16-
}
17-
18-
/// Test if each lane is not equal to the corresponding lane in `other`.
19-
#[inline]
20-
pub fn lanes_ne(self, other: Self) -> crate::$mask<LANES> {
21-
unsafe {
22-
crate::$mask::from_int_unchecked(crate::intrinsics::simd_ne(self, other))
23-
}
24-
}
25-
26-
/// Test if each lane is less than the corresponding lane in `other`.
27-
#[inline]
28-
pub fn lanes_lt(self, other: Self) -> crate::$mask<LANES> {
29-
unsafe {
30-
crate::$mask::from_int_unchecked(crate::intrinsics::simd_lt(self, other))
31-
}
32-
}
33-
34-
/// Test if each lane is greater than the corresponding lane in `other`.
35-
#[inline]
36-
pub fn lanes_gt(self, other: Self) -> crate::$mask<LANES> {
37-
unsafe {
38-
crate::$mask::from_int_unchecked(crate::intrinsics::simd_gt(self, other))
39-
}
40-
}
41-
42-
/// Test if each lane is less than or equal to the corresponding lane in `other`.
43-
#[inline]
44-
pub fn lanes_le(self, other: Self) -> crate::$mask<LANES> {
45-
unsafe {
46-
crate::$mask::from_int_unchecked(crate::intrinsics::simd_le(self, other))
47-
}
48-
}
1+
use crate::{LaneCount, Mask, Simd, SimdElement, SupportedLaneCount};
2+
3+
impl<Element, const LANES: usize> Simd<Element, LANES>
4+
where
5+
Element: SimdElement + PartialEq,
6+
LaneCount<LANES>: SupportedLaneCount,
7+
{
8+
/// Test if each lane is equal to the corresponding lane in `other`.
9+
#[inline]
10+
pub fn lanes_eq(self, other: Self) -> Mask<Element::Mask, LANES> {
11+
unsafe { Mask::from_int_unchecked(crate::intrinsics::simd_eq(self, other)) }
12+
}
4913

50-
/// Test if each lane is greater than or equal to the corresponding lane in `other`.
51-
#[inline]
52-
pub fn lanes_ge(self, other: Self) -> crate::$mask<LANES> {
53-
unsafe {
54-
crate::$mask::from_int_unchecked(crate::intrinsics::simd_ge(self, other))
55-
}
56-
}
57-
}
58-
)*
14+
/// Test if each lane is not equal to the corresponding lane in `other`.
15+
#[inline]
16+
pub fn lanes_ne(self, other: Self) -> Mask<Element::Mask, LANES> {
17+
unsafe { Mask::from_int_unchecked(crate::intrinsics::simd_ne(self, other)) }
5918
}
6019
}
6120

62-
implement_mask_ops! {
63-
SimdI8 => Mask8 (SimdI8),
64-
SimdI16 => Mask16 (SimdI16),
65-
SimdI32 => Mask32 (SimdI32),
66-
SimdI64 => Mask64 (SimdI64),
67-
SimdIsize => MaskSize (SimdIsize),
21+
impl<Element, const LANES: usize> Simd<Element, LANES>
22+
where
23+
Element: SimdElement + PartialOrd,
24+
LaneCount<LANES>: SupportedLaneCount,
25+
{
26+
/// Test if each lane is less than the corresponding lane in `other`.
27+
#[inline]
28+
pub fn lanes_lt(self, other: Self) -> Mask<Element::Mask, LANES> {
29+
unsafe { Mask::from_int_unchecked(crate::intrinsics::simd_lt(self, other)) }
30+
}
6831

69-
SimdU8 => Mask8 (SimdI8),
70-
SimdU16 => Mask16 (SimdI16),
71-
SimdU32 => Mask32 (SimdI32),
72-
SimdU64 => Mask64 (SimdI64),
73-
SimdUsize => MaskSize (SimdIsize),
32+
/// Test if each lane is greater than the corresponding lane in `other`.
33+
#[inline]
34+
pub fn lanes_gt(self, other: Self) -> Mask<Element::Mask, LANES> {
35+
unsafe { Mask::from_int_unchecked(crate::intrinsics::simd_gt(self, other)) }
36+
}
7437

75-
SimdF32 => Mask32 (SimdI32),
76-
SimdF64 => Mask64 (SimdI64),
38+
/// Test if each lane is less than or equal to the corresponding lane in `other`.
39+
#[inline]
40+
pub fn lanes_le(self, other: Self) -> Mask<Element::Mask, LANES> {
41+
unsafe { Mask::from_int_unchecked(crate::intrinsics::simd_le(self, other)) }
42+
}
43+
44+
/// Test if each lane is greater than or equal to the corresponding lane in `other`.
45+
#[inline]
46+
pub fn lanes_ge(self, other: Self) -> Mask<Element::Mask, LANES> {
47+
unsafe { Mask::from_int_unchecked(crate::intrinsics::simd_ge(self, other)) }
48+
}
7749
}

0 commit comments

Comments
 (0)