-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A simpler variant of #206. * Comparisons are moved to `SimdPartialEq`, `SimdPartialOrd`, and `SimdOrd`. The function names are prefixed with `simd_` to disambiguate from the regular `PartialEq` etc functions. With the functions on traits instead of `Simd` directly, shadowing the function names doesn't work very well. * Floating point `Ord`-like functions are put into a `SimdFloat` trait. The intention is that eventually (some time after this PR) all floating point functions will be moved from `Simd` to `SimdFloat`, and the same goes for future `SimdInt`/`SimdUint` traits.
- Loading branch information
Showing
11 changed files
with
412 additions
and
230 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use crate::simd::{intrinsics, LaneCount, Mask, Simd, SimdElement, SupportedLaneCount}; | ||
|
||
/// Parallel `PartialEq`. | ||
pub trait SimdPartialEq { | ||
/// The mask type returned by each comparison. | ||
type Mask; | ||
|
||
/// Test if each lane is equal to the corresponding lane in `other`. | ||
#[must_use = "method returns a new mask and does not mutate the original value"] | ||
fn simd_eq(self, other: Self) -> Self::Mask; | ||
|
||
/// Test if each lane is equal to the corresponding lane in `other`. | ||
#[must_use = "method returns a new mask and does not mutate the original value"] | ||
fn simd_ne(self, other: Self) -> Self::Mask; | ||
} | ||
|
||
macro_rules! impl_number { | ||
{ $($number:ty),* } => { | ||
$( | ||
impl<const LANES: usize> SimdPartialEq for Simd<$number, LANES> | ||
where | ||
LaneCount<LANES>: SupportedLaneCount, | ||
{ | ||
type Mask = Mask<<$number as SimdElement>::Mask, LANES>; | ||
|
||
#[inline] | ||
fn simd_eq(self, other: Self) -> Self::Mask { | ||
// Safety: `self` is a vector, and the result of the comparison | ||
// is always a valid mask. | ||
unsafe { Mask::from_int_unchecked(intrinsics::simd_eq(self, other)) } | ||
} | ||
|
||
#[inline] | ||
fn simd_ne(self, other: Self) -> Self::Mask { | ||
// Safety: `self` is a vector, and the result of the comparison | ||
// is always a valid mask. | ||
unsafe { Mask::from_int_unchecked(intrinsics::simd_ne(self, other)) } | ||
} | ||
} | ||
)* | ||
} | ||
} | ||
|
||
impl_number! { f32, f64, u8, u16, u32, u64, usize, i8, i16, i32, i64, isize } | ||
|
||
macro_rules! impl_mask { | ||
{ $($integer:ty),* } => { | ||
$( | ||
impl<const LANES: usize> SimdPartialEq for Mask<$integer, LANES> | ||
where | ||
LaneCount<LANES>: SupportedLaneCount, | ||
{ | ||
type Mask = Self; | ||
|
||
#[inline] | ||
fn simd_eq(self, other: Self) -> Self::Mask { | ||
// Safety: `self` is a vector, and the result of the comparison | ||
// is always a valid mask. | ||
unsafe { Self::from_int_unchecked(intrinsics::simd_eq(self.to_int(), other.to_int())) } | ||
} | ||
|
||
#[inline] | ||
fn simd_ne(self, other: Self) -> Self::Mask { | ||
// Safety: `self` is a vector, and the result of the comparison | ||
// is always a valid mask. | ||
unsafe { Self::from_int_unchecked(intrinsics::simd_ne(self.to_int(), other.to_int())) } | ||
} | ||
} | ||
)* | ||
} | ||
} | ||
|
||
impl_mask! { i8, i16, i32, i64, isize } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.