Skip to content

Commit

Permalink
Test of principle using SimdF32<n>::sin()
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-thomason committed May 31, 2021
1 parent ce92300 commit 7ca1bfb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/core_simd/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"rust-analyzer.checkOnSave.extraArgs": [
"+nightly"
],
"rust-analyzer.runnables.cargoExtraArgs": [
"+nightly"
]
}
2 changes: 2 additions & 0 deletions crates/core_simd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ pub use masks::*;

mod vector;
pub use vector::*;

mod libmf32;
35 changes: 35 additions & 0 deletions crates/core_simd/src/libmf32.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use crate::SimdF32;

impl<const LANES: usize> SimdF32<LANES>
where
Self: crate::LanesAtMost32,
{
// This does not seem to be implemented, yet.
#[inline]
fn mul_add(self, mul: Self, add: Self) -> Self {
self * mul + add
}

/// Compute the sine of the angle in radians.
/// Result is accurate to 0.0000002.
///
/// # Example
///
/// ```
/// use core_simd::SimdF32;
/// let x = SimdF32::<8>::splat(1.0);
/// assert!((x.sin() - SimdF32::<8>::splat((1.0_f32).sin())).abs().horizontal_max() < 0.0000002);
/// ```
#[inline]
pub fn sin(&self) -> Self {
let x = Self::splat(1.0 / (core::f32::consts::PI * 2.0)) * self;
let x = x - x.floor() - 0.5;
Self::splat(12.268859941019306_f32)
.mul_add(x * x, Self::splat(-41.216241051002875_f32))
.mul_add(x * x, Self::splat(76.58672703334098_f32))
.mul_add(x * x, Self::splat(-81.59746095374902_f32))
.mul_add(x * x, Self::splat(41.34151143437585_f32))
.mul_add(x * x, Self::splat(-6.283184525811273_f32))
* x
}
}

0 comments on commit 7ca1bfb

Please sign in to comment.