pub trait ReductionOp<T: Scalar>:
Sealed
+ Copy
+ 'static {
// Required methods
unsafe fn accumulate<Arch: SimdKernel<T>>(
acc: Arch::Vector,
v: Arch::Vector,
) -> Arch::Vector;
unsafe fn finalize<Arch: SimdKernel<T>>(acc: Arch::Vector) -> T;
fn identity_scalar() -> T;
fn scalar_combine(a: T, b: T) -> T;
// Provided methods
unsafe fn fma_pair_accumulate<Arch: SimdKernel<T>>(
acc: Arch::Vector,
a: Arch::Vector,
b: Arch::Vector,
) -> Arch::Vector { ... }
fn scalar_accumulate(acc: T, elem: T) -> T { ... }
unsafe fn identity_vector<Arch: SimdKernel<T>>() -> Arch::Vector { ... }
unsafe fn transform_vector<Arch: SimdKernel<T>>(
v: Arch::Vector,
) -> Arch::Vector { ... }
unsafe fn combine_vectors<Arch: SimdKernel<T>>(
a: Arch::Vector,
b: Arch::Vector,
) -> Arch::Vector { ... }
}Expand description
Sealed ZST trait for SIMD horizontal reduction strategies.
Implementors define how a vector accumulator is updated (accumulate) and how
the final scalar result is extracted (finalize). Both methods are #[inline(always)]
and carry no branching — DCE eliminates unused strategies entirely.
§Identity Element
identity_scalar() returns the reduction identity (0 for Sum, T::MAX_VALUE for Min,
T::MIN_VALUE for Max). It is used for empty-slice fast paths and for combining the
scalar tail with the SIMD result via scalar_combine.
Required Methods§
Sourceunsafe fn accumulate<Arch: SimdKernel<T>>(
acc: Arch::Vector,
v: Arch::Vector,
) -> Arch::Vector
unsafe fn accumulate<Arch: SimdKernel<T>>( acc: Arch::Vector, v: Arch::Vector, ) -> Arch::Vector
Merge a new data vector v into accumulator acc.
§Safety
Processor must support the target feature of Arch.
Sourceunsafe fn finalize<Arch: SimdKernel<T>>(acc: Arch::Vector) -> T
unsafe fn finalize<Arch: SimdKernel<T>>(acc: Arch::Vector) -> T
Reduce the final accumulator to a scalar.
§Safety
Processor must support the target feature of Arch.
Sourcefn identity_scalar() -> T
fn identity_scalar() -> T
The identity element for this reduction as a scalar.
Default: must be overridden. Sum returns T::ZERO, Min returns T::MAX_VALUE,
Max returns T::MIN_VALUE.
Sourcefn scalar_combine(a: T, b: T) -> T
fn scalar_combine(a: T, b: T) -> T
Combine two scalar partial results using this reduction.
For Sum: addition. For Min: min_scalar. For Max: max_scalar.
Provided Methods§
Sourceunsafe fn fma_pair_accumulate<Arch: SimdKernel<T>>(
acc: Arch::Vector,
a: Arch::Vector,
b: Arch::Vector,
) -> Arch::Vector
unsafe fn fma_pair_accumulate<Arch: SimdKernel<T>>( acc: Arch::Vector, a: Arch::Vector, b: Arch::Vector, ) -> Arch::Vector
FMA-aware pairwise accumulation: acc = fuse(acc, a, b) where fuse may use
a single fused multiply-add instruction rather than a separate mul + accumulate.
Default: Self::accumulate(acc, Arch::mul(a, b)) — a correct two-instruction fallback.
Override this for Dot and similar operations that can exploit Arch::fmadd.
§Safety
Processor must support the target feature of Arch.
Sourcefn scalar_accumulate(acc: T, elem: T) -> T
fn scalar_accumulate(acc: T, elem: T) -> T
Accumulate a single scalar element elem into a scalar accumulator acc.
Default: delegates to Self::scalar_combine(acc, elem).
Override this for reductions whose SIMD accumulate applies a per-element transform
(e.g. SquaredSum applies elem * elem before adding). The scalar tail path uses this
method instead of scalar_combine to maintain correctness for slices shorter than
Arch::LANE_COUNT.
Sourceunsafe fn identity_vector<Arch: SimdKernel<T>>() -> Arch::Vector
unsafe fn identity_vector<Arch: SimdKernel<T>>() -> Arch::Vector
Splat the identity element into a vector register.
Default: Arch::splat(Self::identity_scalar()). Backends may override.
§Safety
Processor must support the target feature of Arch.
Sourceunsafe fn transform_vector<Arch: SimdKernel<T>>(v: Arch::Vector) -> Arch::Vector
unsafe fn transform_vector<Arch: SimdKernel<T>>(v: Arch::Vector) -> Arch::Vector
Per-element lane transform applied before combining (identity by default).
Reductions with a per-element transform (AbsSum applies abs) override
this so the reduce loop can seed unrolled accumulators with
transform_vector(load(...)) instead of raw loads.
§Safety
Processor must support the target feature of Arch.
Sourceunsafe fn combine_vectors<Arch: SimdKernel<T>>(
a: Arch::Vector,
b: Arch::Vector,
) -> Arch::Vector
unsafe fn combine_vectors<Arch: SimdKernel<T>>( a: Arch::Vector, b: Arch::Vector, ) -> Arch::Vector
Merge two partial accumulators WITHOUT the per-element transform.
accumulate is combine_vectors(acc, transform_vector(v)); the reduce
loop’s cross-accumulator merge must use this method, because the
partials are already transformed. Default delegates to accumulate,
which is correct exactly when transform_vector is the identity —
transform-bearing ops must override both.
§Safety
Processor must support the target feature of Arch.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".