Skip to content

Commit 1c53bff

Browse files
committed
perf(saturators): use fast tanh
1 parent 3044080 commit 1c53bff

File tree

1 file changed

+4
-2
lines changed
  • crates/valib-saturators/src

1 file changed

+4
-2
lines changed

crates/valib-saturators/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::ops;
1414
use clippers::DiodeClipperModel;
1515

1616
use valib_core::dsp::{DSPMeta, DSPProcess};
17+
use valib_core::math::fast;
1718
use valib_core::Scalar;
1819

1920
pub mod adaa;
@@ -152,13 +153,14 @@ pub struct Tanh;
152153
impl<S: Scalar> Saturator<S> for Tanh {
153154
#[inline(always)]
154155
fn saturate(&self, x: S) -> S {
155-
x.simd_tanh()
156+
fast::tanh(x)
156157
}
157158

158159
#[inline(always)]
159160
#[replace_float_literals(S::from_f64(literal))]
160161
fn sat_diff(&self, x: S) -> S {
161-
1. - x.simd_tanh().simd_powi(2)
162+
let tanh = fast::tanh(x);
163+
1. - tanh * tanh
162164
}
163165
}
164166

0 commit comments

Comments
 (0)