Skip to content

Commit 41db153

Browse files
Merge pull request rust-lang#224 from rust-lang/feature/min-max-intrinsic
Use intrinsic for min/max
2 parents 65cb2c9 + 138b9cf commit 41db153

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

crates/core_simd/src/intrinsics.rs

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ extern "platform-intrinsic" {
4646
/// fabs
4747
pub(crate) fn simd_fabs<T>(x: T) -> T;
4848

49+
// minnum/maxnum
50+
pub(crate) fn simd_fmin<T>(x: T, y: T) -> T;
51+
pub(crate) fn simd_fmax<T>(x: T, y: T) -> T;
52+
4953
pub(crate) fn simd_eq<T, U>(x: T, y: T) -> U;
5054
pub(crate) fn simd_ne<T, U>(x: T, y: T) -> U;
5155
pub(crate) fn simd_lt<T, U>(x: T, y: T) -> U;

crates/core_simd/src/vector/float.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,7 @@ macro_rules! impl_float_vector {
141141
#[inline]
142142
#[must_use = "method returns a new vector and does not mutate the original value"]
143143
pub fn min(self, other: Self) -> Self {
144-
// TODO consider using an intrinsic
145-
self.is_nan().select(
146-
other,
147-
self.lanes_ge(other).select(other, self)
148-
)
144+
unsafe { intrinsics::simd_fmin(self, other) }
149145
}
150146

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

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

0 commit comments

Comments
 (0)