]> git.lizzy.rs Git - rust.git/commitdiff
add simd_fsqrt intrinsic
authormiguel raz <miguelraz@gmail.com>
Tue, 18 May 2021 14:26:01 +0000 (09:26 -0500)
committermiguel raz <miguelraz@gmail.com>
Tue, 18 May 2021 15:11:37 +0000 (10:11 -0500)
crates/core_simd/src/intrinsics.rs
crates/core_simd/src/vector/float.rs
crates/core_simd/tests/ops_macros.rs

index 3779d96a40ec4283a517e744b5de26b4439e05dd..7adf4c24e104ee79518f85167fe55495517bda72 100644 (file)
@@ -45,6 +45,9 @@
 
     /// 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;
index 6371f88a40a21deef428d16ea527a1360841ee56..c4565a9dd900bb3afb9fd3cf0e924b573a7b8d45 100644 (file)
@@ -35,6 +35,14 @@ pub fn from_bits(bits: crate::$bits_ty<LANES>) -> Self {
             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>
index 9f9992258770166038e83aa73d611f7275fb2298..83c6fec69e883c357ed5e094b785d2ec056b705b 100644 (file)
@@ -426,6 +426,13 @@ fn abs<const LANES: usize>() {
                     )
                 }
 
+                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! (