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(x: T) -> T; + + /// fsqrt + pub(crate) fn simd_fsqrt(x: T) -> T; pub(crate) fn simd_eq(x: T, y: T) -> U; pub(crate) fn simd_ne(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 $name 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() { + test_helpers::test_unary_elementwise( + &Vector::::sqrt, + &Scalar::sqrt, + &|_| true, + ) + } fn horizontal_sum() { test_helpers::test_1(&|x| { test_helpers::prop_assert_biteq! (