Module simd
Expand description
Explicit-SIMD batch kernels for transform math — the AGDF compute-heavy hot loop lever.
A component column is stored as an array of whole structs (AoS-within-the-
component), which is fine for random access but leaves SIMD lanes empty on a
batched math sweep: a Vec3/Quaternion only fills part of a vector
register. The lever is to feed the heavy loops field-split data — every
field its own contiguous f32 stream (TrsBatchSoa) — and process eight
entities at a time with [wide::f32x8]. f32x8 maps 1:1 to an 8-wide AoSoA
tile, so the index split is trivial and the compiler emits one aligned vector
op per field instead of eight scalar ones.
Why explicit SIMD rather than trusting auto-vectorisation: the heavy parts
of this math are a quaternion-to-matrix expansion and a 1/√(x²+y²+z²+w²)
normalisation. The normalisation’s horizontal sum is a floating-point
reduction, and FP addition is not associative — the compiler is not allowed
to reorder it into independent lanes, so it serialises and the loop stays
scalar. Writing the lanes by hand recovers the throughput the auto-vectoriser
leaves on the table.
The kernels are layout-agnostic in the LLAMA sense: callers fill a
TrsBatchSoa from whatever their storage is, and the kernel owns the
physical f32x8 tiling underneath. Each kernel has a scalar twin (used for the
ragged tail and as the equivalence oracle in tests) so the SIMD path is
guaranteed to match the scalar result to the last representable bit of the
same operations.
Structs§
- TrsBatch
Soa - A field-split (struct-of-arrays) batch of translate/rotate/scale inputs.
Constants§
- LANES
- SIMD lane width. Eight
f32lanes = one 256-bit register (AVX) and the AoSoA tile width theTrsBatchSoakernels stride by.
Functions§
- compose_
trs_ to_ mat4 - Composes
out[i] = T · R · Sfor every entity inbatch, the same column-major affine matrixMat4::from_translation(t) *Mat4::from_quat(q) *Mat4::from_scale(s)produces — eight entities per [f32x8] tile, scalar for the ragged tail. - compose_
trs_ to_ mat4_ scalar - Scalar twin of
compose_trs_to_mat4— identical result, one entity at a time, no SIMD. This is the fallback a caller should prefer for small batches (where the field-split transpose costs more than the vector op saves) and the equivalence oracle the SIMD path is tested against. - normalize_
quat_ batch - Normalises a batch of quaternions in place to unit length, eight at a time.