Skip to main content

Crate wickra_simd

Crate wickra_simd 

Source
Expand description

Runtime SIMD dispatch for the Wickra technical indicators core.

Release binaries are built for the baseline of their target — on x86_64 that is SSE2, with no AVX and no fused multiply-add instruction — so they run on every CPU of the architecture. A batch kernel that would profit from AVX2 lanes or a hardware FMA therefore cannot simply be compiled for them. dispatch closes that gap: it checks the CPU once (the standard library caches the answer) and runs a Kernel inside a function compiled with AVX2 and FMA enabled when both are present, and in the baseline build otherwise. A kernel that opts in (Kernel::WIDE) runs with AVX-512F enabled as well where the CPU has it, and does its element-wise work in eight-lane Simd::W values: one 512-bit register there, two four-lane vectors everywhere else.

§Same result on every path

Dispatch changes how a kernel is compiled, never what it computes. Rust evaluates floating-point code exactly as written — it never reassociates, and never contracts a * b + c into a fused multiply-add — so the AVX2 build and the baseline build of one kernel perform the same IEEE-754 operations in the same order. f64::mul_add is correctly rounded whether it becomes the FMA instruction or the C library’s fma, and an eight-lane operation is the same IEEE-754 operation on each lane whether the lanes sit in one register or two. Every path therefore returns bit-identical values; the crate’s tests check exactly that, at every level the machine has.

The AVX-512 level needs Rust 1.89 or later, where its target feature is stable; built by an older compiler the crate has no such level, and a kernel that opts in runs at the AVX2 one – the same bits, at the AVX2 speed.

On aarch64, NEON and FMA are part of the baseline, so kernels already get them and dispatch runs them directly.

§Writing a kernel

Implement Kernel and mark Kernel::run #[inline(always)], as well as any helper it calls: code is only compiled with the enabled features if it is inlined into the dispatching function.

Structs§

Avx2
Proof that this CPU implements AVX2 and FMA; only crate::dispatch makes one.
Avx512
Proof that this CPU implements AVX-512F (and so AVX2 and FMA); only crate::dispatch makes one.
Portable
Lanes as [f64; 4] in ordinary Rust arithmetic.

Enums§

Level
The instruction set dispatch selects on this machine.

Traits§

Kernel
A unit of work dispatch can run with the best instruction set available.
Simd
Four f64 lanes and the operations the Wickra kernels are built from.

Functions§

dispatch
Run kernel with the best instruction set this CPU offers.
level
The instruction set dispatch runs kernels with on this machine.
run_baseline
Run kernel in the baseline build with the Portable lanes, never dispatching. Exists so tests (in this crate and in its users) can prove a kernel returns the same bits on every path.