diff options
| author | miguel raz <miguelraz@gmail.com> | 2021-05-18 09:26:01 -0500 |
|---|---|---|
| committer | miguel raz <miguelraz@gmail.com> | 2021-05-18 10:11:37 -0500 |
| commit | d6795814d402ec47c98c023dd3f298c6a3f5bfa1 (patch) | |
| tree | 1e9aadf3fe29ffe893249c121cfb13de2cf38935 | |
| parent | ce92300a49367a10489d0f9280adfa52ff60f6cf (diff) | |
| download | rust-d6795814d402ec47c98c023dd3f298c6a3f5bfa1.tar.gz rust-d6795814d402ec47c98c023dd3f298c6a3f5bfa1.zip | |
add simd_fsqrt intrinsic
| -rw-r--r-- | crates/core_simd/src/intrinsics.rs | 3 | ||||
| -rw-r--r-- | crates/core_simd/src/vector/float.rs | 8 | ||||
| -rw-r--r-- | crates/core_simd/tests/ops_macros.rs | 7 |
3 files changed, 18 insertions, 0 deletions
diff --git a/crates/core_simd/src/intrinsics.rs b/crates/core_simd/src/intrinsics.rs index 3779d96a40e..7adf4c24e10 100644 --- a/crates/core_simd/src/intrinsics.rs +++ b/crates/core_simd/src/intrinsics.rs @@ -45,6 +45,9 @@ extern "platform-intrinsic" { /// fabs pub(crate) fn simd_fabs<T>(x: T) -> T; + + /// fsqrt + pub(crate) fn simd_fsqrt<T>(x: 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; diff --git a/crates/core_simd/src/vector/float.rs b/crates/core_simd/src/vector/float.rs index 6371f88a40a..c4565a9dd90 100644 --- a/crates/core_simd/src/vector/float.rs +++ b/crates/core_simd/src/vector/float.rs @@ -35,6 +35,14 @@ macro_rules! impl_float_vector { pub fn abs(self) -> Self { unsafe { crate::intrinsics::simd_fabs(self) } } + + /// Produces a vector where every lane has the square root value + /// of the equivalently-indexed lane in `self` + #[inline] + #[cfg(feature = "std")] + pub fn sqrt(self) -> Self { + unsafe { crate::intrinsics::simd_fsqrt(self) } + } } impl<const LANES: usize> $name<LANES> diff --git a/crates/core_simd/tests/ops_macros.rs b/crates/core_simd/tests/ops_macros.rs index 9f999225877..83c6fec69e8 100644 --- a/crates/core_simd/tests/ops_macros.rs +++ b/crates/core_simd/tests/ops_macros.rs @@ -426,6 +426,13 @@ macro_rules! impl_float_tests { ) } + fn sqrt<const LANES: usize>() { + test_helpers::test_unary_elementwise( + &Vector::<LANES>::sqrt, + &Scalar::sqrt, + &|_| true, + ) + } fn horizontal_sum<const LANES: usize>() { test_helpers::test_1(&|x| { test_helpers::prop_assert_biteq! ( |
