Skip to main content

nam_rs/math/common/avx2_impl/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 Fábio Henrique de Lima Silva (fhl.bsb@gmail.com) All rights reserved.
3#![allow(
4    // SAFETY: slices are valid; CPU supports AVX2+FMA (x86-64-v3, verified by dispatch).
5    unsafe_op_in_unsafe_fn,
6    clippy::missing_safety_doc,
7    clippy::too_many_arguments
8)]
9
10//! AVX2 implementations of the `SimdMath` trait.
11//!
12//! This module contains the `Avx2Math` struct.
13//! that implement the `SimdMath` trait using AVX2/FMA instructions.
14//! Methods delegate to kernel functions in `math::gemm`, `math::wavenet`,
15//! `math::lstm`, `math::dsp`, and `math::common::utility`.
16
17use crate::math::common::InstructionSet;
18use crate::math::common::traits::SimdMath;
19use core::arch::x86_64::*;
20
21/// Concrete implementation of the SimdMath trait for processors with AVX2 and FMA support.
22///
23/// This is where we "connect the wires": we connect the abstract mathematical operations of the system
24/// to the ultra-fast functions documented above. This struct ensures that NAM-rs
25/// takes full advantage of modern hardware to process audio in real time.
26pub struct Avx2Math;
27
28mod activations;
29mod bf16;
30mod dsp;
31mod gemv;
32mod reduce;
33
34impl SimdMath for Avx2Math {
35    type V = __m256;
36    const ISA: InstructionSet = InstructionSet::Avx2;
37
38    gemv::impl_avx2_gemv!();
39    activations::impl_avx2_activations!();
40    bf16::impl_avx2_bf16!();
41    reduce::impl_avx2_reduce!();
42    dsp::impl_avx2_dsp!();
43}