Use intrinsic for min/max

This commit is contained in:
Caleb Zulawski 2022-01-13 17:59:55 -05:00
parent 65cb2c90a0
commit 138b9cf4bf
2 changed files with 6 additions and 10 deletions

View file

@ -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;

View file

@ -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.
@ -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.