Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add simd_fsqrt intrinsic #120

Merged
merged 1 commit into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/core_simd/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions crates/core_simd/src/vector/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
miguelraz marked this conversation as resolved.
Show resolved Hide resolved
unsafe { crate::intrinsics::simd_fsqrt(self) }
}
}

impl<const LANES: usize> $name<LANES>
Expand Down
7 changes: 7 additions & 0 deletions crates/core_simd/tests/ops_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! (
Expand Down