Skip to main content

Module arithmetic

Module arithmetic 

Source
Expand description

SIMD-accelerated batch arithmetic operations.

All public functions in this module are slice-iterating wrappers over the 4-lane kernels in crate::asm_presets. The inner kernels emit explicit AVX2 / FMA instructions via core::arch::asm! — there is no reliance on the compiler’s auto-vectorizer (simd_review §1).

Each wrapper:

  1. Checks AVX2 availability once per process via HAS_AVX2.
  2. Splits the input into 4-element chunks aligned to the kernel width.
  3. Calls the kernel per chunk.
  4. Processes the trailing 0..3 elements with the scalar fallback, guaranteeing bit-identical results across vectorized / scalar paths.

Feature detection is hoisted out of the per-chunk inner loop using a OnceLock<bool>is_x86_feature_detected! touches an MMIO-mapped CPUID leaf on x86_64 and should not be called on every inner iteration.

Enums§

BatchError
Reasons a batch arithmetic operation cannot proceed.

Functions§

batch_abs
Batch element-wise absolute value: result[i] = |inp[i]|.
batch_add
Batch element-wise addition: result[i] = lhs[i] + rhs[i].
batch_add_scalar
Batch scalar addition: result[i] = lhs[i] + scalar.
batch_cmp_eq
Batch IEEE-754 equality: mask[i] = 0xFF if lhs[i] == rhs[i], else 0x00. NaN never equals NaN.
batch_coef_merge
Batch symbolic coefficient merge: out[i] = (coef_a[i] * coef_b[i]) * (var_x[i] * var_y[i]).
batch_div
Batch element-wise division: result[i] = lhs[i] / rhs[i].
batch_eval
Evaluates a JIT-compiled expression for each row of var_sets.
batch_eval_parallel
Parallel variant of batch_eval that splits rows into chunks and evaluates each chunk on a separate fiber from the dtact runtime pool.
batch_fma
Batch fused multiply-add: out[i] = lhs[i] * rhs[i] + addend[i] with single-rounding semantics when FMA is available.
batch_mul
Batch element-wise multiplication: result[i] = lhs[i] * rhs[i].
batch_neg
Batch element-wise negation: result[i] = -inp[i].
batch_pow
Batch element-wise pow: result[i] = base[i] ^ exp[i].
batch_sqrt
Batch element-wise square root: result[i] = sqrt(inp[i]).
batch_sub
Batch element-wise subtraction: result[i] = lhs[i] - rhs[i].