voice: gate Opus AVX paths to x86_64

This commit is contained in:
DeFiDude 2026-05-21 03:20:07 -06:00
parent b737c320cc
commit 7ac244cafd
6 changed files with 48 additions and 78 deletions

View file

@ -203,7 +203,7 @@ pub fn haar1(x: &mut [f32], n0: usize, stride: usize) {
haar1_scalar(x, n0, stride);
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
unsafe {
if stride == 1 && n0 >= 16 && is_x86_feature_detected!("avx") {
haar1_avx(x, n0);
@ -214,7 +214,7 @@ pub fn haar1(x: &mut [f32], n0: usize, stride: usize) {
haar1_scalar(x, n0, stride);
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx")]
unsafe fn haar1_avx(x: &mut [f32], n0: usize) {
use std::arch::x86_64::*;

View file

@ -613,7 +613,7 @@ fn comb_filter_const(
{
comb_filter_const_neon(y, x, y_idx, x_idx, t, n, g10, g11, g12);
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
unsafe {
if std::arch::is_x86_feature_detected!("avx") {
comb_filter_const_avx(y, x, y_idx, x_idx, t, n, g10, g11, g12);
@ -814,7 +814,7 @@ unsafe fn comb_filter_const_sse(
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx,fma")]
#[allow(unsafe_op_in_unsafe_fn)]
unsafe fn comb_filter_const_avx(
@ -917,7 +917,7 @@ unsafe fn comb_filter_const_avx(
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx,fma")]
#[allow(unsafe_op_in_unsafe_fn)]
unsafe fn comb_filter_const_sse_fma(

View file

@ -270,7 +270,7 @@ unsafe fn kf_bfly2_m1_neon(fout: &mut [KissCpx], n: usize) {
#[inline(always)]
fn kf_bfly2(fout: &mut [KissCpx], m: usize, n: usize) {
if m == 1 {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
unsafe {
if std::arch::is_x86_feature_detected!("avx") {
kf_bfly2_m1_avx(fout, n);
@ -472,7 +472,7 @@ fn kf_bfly4(
mm: usize,
) {
if m == 1 {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
unsafe {
if std::arch::is_x86_feature_detected!("avx") {
kf_bfly4_m1_avx(fout, n);
@ -498,7 +498,7 @@ fn kf_bfly4(
fout[base + 3] = KissCpx::new(scratch0.r - diff13.i, scratch0.i + diff13.r);
}
} else {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
unsafe {
if std::arch::is_x86_feature_detected!("avx") {
kf_bfly4_avx_inner(fout, twiddles, m, n, mm, fstride);
@ -558,7 +558,7 @@ fn kf_bfly3(
n: usize,
mm: usize,
) {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
unsafe {
if std::arch::is_x86_feature_detected!("avx") {
kf_bfly3_avx_inner(fout, fstride, twiddles, m, n, mm);
@ -621,7 +621,7 @@ fn kf_bfly5(
n: usize,
mm: usize,
) {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
unsafe {
if std::arch::is_x86_feature_detected!("avx") {
kf_bfly5_avx_inner(fout, fstride, twiddles, m, n, mm);
@ -707,7 +707,7 @@ fn kf_bfly5(
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx")]
unsafe fn kf_bfly2_m1_avx(fout: &mut [KissCpx], n: usize) {
for i in 0..n {
@ -718,7 +718,7 @@ unsafe fn kf_bfly2_m1_avx(fout: &mut [KissCpx], n: usize) {
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx")]
unsafe fn kf_bfly4_m1_avx(fout: &mut [KissCpx], n: usize) {
let mut i = 0usize;
@ -737,7 +737,7 @@ unsafe fn kf_bfly4_m1_avx(fout: &mut [KissCpx], n: usize) {
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx")]
unsafe fn kf_bfly4_avx_inner(
fout: &mut [KissCpx],
@ -784,7 +784,7 @@ unsafe fn kf_bfly4_avx_inner(
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx")]
unsafe fn kf_bfly3_avx_inner(
fout: &mut [KissCpx],
@ -828,7 +828,7 @@ unsafe fn kf_bfly3_avx_inner(
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx")]
unsafe fn kf_bfly5_avx_inner(
fout: &mut [KissCpx],

View file

@ -149,7 +149,7 @@ impl MdctLookup {
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
unsafe {
if std::arch::is_x86_feature_detected!("avx") {
mdct_pre_rotation_avx(f, f2, trig, &st.bitrev[..n4], n4, scale);
@ -167,17 +167,11 @@ impl MdctLookup {
}
}
}
#[cfg(all(
not(any(target_arch = "x86", target_arch = "x86_64")),
target_arch = "aarch64"
))]
#[cfg(all(not(target_arch = "x86_64"), target_arch = "aarch64"))]
{
mdct_pre_rotation_neon(f, f2, trig, &st.bitrev[..n4], n4, scale);
}
#[cfg(all(
not(any(target_arch = "x86", target_arch = "x86_64")),
not(target_arch = "aarch64")
))]
#[cfg(all(not(target_arch = "x86_64"), not(target_arch = "aarch64")))]
for i in 0..n4 {
let re = f[2 * i];
let im = f[2 * i + 1];
@ -192,7 +186,7 @@ impl MdctLookup {
opus_fft_impl(st, f2);
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
unsafe {
if std::arch::is_x86_feature_detected!("avx") {
mdct_post_rotation_avx(f2, trig, output, n4, n2, stride);
@ -210,17 +204,11 @@ impl MdctLookup {
}
}
}
#[cfg(all(
not(any(target_arch = "x86", target_arch = "x86_64")),
target_arch = "aarch64"
))]
#[cfg(all(not(target_arch = "x86_64"), target_arch = "aarch64"))]
{
mdct_post_rotation_neon(f2, trig, output, n4, n2, stride);
}
#[cfg(all(
not(any(target_arch = "x86", target_arch = "x86_64")),
not(target_arch = "aarch64")
))]
#[cfg(all(not(target_arch = "x86_64"), not(target_arch = "aarch64")))]
for i in 0..n4 {
let fp = &f2[i];
let t0 = trig[i];
@ -258,7 +246,7 @@ impl MdctLookup {
let f2 = unsafe { std::slice::from_raw_parts_mut(f2_buf.as_mut_ptr() as *mut KissCpx, n4) };
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
unsafe {
if std::arch::is_x86_feature_detected!("avx") {
mdct_backward_pre_rotation_avx(input, f2, trig, &st.bitrev[..n4], n4, n2, stride);
@ -277,17 +265,11 @@ impl MdctLookup {
}
}
}
#[cfg(all(
not(any(target_arch = "x86", target_arch = "x86_64")),
target_arch = "aarch64"
))]
#[cfg(all(not(target_arch = "x86_64"), target_arch = "aarch64"))]
{
mdct_backward_pre_rotation_neon(input, f2, trig, &st.bitrev[..n4], n4, n2, stride);
}
#[cfg(all(
not(any(target_arch = "x86", target_arch = "x86_64")),
not(target_arch = "aarch64")
))]
#[cfg(all(not(target_arch = "x86_64"), not(target_arch = "aarch64")))]
for i in 0..n4 {
let rev = st.bitrev[i] as usize;
let x1 = input[2 * i * stride];
@ -305,7 +287,7 @@ impl MdctLookup {
assert!(output.len() >= overlap2 + n2);
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
unsafe {
if std::arch::is_x86_feature_detected!("avx") {
mdct_backward_post_rotation_avx(f2, trig, output, n4, n2, overlap2);
@ -335,17 +317,11 @@ impl MdctLookup {
}
}
}
#[cfg(all(
not(any(target_arch = "x86", target_arch = "x86_64")),
target_arch = "aarch64"
))]
#[cfg(all(not(target_arch = "x86_64"), target_arch = "aarch64"))]
{
mdct_backward_post_rotation_neon(f2, trig, output, n4, n2, overlap2);
}
#[cfg(all(
not(any(target_arch = "x86", target_arch = "x86_64")),
not(target_arch = "aarch64")
))]
#[cfg(all(not(target_arch = "x86_64"), not(target_arch = "aarch64")))]
for i in 0..((n4 + 1) >> 1) {
let im0 = f2[i].r;
let re0 = f2[i].i;
@ -370,7 +346,7 @@ impl MdctLookup {
output[overlap2 + 2 * i + 1] = yi1;
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
unsafe {
if std::arch::is_x86_feature_detected!("avx") {
mdct_tdac_avx(output, window, overlap);
@ -386,17 +362,11 @@ impl MdctLookup {
}
}
}
#[cfg(all(
not(any(target_arch = "x86", target_arch = "x86_64")),
target_arch = "aarch64"
))]
#[cfg(all(not(target_arch = "x86_64"), target_arch = "aarch64"))]
{
mdct_tdac_neon(output, window, overlap);
}
#[cfg(all(
not(any(target_arch = "x86", target_arch = "x86_64")),
not(target_arch = "aarch64")
))]
#[cfg(all(not(target_arch = "x86_64"), not(target_arch = "aarch64")))]
for i in 0..overlap2 {
let x1 = output[overlap - 1 - i];
let x2 = output[i];
@ -409,7 +379,7 @@ impl MdctLookup {
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx")]
unsafe fn mdct_pre_rotation_avx(
f: &[f32],
@ -432,7 +402,7 @@ unsafe fn mdct_pre_rotation_avx(
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx")]
unsafe fn mdct_post_rotation_avx(
f2: &[KissCpx],
@ -455,7 +425,7 @@ unsafe fn mdct_post_rotation_avx(
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx")]
unsafe fn mdct_backward_pre_rotation_avx(
input: &[f32],
@ -480,7 +450,7 @@ unsafe fn mdct_backward_pre_rotation_avx(
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx")]
unsafe fn mdct_backward_post_rotation_avx(
f2: &[KissCpx],
@ -515,7 +485,7 @@ unsafe fn mdct_backward_post_rotation_avx(
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx")]
unsafe fn mdct_tdac_avx(output: &mut [f32], window: &[f32], overlap: usize) {
use std::arch::x86_64::*;

View file

@ -2,7 +2,7 @@
use crate::celt_lpc::{autocorr, lpc};
pub fn inner_prod(x: &[f32], y: &[f32], n: usize) -> f32 {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
unsafe {
if std::arch::is_x86_feature_detected!("avx") {
return inner_prod_avx(x, y, n);
@ -30,7 +30,7 @@ pub fn inner_prod(x: &[f32], y: &[f32], n: usize) -> f32 {
}
pub fn dual_inner_prod(x: &[f32], y1: &[f32], y2: &[f32], n: usize) -> (f32, f32) {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
unsafe {
if std::arch::is_x86_feature_detected!("avx") {
return dual_inner_prod_avx(x, y1, y2, n);
@ -60,7 +60,7 @@ pub fn dual_inner_prod(x: &[f32], y1: &[f32], y2: &[f32], n: usize) -> (f32, f32
}
pub fn pitch_xcorr(x: &[f32], y: &[f32], xcorr: &mut [f32], len: usize, max_pitch: usize) {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
unsafe {
if std::arch::is_x86_feature_detected!("avx") {
return pitch_xcorr_avx(x, y, xcorr, len, max_pitch);
@ -461,7 +461,7 @@ unsafe fn pitch_xcorr_sse(x: &[f32], y: &[f32], xcorr: &mut [f32], len: usize, m
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx,fma")]
unsafe fn inner_prod_avx(x: &[f32], y: &[f32], n: usize) -> f32 {
use std::arch::x86_64::*;
@ -505,7 +505,7 @@ unsafe fn inner_prod_avx(x: &[f32], y: &[f32], n: usize) -> f32 {
result
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx,fma")]
unsafe fn dual_inner_prod_avx(x: &[f32], y1: &[f32], y2: &[f32], n: usize) -> (f32, f32) {
use std::arch::x86_64::*;
@ -567,7 +567,7 @@ unsafe fn dual_inner_prod_avx(x: &[f32], y1: &[f32], y2: &[f32], n: usize) -> (f
(s1, s2)
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx,fma")]
unsafe fn pitch_xcorr_avx(x: &[f32], y: &[f32], xcorr: &mut [f32], len: usize, max_pitch: usize) {
let mut i = 0;
@ -587,7 +587,7 @@ unsafe fn pitch_xcorr_avx(x: &[f32], y: &[f32], xcorr: &mut [f32], len: usize, m
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx,fma")]
unsafe fn xcorr_kernel_avx(x: &[f32], y: &[f32], sum: &mut [f32; 4], len: usize) {
use std::arch::x86_64::*;
@ -892,7 +892,7 @@ fn find_best_pitch(
}
sum
};
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
let mut syy = unsafe {
if std::arch::is_x86_feature_detected!("avx") {
use std::arch::x86_64::*;
@ -932,7 +932,7 @@ fn find_best_pitch(
sum
}
};
#[cfg(not(any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64")))]
#[cfg(not(any(target_arch = "aarch64", target_arch = "x86_64")))]
let mut syy = {
let mut sum = 1.0f32;
for j in 0..len {

View file

@ -1579,7 +1579,7 @@ fn pvq_search_neon(x: &[f32], y: &mut [i32], k: i32, n: usize) {
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx2,fma")]
#[allow(unsafe_op_in_unsafe_fn)]
unsafe fn pvq_search_avx2(x: &[f32], y: &mut [i32], k: i32, n: usize) {
@ -1950,7 +1950,7 @@ pub fn extract_collapse_mask(iy: &[i32], n: usize, b: usize) -> u32 {
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx2,fma")]
#[allow(unsafe_op_in_unsafe_fn)]
unsafe fn renormalise_vector_avx2(x: &mut [f32], n: usize, gain: f32) {
@ -2004,7 +2004,7 @@ unsafe fn renormalise_vector_avx2(x: &mut [f32], n: usize, gain: f32) {
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx2,fma")]
#[allow(unsafe_op_in_unsafe_fn)]
unsafe fn alg_quant_resynth_avx2(y: &[i32], x: &mut [f32], n: usize, gain: f32) {
@ -2048,7 +2048,7 @@ unsafe fn alg_quant_resynth_avx2(y: &[i32], x: &mut [f32], n: usize, gain: f32)
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "avx2")]
#[allow(unsafe_op_in_unsafe_fn)]
unsafe fn pvq_search_scalar_init_avx2(