Skip to content

Commit

Permalink
Merge pull request #224 from rust-lang/feature/min-max-intrinsic
Browse files Browse the repository at this point in the history
Use intrinsic for min/max
  • Loading branch information
calebzulawski authored Jan 14, 2022
2 parents 65cb2c9 + 138b9cf commit 41db153
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
4 changes: 4 additions & 0 deletions crates/core_simd/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ extern "platform-intrinsic" {
/// fabs
pub(crate) fn simd_fabs<T>(x: T) -> T;

// minnum/maxnum
pub(crate) fn simd_fmin<T>(x: T, y: T) -> T;
pub(crate) fn simd_fmax<T>(x: T, y: T) -> T;

pub(crate) fn simd_eq<T, U>(x: T, y: T) -> U;
pub(crate) fn simd_ne<T, U>(x: T, y: T) -> U;
pub(crate) fn simd_lt<T, U>(x: T, y: T) -> U;
Expand Down
12 changes: 2 additions & 10 deletions crates/core_simd/src/vector/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,7 @@ macro_rules! impl_float_vector {
#[inline]
#[must_use = "method returns a new vector and does not mutate the original value"]
pub fn min(self, other: Self) -> Self {
// TODO consider using an intrinsic
self.is_nan().select(
other,
self.lanes_ge(other).select(other, self)
)
unsafe { intrinsics::simd_fmin(self, other) }
}

/// Returns the maximum of each lane.
Expand All @@ -154,11 +150,7 @@ macro_rules! impl_float_vector {
#[inline]
#[must_use = "method returns a new vector and does not mutate the original value"]
pub fn max(self, other: Self) -> Self {
// TODO consider using an intrinsic
self.is_nan().select(
other,
self.lanes_le(other).select(other, self)
)
unsafe { intrinsics::simd_fmax(self, other) }
}

/// Restrict each lane to a certain interval unless it is NaN.
Expand Down

0 comments on commit 41db153

Please sign in to comment.