-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test of principle using SimdF32<n>::sin()
- Loading branch information
1 parent
ce92300
commit 7ca1bfb
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"rust-analyzer.checkOnSave.extraArgs": [ | ||
"+nightly" | ||
], | ||
"rust-analyzer.runnables.cargoExtraArgs": [ | ||
"+nightly" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,5 @@ pub use masks::*; | |
|
||
mod vector; | ||
pub use vector::*; | ||
|
||
mod libmf32; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |