From c2f59483f96cf1ab1e92cf10e0f9094432a8374c Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Tue, 21 Sep 2021 18:55:05 -0700 Subject: [PATCH] Feature-flag fused mul-add to block libcalls --- crates/core_simd/src/intrinsics.rs | 13 +++++------ crates/core_simd/src/vector/float.rs | 1 + crates/core_simd/tests/ops_macros.rs | 33 +++++++++++++++------------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/crates/core_simd/src/intrinsics.rs b/crates/core_simd/src/intrinsics.rs index 3ed9845d608e..5783950f353e 100644 --- a/crates/core_simd/src/intrinsics.rs +++ b/crates/core_simd/src/intrinsics.rs @@ -46,13 +46,6 @@ extern "platform-intrinsic" { /// fabs pub(crate) fn simd_fabs(x: T) -> T; - /// fsqrt - #[cfg(feature = "std")] - pub(crate) fn simd_fsqrt(x: T) -> T; - - /// fma - pub(crate) fn simd_fma(x: T, y: T, z: T) -> T; - pub(crate) fn simd_eq(x: T, y: T) -> U; pub(crate) fn simd_ne(x: T, y: T) -> U; pub(crate) fn simd_lt(x: T, y: T) -> U; @@ -110,6 +103,12 @@ mod std { // trunc pub(crate) fn simd_trunc(x: T) -> T; + + // fsqrt + pub(crate) fn simd_fsqrt(x: T) -> T; + + // fma + pub(crate) fn simd_fma(x: T, y: T, z: T) -> T; } } diff --git a/crates/core_simd/src/vector/float.rs b/crates/core_simd/src/vector/float.rs index 21a6c43e153a..c09d0ac84d24 100644 --- a/crates/core_simd/src/vector/float.rs +++ b/crates/core_simd/src/vector/float.rs @@ -42,6 +42,7 @@ macro_rules! impl_float_vector { /// architecture has a dedicated `fma` CPU instruction. However, this is not always /// true, and will be heavily dependent on designing algorithms with specific target /// hardware in mind. + #[cfg(feature = "std")] #[inline] pub fn mul_add(self, a: Self, b: Self) -> Self { unsafe { intrinsics::simd_fma(self, a, b) } diff --git a/crates/core_simd/tests/ops_macros.rs b/crates/core_simd/tests/ops_macros.rs index 0c45ea2367c9..31b7ee206959 100644 --- a/crates/core_simd/tests/ops_macros.rs +++ b/crates/core_simd/tests/ops_macros.rs @@ -437,14 +437,6 @@ macro_rules! impl_float_tests { ) } - fn mul_add() { - test_helpers::test_ternary_elementwise( - &Vector::::mul_add, - &Scalar::mul_add, - &|_, _, _| true, - ) - } - fn recip() { test_helpers::test_unary_elementwise( &Vector::::recip, @@ -601,13 +593,24 @@ macro_rules! impl_float_tests { } #[cfg(feature = "std")] - test_helpers::test_lanes! { - fn sqrt() { - test_helpers::test_unary_elementwise( - &Vector::::sqrt, - &Scalar::sqrt, - &|_| true, - ) + mod std { + use super::*; + test_helpers::test_lanes! { + fn sqrt() { + test_helpers::test_unary_elementwise( + &Vector::::sqrt, + &Scalar::sqrt, + &|_| true, + ) + } + + fn mul_add() { + test_helpers::test_ternary_elementwise( + &Vector::::mul_add, + &Scalar::mul_add, + &|_, _, _| true, + ) + } } } }