Skip to main content

Module kernel

Module kernel 

Source
Expand description

Kernel dispatch layer — safe public API + runtime CPU feature detection.

§For application code (safe, no unsafe)

Use only:

  • axpyy[i] ^= c * x[i] (equal lengths; non-overlapping buffers)
  • scaley[i] = c * x[i] (equal lengths; non-overlapping; use scale_inplace for in-place)
  • scale_inplacey[i] = c * y[i]
  • axpy_multi — adaptive blocked/fused multi-source AXPY for encoding
  • dot — GF(2⁸) dot product (GFNI accelerated when available)
  • active_kernel_name — which SIMD tier is active

Length and overlap are asserted in release on the safe wrappers. Tier modules (x86, arm, wasm) are pub(crate) — not part of the external API.

§Dispatch

All SIMD variants are compiled in. On the first call to axpy / scale / scale_inplace (with std), the best tier is selected via is_x86_feature_detected! and cached in OnceLock<KernelSet>.

§Dispatch priority (x86_64)

TierRuntime checkWidthInstruction
1gfni + avx512f + avx512bw512-bitGF2P8MULB zmm
2gfni + avx2256-bitGF2P8MULB ymm
3gfni + sse4.2128-bitGF2P8MULB xmm
4avx512f + avx512bw + ssse3512-bitvpshufb zmm
5avx2 + ssse3256-bitvpshufb ymm
6ssse3128-bitpshufb xmm
7neon (AArch64)128-bitvqtbl1q
8wasm simd128 (compile-time)128-biti8x16_swizzle
9scalar (universal fallback)1 bytetable lookup

§no_std targets

OnceLock requires std. Without std, dispatch uses compile-time #[cfg(target_feature)] selection (bare-metal / embedded).

Functions§

active_kernel_name
Returns the name of the currently active kernel tier.
axpy
y[i] ^= c * x[i] in GF(2⁸) — the fundamental RLNC primitive.
axpy_multi
Multi-source fused AXPY with improved cache behaviour: for each chunk of the destination, apply y ^= c_i * source_i for all i.
dot
sum(a[i] * b[i]) in GF(2⁸).
scale
y[i] = c * x[i] in GF(2⁸).
scale_inplace
In-place scale: y[i] = c * y[i] in GF(2⁸).