Skip to content

Commit 2196eda

Browse files
committed
Proof of principle with sin(f32)
1 parent f3543b0 commit 2196eda

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

crates/core_simd/src/lib.rs

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

3131
mod vector;
3232
pub use vector::*;
33+
34+
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)