Skip to main content

ta_lib_dispatch/
lib.rs

1// Crate docs = README.md verbatim (single source for crates.io + docs.rs;
2// see README.md for the actual text).
3#![doc = include_str!("../README.md")]
4
5/// Dispatch one indicator call to its hardware-FMA clone when the CPU supports
6/// FMA, else to the portable implementation.
7///
8/// Both paths compute IEEE-754 correctly-rounded fused multiply-adds (`vfmadd`
9/// vs libm `fma()`), so which one runs can change speed, never bits.
10///
11/// # Contract (enforced by ta_codegen, not checkable by a macro)
12///
13/// `$fma` must name a method whose only `#[target_feature]` requirement is
14/// `fma`; the generator emits the clone and this dispatch call as a pair.
15#[macro_export]
16macro_rules! dispatch_fma {
17    ($core:expr, $fma:ident, $plain:ident, ( $($arg:expr),* $(,)? )) => {
18        if std::arch::is_x86_feature_detected!("fma") {
19            // SAFETY: $fma's only target_feature requirement is "fma", proven
20            // present on this CPU by the guard above.
21            unsafe { $core.$fma($($arg),*) }
22        } else {
23            $core.$plain($($arg),*)
24        }
25    };
26}