Skip to content

Commit 20c3b8e

Browse files
Merge pull request #120 from miguelraz/simd_fsqrt
add simd_fsqrt intrinsic
2 parents 1c18f8f + d679581 commit 20c3b8e

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

crates/core_simd/src/intrinsics.rs

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ extern "platform-intrinsic" {
4545

4646
/// fabs
4747
pub(crate) fn simd_fabs<T>(x: T) -> T;
48+
49+
/// fsqrt
50+
pub(crate) fn simd_fsqrt<T>(x: T) -> T;
4851

4952
pub(crate) fn simd_eq<T, U>(x: T, y: T) -> U;
5053
pub(crate) fn simd_ne<T, U>(x: T, y: T) -> U;

crates/core_simd/src/vector/float.rs

+8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ macro_rules! impl_float_vector {
3535
pub fn abs(self) -> Self {
3636
unsafe { crate::intrinsics::simd_fabs(self) }
3737
}
38+
39+
/// Produces a vector where every lane has the square root value
40+
/// of the equivalently-indexed lane in `self`
41+
#[inline]
42+
#[cfg(feature = "std")]
43+
pub fn sqrt(self) -> Self {
44+
unsafe { crate::intrinsics::simd_fsqrt(self) }
45+
}
3846
}
3947

4048
impl<const LANES: usize> $name<LANES>

crates/core_simd/tests/ops_macros.rs

+7
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,13 @@ macro_rules! impl_float_tests {
426426
)
427427
}
428428

429+
fn sqrt<const LANES: usize>() {
430+
test_helpers::test_unary_elementwise(
431+
&Vector::<LANES>::sqrt,
432+
&Scalar::sqrt,
433+
&|_| true,
434+
)
435+
}
429436
fn horizontal_sum<const LANES: usize>() {
430437
test_helpers::test_1(&|x| {
431438
test_helpers::prop_assert_biteq! (

0 commit comments

Comments
 (0)