use super::InstructionSet;
pub trait SimdMath {
type V: Copy;
const IS_BF16: bool = false;
const ISA: InstructionSet;
unsafe fn dot_product(a: &[f32], b: &[f32]) -> f32;
unsafe fn dot_product_bf16(a: &[u16], b: &[u16]) -> f32;
unsafe fn dot_product_4x_interleaved(weights: &[[u16; 4]], state: &[f32]) -> [f32; 4];
unsafe fn dot_product_4x_interleaved_dual_frame(
weights: &[[u16; 4]],
state_f0: &[f32],
state_f1: &[f32],
) -> ([f32; 4], [f32; 4]);
unsafe fn dot_product_4x_f32(weights: &[[f32; 4]], state: &[f32]) -> [f32; 4];
unsafe fn dot_product_4x_f32_dual(
weights: &[[f32; 4]],
state_f0: &[f32],
state_f1: &[f32],
) -> ([f32; 4], [f32; 4]);
unsafe fn dot_product_8x_f32(weights: &[[f32; 8]], state: &[f32]) -> [f32; 8];
unsafe fn dot_product_8x_f32_dual(
weights: &[[f32; 8]],
state_f0: &[f32],
state_f1: &[f32],
) -> ([f32; 8], [f32; 8]);
unsafe fn dot_product_16x_f32(weights: &[[f32; 16]], state: &[f32]) -> [f32; 16];
unsafe fn dot_product_16x_f32_dual(
weights: &[[f32; 16]],
state_f0: &[f32],
state_f1: &[f32],
) -> ([f32; 16], [f32; 16]);
unsafe fn dot_product_4x_f32_accumulate(
weights: &[[f32; 4]],
state: &[f32],
init: &[f32; 4],
) -> [f32; 4];
unsafe fn dot_product_4x_f32_dual_accumulate(
weights: &[[f32; 4]],
state_f0: &[f32],
state_f1: &[f32],
init_f0: &[f32; 4],
init_f1: &[f32; 4],
) -> ([f32; 4], [f32; 4]);
unsafe fn dot_product_8x_f32_accumulate(
weights: &[[f32; 8]],
state: &[f32],
init: &[f32; 8],
) -> [f32; 8];
unsafe fn dot_product_8x_f32_dual_accumulate(
weights: &[[f32; 8]],
state_f0: &[f32],
state_f1: &[f32],
init_f0: &[f32; 8],
init_f1: &[f32; 8],
) -> ([f32; 8], [f32; 8]);
unsafe fn dot_product_16x_f32_accumulate(
weights: &[[f32; 16]],
state: &[f32],
init: &[f32; 16],
) -> [f32; 16];
unsafe fn dot_product_16x_f32_dual_accumulate(
weights: &[[f32; 16]],
state_f0: &[f32],
state_f1: &[f32],
init_f0: &[f32; 16],
init_f1: &[f32; 16],
) -> ([f32; 16], [f32; 16]);
unsafe fn dot_product_bf16_4x(
w0: &[u16],
w1: &[u16],
w2: &[u16],
w3: &[u16],
in_frame: &[u16],
) -> [f32; 4];
unsafe fn horizontal_sum<const N: usize>(ptr: *const f32) -> f32;
unsafe fn fused_add_gemv(
in_frame: &[f32],
weights: &[f32],
bias: &[f32],
out_frame: &mut [f32],
do_bias: bool,
);
unsafe fn fused_add_gemm_batch(
in_frames: &[f32],
weights: &[f32],
bias: &[f32],
out_frames: &mut [f32],
num_frames: usize,
do_bias: bool,
);
unsafe fn fused_gemm_residual_batch(
in_frames: &[f32],
weights: &[f32],
bias: &[f32],
residual: &[f32],
out_frames: &mut [f32],
num_frames: usize,
do_bias: bool,
);
unsafe fn fused_gemm_residual_batch_f32(
in_frames: &[f32],
weights: &[f32],
bias: &[f32],
residual: &[f32],
out_frames: &mut [f32],
num_frames: usize,
do_bias: bool,
);
unsafe fn gemv_overwrite(
in_frame: &[f32],
weights: &[f32],
bias: &[f32],
out_frame: &mut [f32],
do_bias: bool,
);
unsafe fn gemv_overwrite_batch(
in_frames: &[f32],
weights: &[f32],
bias: &[f32],
out_frames: &mut [f32],
num_frames: usize,
do_bias: bool,
);
unsafe fn gemv_overwrite_bf16(
in_frame: &[u16],
weights: &[u16],
bias: &[f32],
out_frame: &mut [f32],
do_bias: bool,
);
unsafe fn gemv_with_bias_f32(
in_frames: &[f32],
weights: &[f32],
bias: &[f32],
out_frames: &mut [f32],
num_frames: usize,
);
unsafe fn gemv_no_bias_f32(
in_frames: &[f32],
weights: &[f32],
out_frames: &mut [f32],
num_frames: usize,
);
unsafe fn gemv_overwrite_4gate(
in_frame: &[f32],
weights: &[u16],
bias: &[f32],
out_gates: &mut [f32],
hidden_size: usize,
do_bias: bool,
);
unsafe fn gemv_overwrite_bf16_4gate(
in_frame: &[u16],
weights: &[u16],
bias: &[f32],
out_gates: &mut [f32],
hidden_size: usize,
do_bias: bool,
);
unsafe fn accumulate_head(dest: &mut [f32], src: &[f32]);
unsafe fn tanh_and_accumulate_block(head_input: &mut [f32], block: &mut [f32]);
unsafe fn gated_activation_and_accumulate_block(
head_input: &mut [f32],
block: &mut [f32],
ch: usize,
);
unsafe fn tanh_and_overwrite_block(head_input: &mut [f32], block: &mut [f32]);
unsafe fn tanh_and_accumulate_with_seed(
head_input: &mut [f32],
block: &mut [f32],
seed: &[f32],
);
unsafe fn gated_activation_and_overwrite_block(
head_input: &mut [f32],
block: &mut [f32],
ch: usize,
);
unsafe fn compute_energy_stereo(l: &[f32], r: &[f32]) -> f32;
unsafe fn compute_energy(data: &[f32]) -> f32;
unsafe fn compute_max_diff(a: &[f32], b: &[f32]) -> f32;
unsafe fn compute_peak_abs_stereo(left: &[f32], right: &[f32]) -> (f32, f32);
unsafe fn compute_peak_abs_mono(data: &[f32]) -> f32;
unsafe fn tanh_slice(slice: &mut [f32]);
unsafe fn sigmoid_slice(slice: &mut [f32]);
unsafe fn tanh_slice_hf(slice: &mut [f32]) {
unsafe {
Self::tanh_slice(slice);
}
}
unsafe fn sigmoid_slice_hf(slice: &mut [f32]) {
unsafe {
Self::sigmoid_slice(slice);
}
}
unsafe fn relu_slice(slice: &mut [f32]);
unsafe fn prelu_slice(slice: &mut [f32], slopes: &[f32]);
unsafe fn softsign_slice(slice: &mut [f32]);
unsafe fn silu_slice(slice: &mut [f32]);
unsafe fn hard_tanh_slice(slice: &mut [f32]);
unsafe fn hard_swish_slice(slice: &mut [f32]);
unsafe fn fast_tanh_slice(slice: &mut [f32]);
unsafe fn leaky_hard_tanh_slice(
slice: &mut [f32],
min_val: f32,
max_val: f32,
min_slope: f32,
max_slope: f32,
);
unsafe fn activation_tanh_block(buf: &mut [f32]);
unsafe fn f32_to_bf16(src: &[f32], dest: &mut [u16]);
unsafe fn store_bf16(ptr: *mut u16, v: Self::V);
unsafe fn fused_lstm_gates_dyn(
gates: &mut [f32],
cell_state: &mut [f32],
cell_error: &mut [f32],
hidden_state: &mut [f32],
hidden_size: usize,
);
unsafe fn convolve_stereo(
coeffs: *const f32,
input_l: *const f32,
input_r: *const f32,
taps: usize,
) -> (f32, f32);
unsafe fn convolve_stereo_dual(
coeffs0: *const f32,
coeffs1: *const f32,
input_l: *const f32,
input_r: *const f32,
taps: usize,
) -> ((f32, f32), (f32, f32));
unsafe fn convolve_mono(coeffs: *const f32, input: *const f32, taps: usize) -> f32;
unsafe fn convolve_mono_dual(
coeffs0: *const f32,
coeffs1: *const f32,
input: *const f32,
taps: usize,
) -> (f32, f32);
unsafe fn apply_gain_and_detect_clipping_mono(data: &mut [f32], gain: f32) -> bool;
unsafe fn apply_gain_and_detect_clipping_stereo(
left: &mut [f32],
right: &mut [f32],
gain: f32,
) -> bool;
unsafe fn apply_gain_stereo(left: &mut [f32], right: &mut [f32], gain: f32);
unsafe fn apply_gain(data: &mut [f32], gain: f32);
unsafe fn apply_ramp(data: &mut [f32], start: f32, step: f32);
unsafe fn crossfade_blend_mono(out: &mut [f32], pending: &[f32], t: f32);
unsafe fn apply_ramp_stereo(left: &mut [f32], right: &mut [f32], start: f32, step: f32);
unsafe fn apply_gain_then_dither(data: &mut [f32], gain: f32, offset: f32);
unsafe fn apply_dither_add(data: &mut [f32], offset: f32);
unsafe fn complex_mac_overwrite(
h_re: &[f32],
h_im: &[f32],
x_re: &[f32],
x_im: &[f32],
out_re: &mut [f32],
out_im: &mut [f32],
);
unsafe fn complex_mac_accumulate(
h_re: &[f32],
h_im: &[f32],
x_re: &[f32],
x_im: &[f32],
acc_re: &mut [f32],
acc_im: &mut [f32],
);
unsafe fn fft_butterfly_stage(
re: *mut f32,
im: *mut f32,
half: usize,
tw_re: *const f32,
tw_im: *const f32,
group_start: usize,
inverse: bool,
);
unsafe fn batch_norm_process(
data: &mut [f32],
scale: &[f32],
offset: &[f32],
n_ch: usize,
num_frames: usize,
);
}