Skip to main content

Module ops

Module ops 

Source
Expand description

Zero-cost operation strategy markers for SIMD reductions and elementwise transforms.

ReductionOp<T>, ElementOp<T>, and UnaryOp<T> are sealed ZST traits parameterized by the scalar type T: Scalar. Concrete strategies (Sum, Dot, Mul, Add, Sub, Abs, Neg, Sqrt) implement these traits and are passed as ZST values — they carry no runtime data and the compiler eliminates all abstraction overhead via monomorphization.

§Module Organization

Sub-moduleContents
reductionReductionOp<T>, Sum, Dot, Min, Max, Product
elementwiseElementOp<T>, Mul, Add, Sub, Div, BitAnd, BitOr, BitXor, FmaAdd, Clamp
unaryUnaryOp<T>, Abs, Neg, Sqrt (and Clamp as UnaryOp)
scanScanOp<T>, ScanMode, ScanAdd, ScanMul, ScanMin, ScanMax, Inclusive, Exclusive

§Usage

let total: f32 = view.reduce(ops::Sum);
let dot: f32 = view.zip_reduce(&other, ops::Dot)?;

§Zero-Cost Guarantee

Each unsafe fn accumulate / unsafe fn apply call site is a direct call to an #[inline(always)] function that the compiler inlines into the surrounding loop. The ZST parameter is erased entirely — size_of::<Sum>() == 0.

§Scalar Tail Handling

ElementOp<T> provides apply_scalar(a, b) -> T for processing tail elements that do not fill a complete SIMD vector. This is a pure scalar operation using T: Scalar arithmetic operators, eliminating all boundary-condition UB from vector load/store.

Re-exports§

pub use elementwise::Add;
pub use elementwise::BitAnd;
pub use elementwise::BitOr;
pub use elementwise::BitXor;
pub use elementwise::Clamp;
pub use elementwise::Div;
pub use elementwise::ElementOp;
pub use elementwise::FmaAdd;
pub use elementwise::Mul;
pub use elementwise::Sub;
pub use reduction::AbsMax;
pub use reduction::AbsSum;
pub use reduction::Dot;
pub use reduction::Max;
pub use reduction::Min;
pub use reduction::Product;
pub use reduction::ReductionOp;
pub use reduction::Sum;
pub use scan::Exclusive;
pub use scan::Inclusive;
pub use scan::ScanAdd;
pub use scan::ScanMax;
pub use scan::ScanMin;
pub use scan::ScanMode;
pub use scan::ScanMul;
pub use scan::ScanOp;
pub use unary::Abs;
pub use unary::Neg;
pub use unary::Popcount;
pub use unary::RecipSqrt;
pub use unary::Sqrt;
pub use unary::UnaryOp;

Modules§

elementwise
Pairwise lane-wise elementwise operation strategies.
reduction
Horizontal reduction operation strategies.
scan
Associative prefix-scan operation strategies and inclusion-mode ZSTs.
unary
Single-operand SIMD elementwise operation strategies.