diff options
| author | Caleb Zulawski <caleb.zulawski@gmail.com> | 2022-01-13 20:22:00 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-13 20:22:00 -0500 |
| commit | 41db15373a72f5234fefae3b3dd2f95c874a1bfd (patch) | |
| tree | c044dcf40c18fa00875e984068878d94e19c4fc6 | |
| parent | 65cb2c90a0688c110d983a2dbb9932900cd6b5d9 (diff) | |
| parent | 138b9cf4bf8f483c60e4454f0a7e64973474ca07 (diff) | |
| download | rust-41db15373a72f5234fefae3b3dd2f95c874a1bfd.tar.gz rust-41db15373a72f5234fefae3b3dd2f95c874a1bfd.zip | |
Merge pull request #224 from rust-lang/feature/min-max-intrinsic
Use intrinsic for min/max
| -rw-r--r-- | crates/core_simd/src/intrinsics.rs | 4 | ||||
| -rw-r--r-- | crates/core_simd/src/vector/float.rs | 12 |
2 files changed, 6 insertions, 10 deletions
diff --git a/crates/core_simd/src/intrinsics.rs b/crates/core_simd/src/intrinsics.rs index 0bc241af1f1..70f1d47c08b 100644 --- a/crates/core_simd/src/intrinsics.rs +++ b/crates/core_simd/src/intrinsics.rs @@ -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; diff --git a/crates/core_simd/src/vector/float.rs b/crates/core_simd/src/vector/float.rs index 3528a420351..0e179d6fa76 100644 --- a/crates/core_simd/src/vector/float.rs +++ b/crates/core_simd/src/vector/float.rs @@ -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. |
