Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7ca1bfb

Browse files
committedMay 31, 2021
Test of principle using SimdF32<n>::sin()
1 parent ce92300 commit 7ca1bfb

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
 
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"rust-analyzer.checkOnSave.extraArgs": [
3+
"+nightly"
4+
],
5+
"rust-analyzer.runnables.cargoExtraArgs": [
6+
"+nightly"
7+
]
8+
}

‎crates/core_simd/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ pub use masks::*;
3333

3434
mod vector;
3535
pub use vector::*;
36+
37+
mod libmf32;

‎crates/core_simd/src/libmf32.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use crate::SimdF32;
2+
3+
impl<const LANES: usize> SimdF32<LANES>
4+
where
5+
Self: crate::LanesAtMost32,
6+
{
7+
// This does not seem to be implemented, yet.
8+
#[inline]
9+
fn mul_add(self, mul: Self, add: Self) -> Self {
10+
self * mul + add
11+
}
12+
13+
/// Compute the sine of the angle in radians.
14+
/// Result is accurate to 0.0000002.
15+
///
16+
/// # Example
17+
///
18+
/// ```
19+
/// use core_simd::SimdF32;
20+
/// let x = SimdF32::<8>::splat(1.0);
21+
/// assert!((x.sin() - SimdF32::<8>::splat((1.0_f32).sin())).abs().horizontal_max() < 0.0000002);
22+
/// ```
23+
#[inline]
24+
pub fn sin(&self) -> Self {
25+
let x = Self::splat(1.0 / (core::f32::consts::PI * 2.0)) * self;
26+
let x = x - x.floor() - 0.5;
27+
Self::splat(12.268859941019306_f32)
28+
.mul_add(x * x, Self::splat(-41.216241051002875_f32))
29+
.mul_add(x * x, Self::splat(76.58672703334098_f32))
30+
.mul_add(x * x, Self::splat(-81.59746095374902_f32))
31+
.mul_add(x * x, Self::splat(41.34151143437585_f32))
32+
.mul_add(x * x, Self::splat(-6.283184525811273_f32))
33+
* x
34+
}
35+
}

0 commit comments

Comments
 (0)
Please sign in to comment.