diff --git a/src/oscillator/adaa.rs b/src/oscillator/adaa.rs index aa85a91..cb19481 100644 --- a/src/oscillator/adaa.rs +++ b/src/oscillator/adaa.rs @@ -98,7 +98,7 @@ impl Bank { } } impl Table { - #[inline] + #[inline(always)] fn loc(self, q: f64) -> (usize, f64, f64) { // Large tables store the positive half cycle: F2 is odd and F1 is even. // Small tables retain a full cycle to avoid reflection in the common path. @@ -115,15 +115,17 @@ impl Table { if FOLDED { 1.0_f64.copysign(phase) } else { 1.0 }, ) } - #[inline] + #[inline(always)] fn coefficients(self, i: usize) -> [f64; 6] { read_coefficients(SECOND, self.offset + 6 * i) } + #[inline(always)] fn p1(self, q: f64) -> f64 { let (i, t, _) = self.loc::(q); let c = self.coefficients(i); self.n * (c[1] + t * (2. * c[2] + t * (3. * c[3] + t * (4. * c[4] + t * 5. * c[5])))) } + #[inline(always)] fn p2(self, q: f64) -> f64 { let (i, t, sign) = self.loc::(q); let c = self.coefficients(i); @@ -131,6 +133,7 @@ impl Table { // Odd reflection changes only the sign bit, avoiding multiplication by +/-1. f64::from_bits(value.to_bits() ^ (sign.to_bits() & (1 << 63))) } + #[inline(always)] fn raw(self, q: f64) -> f64 { let (i, t, sign) = self.loc::(q); let c = self.coefficients(i); @@ -147,6 +150,22 @@ impl Table { } } fn second(self, a: f64, b: f64, c: f64) -> f64 { + #[cfg(all(target_arch = "x86_64", not(miri)))] + if std::is_x86_feature_detected!("sse4.1") { + // SAFETY: この分岐で必要命令の対応を確認している。 + return unsafe { self.second_sse41::(a, b, c) }; + } + self.second_inner::(a, b, c) + } + + #[cfg(all(target_arch = "x86_64", not(miri)))] + #[target_feature(enable = "sse4.1")] + unsafe fn second_sse41(self, a: f64, b: f64, c: f64) -> f64 { + self.second_inner::(a, b, c) + } + + #[inline(always)] + fn second_inner(self, a: f64, b: f64, c: f64) -> f64 { let span = c - a; if span * self.n < 1. { let (i, x, sign) = self.loc::(a); diff --git a/src/oscillator.rs b/src/oscillator.rs index 17ae160..68f7f85 100644 --- a/src/oscillator.rs +++ b/src/oscillator.rs @@ -204,6 +204,8 @@ pub struct Oscillator { impl Oscillator { pub fn new() -> Self { + #[cfg(all(target_arch = "x86_64", not(miri)))] + let _ = std::is_x86_feature_detected!("sse4.1"); Self { state: OscillatorState { phases: [0.0; 7],