nam_rs/math/common/
mod.rs1#![warn(clippy::undocumented_unsafe_blocks)]
5
6pub mod aligned;
19pub mod avx2_impl;
20pub mod half;
21pub mod huge_alloc;
22pub use huge_alloc::HugePageVec;
23pub mod avx512;
24#[cfg(test)]
26pub mod common_test;
27pub mod dispatch;
28pub mod kahan;
29pub mod ops;
30pub mod scalar_ref;
31pub mod traits;
32pub mod utility;
33
34pub use aligned::Aligned64;
35pub use aligned::AlignedVec;
36pub use avx2_impl::Avx2Math;
37pub use avx512::{Avx512Math, Avx512VnniBf16Math};
38pub use dispatch::{InstructionSet, SIMD_MATH, SimdMathConfig, TEST_ISA_OVERRIDE};
39pub use dispatch::{decode_isa_override, effective_instruction_set, encode_isa_override};
40pub use kahan::{Kahan4F32, KahanF32, kahan_add};
41pub use ops::*;
42pub use scalar_ref::*;
43pub use traits::SimdMath;
44pub use utility::*;
45
46#[macro_export]
53macro_rules! dispatch_simd {
54 (@ $target:expr, $m512bf16:ident, $m512:ident, $m256:ident $(, $arg:expr)*) => {
56 {
57 use $crate::math::common::InstructionSet;
58 let __isa = $crate::math::common::effective_instruction_set();
59 match __isa {
60 InstructionSet::Avx512VnniBf16 => $target.$m512bf16($($arg),*),
61 InstructionSet::Avx512 => $target.$m512($($arg),*),
62 InstructionSet::Avx2 => $target.$m256($($arg),*),
63 }
64 }
65 };
66
67 ($target:expr, $method:ident $(, $arg:expr)*) => {
69 {
70 use $crate::math::common::InstructionSet;
71 let __isa = $crate::math::common::effective_instruction_set();
72 match __isa {
73 InstructionSet::Avx512VnniBf16 => {
74 $target.$method::<$crate::math::common::Avx512VnniBf16Math>($($arg),*)
75 }
76 InstructionSet::Avx512 => {
77 $target.$method::<$crate::math::common::Avx512Math>($($arg),*)
78 }
79 InstructionSet::Avx2 => {
80 $target.$method::<$crate::math::common::Avx2Math>($($arg),*)
81 }
82 }
83 }
84 };
85
86 ($method:ident ($($arg:expr),*)) => {
88 {
89 use $crate::math::common::InstructionSet;
90 use $crate::math::common::traits::SimdMath;
91 let __isa = $crate::math::common::effective_instruction_set();
92 #[allow(clippy::macro_metavars_in_unsafe, clippy::allow_attributes)]
94 unsafe {
95 match __isa {
96 InstructionSet::Avx512VnniBf16 => {
97 $crate::math::common::Avx512VnniBf16Math::$method($($arg),*)
98 }
99 InstructionSet::Avx512 => {
100 $crate::math::common::Avx512Math::$method($($arg),*)
101 }
102 InstructionSet::Avx2 => {
103 $crate::math::common::Avx2Math::$method($($arg),*)
104 }
105 }
106 }
107 }
108 };
109}
110
111pub use dispatch_simd;