Skip to main content

Module kernel

Module kernel 

Source
Expand description

Low-level SIMD operations trait implemented per architecture and primitive type.

§Extension Surface (v2+)

New in this iteration:

  • sub(a, b) — elementwise subtraction, required for Sub ElementOp strategy.
  • mask_from_bitmask(bm) — convert BitMask<LANE_COUNT> to native mask; default calls mask_from_bools via BitMask::to_bools(). AVX-512 impls override with direct cast.
  • zero() — returns a vector of zeros; default implementation uses splat(T::ZERO). Backends may override with an architecture-specific XOR-zero idiom if profiling shows benefit.

§Extension Surface (v2)

Beyond the base load/store/arithmetic/reduce methods, SimdKernel now exposes:

  • Masked operations (masked_load_unaligned, masked_store_unaligned, masked_add, masked_mul, masked_fmadd, masked_sum_reduce) — predicated arithmetic using hardware mask registers. The src parameter follows AVX-512 merge-masking semantics: lanes where mask[i] = 0 are taken from src.

  • Compress / expand — scatter/gather from/to contiguous storage:

    • compress: packs selected lanes (mask[i]=1) to low lanes of result.
    • expand: scatters low lanes of src to positions where mask[i]=1.
  • Gather (gather, gather_masked) — indirect indexed load from a base pointer.

  • Mask construction (mask_from_bools, leading_k_mask) — build masks from boolean arrays or lane counts for tail handling.

§Architecture Mapping

MethodAVX-512AVX2NEONScalar
masked_add_mm512_mask_add_ps_mm256_blendv_ps(src,add,mask)vbslq_f32loop+if
compress_mm512_mask_compressstoreu_psemulatedemulatedloop+if
gather_mm512_i32gather_ps_mm256_i32gather_psemulatedloop

Constants§

MAX_SIMD_LANES
Lane capacity of the fixed scalar-fallback stack buffers used by the default SimdKernel methods (scan_vector, swap_adjacent, dup_even/dup_odd, and the kernel_helpers scalar emulations). A backend’s SimdKernel::LANE_COUNT must not exceed this, or store_unaligned into those buffers would overflow the stack. The current workspace maximum is 64 (AVX-512 i8, 64×i8); the bound is checked at compile time by SimdKernel::LANE_BOUND_CHECK, so a future wider backend fails to build rather than silently overflowing the stack.

Traits§

SimdKernel
Abstract trait defining low-level vector operations.