Skip to main content

hermes_simd_core/ops/
mod.rs

1//! Zero-cost operation strategy markers for SIMD reductions and elementwise transforms.
2//!
3//! `ReductionOp<T>`, `ElementOp<T>`, and `UnaryOp<T>` are sealed ZST traits parameterized
4//! by the scalar type `T: Scalar`. Concrete strategies (`Sum`, `Dot`, `Mul`, `Add`, `Sub`,
5//! `Abs`, `Neg`, `Sqrt`) implement these traits and are passed as ZST values — they carry no
6//! runtime data and the compiler eliminates all abstraction overhead via monomorphization.
7//!
8//! # Module Organization
9//!
10//! | Sub-module | Contents |
11//! |---|---|
12//! | [`reduction`] | `ReductionOp<T>`, `Sum`, `Dot`, `Min`, `Max`, `Product` |
13//! | [`elementwise`] | `ElementOp<T>`, `Mul`, `Add`, `Sub`, `Div`, `BitAnd`, `BitOr`, `BitXor`, `FmaAdd`, `Clamp` |
14//! | [`unary`] | `UnaryOp<T>`, `Abs`, `Neg`, `Sqrt` (and `Clamp` as `UnaryOp`) |
15//! | [`scan`] | `ScanOp<T>`, `ScanMode`, `ScanAdd`, `ScanMul`, `ScanMin`, `ScanMax`, `Inclusive`, `Exclusive` |
16//!
17//! # Usage
18//!
19//! ```rust,ignore
20//! let total: f32 = view.reduce(ops::Sum);
21//! let dot: f32 = view.zip_reduce(&other, ops::Dot)?;
22//! ```
23//!
24//! # Zero-Cost Guarantee
25//!
26//! Each `unsafe fn accumulate` / `unsafe fn apply` call site is a direct call to
27//! an `#[inline(always)]` function that the compiler inlines into the surrounding loop.
28//! The ZST parameter is erased entirely — `size_of::<Sum>() == 0`.
29//!
30//! # Scalar Tail Handling
31//!
32//! `ElementOp<T>` provides `apply_scalar(a, b) -> T` for processing tail elements that
33//! do not fill a complete SIMD vector. This is a pure scalar operation using `T: Scalar`
34//! arithmetic operators, eliminating all boundary-condition UB from vector load/store.
35
36pub mod elementwise;
37pub mod reduction;
38pub mod scan;
39pub mod unary;
40
41// Re-exports for backwards-compatible access at the `ops::*` level.
42pub use elementwise::{Add, BitAnd, BitOr, BitXor, Clamp, Div, ElementOp, FmaAdd, Mul, Sub};
43pub use reduction::{AbsMax, AbsSum, Dot, Max, Min, Product, ReductionOp, Sum};
44pub use scan::{Exclusive, Inclusive, ScanAdd, ScanMax, ScanMin, ScanMode, ScanMul, ScanOp};
45pub use unary::{Abs, Neg, Popcount, RecipSqrt, Sqrt, UnaryOp};