1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2026 Fábio Henrique de Lima Silva (fhl.bsb@gmail.com) All rights reserved.
macro_rules! impl_avx512_reduce {
() => {
#[inline(always)]
// SAFETY: ptr is a valid raw pointer to N valid f32 elements;
// CPU supports AVX-512F (verified by dispatch). Kernel uses unaligned 512-bit loads.
unsafe fn horizontal_sum<const N: usize>(ptr: *const f32) -> f32 {
// SAFETY: ptr and N satisfy function invariants.
unsafe { crate::math::common::utility::horizontal_sum_avx512(ptr, N) }
}
#[inline(always)]
// SAFETY: l and r are valid f32 slices of equal length;
// CPU supports AVX-512F (verified by dispatch).
unsafe fn compute_energy_stereo(l: &[f32], r: &[f32]) -> f32 {
// SAFETY: l and r satisfy function invariants.
unsafe { crate::math::dsp::stereo::compute_energy_stereo_avx512(l, r) }
}
#[inline(always)]
// SAFETY: data is a valid f32 slice; CPU supports AVX-512F (verified by dispatch).
unsafe fn compute_energy(data: &[f32]) -> f32 {
// SAFETY: data satisfies function invariants.
unsafe { crate::math::dsp::stereo::compute_energy_avx512(data) }
}
#[inline(always)]
// SAFETY: a and b are valid f32 slices of equal length;
// CPU supports AVX-512F (verified by dispatch).
unsafe fn compute_max_diff(a: &[f32], b: &[f32]) -> f32 {
// SAFETY: a and b satisfy function invariants.
unsafe { crate::math::dsp::stereo::compute_max_diff_avx512(a, b) }
}
#[inline(always)]
// SAFETY: left and right are valid f32 slices of equal length;
// CPU supports AVX-512F (verified by dispatch).
unsafe fn compute_peak_abs_stereo(left: &[f32], right: &[f32]) -> (f32, f32) {
// SAFETY: left and right satisfy function invariants.
unsafe { crate::math::dsp::stereo::compute_peak_abs_stereo_avx512(left, right) }
}
#[inline(always)]
// SAFETY: data is a valid f32 slice; CPU supports AVX-512F (verified by dispatch).
unsafe fn compute_peak_abs_mono(data: &[f32]) -> f32 {
// SAFETY: data satisfies function invariants.
unsafe { crate::math::dsp::stereo::compute_peak_abs_mono_avx512(data) }
}
};
}
macro_rules! impl_avx512vnni_bf16_reduce {
() => {
const IS_BF16: bool = true;
#[inline(always)]
// SAFETY: ptr is a valid raw pointer to N valid f32 elements;
// CPU supports AVX-512 VNNI+BF16 (verified by dispatch).
unsafe fn horizontal_sum<const N: usize>(ptr: *const f32) -> f32 {
crate::math::common::utility::horizontal_sum_avx512(ptr, N)
}
#[inline(always)]
// SAFETY: l and r are valid f32 slices of equal length;
// CPU supports AVX-512 VNNI+BF16 (verified by dispatch).
unsafe fn compute_energy_stereo(l: &[f32], r: &[f32]) -> f32 {
// SAFETY: l and r satisfy function invariants.
unsafe { Avx512Math::compute_energy_stereo(l, r) }
}
#[inline(always)]
// SAFETY: data is a valid f32 slice; CPU supports AVX-512 VNNI+BF16.
unsafe fn compute_energy(data: &[f32]) -> f32 {
// SAFETY: data satisfies function invariants.
unsafe { Avx512Math::compute_energy(data) }
}
#[inline(always)]
// SAFETY: a and b are valid f32 slices of equal length;
// CPU supports AVX-512 VNNI+BF16.
unsafe fn compute_max_diff(a: &[f32], b: &[f32]) -> f32 {
// SAFETY: a and b satisfy function invariants.
unsafe { Avx512Math::compute_max_diff(a, b) }
}
#[inline(always)]
// SAFETY: left and right are valid f32 slices of equal length;
// CPU supports AVX-512 VNNI+BF16.
unsafe fn compute_peak_abs_stereo(left: &[f32], right: &[f32]) -> (f32, f32) {
// SAFETY: left and right satisfy function invariants.
unsafe { Avx512Math::compute_peak_abs_stereo(left, right) }
}
#[inline(always)]
// SAFETY: data is a valid f32 slice; CPU supports AVX-512 VNNI+BF16.
unsafe fn compute_peak_abs_mono(data: &[f32]) -> f32 {
// SAFETY: data satisfies function invariants.
unsafe { Avx512Math::compute_peak_abs_mono(data) }
}
};
}
pub(super) use impl_avx512_reduce;
pub(super) use impl_avx512vnni_bf16_reduce;