Skip to main content

Module simd

Module simd 

Source
Expand description

SIMD-accelerated engines for the standard and URL-safe alphabets.

These are gated behind the simd-unsafe feature because they use unsafe. Three engines are provided:

  • Simd detects the best available instruction set at runtime and falls back to the scalar GeneralPurpose engine when none is available. It requires std for the detection.
  • Avx2 and Neon target a specific instruction set with no runtime detection, so they can be used in no_std builds when the target is known to support the instructions.

Only the STANDARD and URL_SAFE alphabets are accelerated (they share indices 0..=61 and differ only at 62/63). Each engine therefore has dedicated standard / url_safe constructors rather than taking an arbitrary Alphabet; use GeneralPurpose for any other alphabet.

The kernels follow Wojciech Mula’s vectorized base64 algorithms (http://0x80.pl/notesen/2016-01-17-sse-base64-decoding.html and the companion encoding note). AVX2 uses the multiply-based bit (de)interleave; NEON, which lacks the relevant multiplies, uses the shift/mask variant. Both share the same per-alphabet lookup tables, expressed as the associated constants of the SimdAlphabet trait so the kernels can inline them.

Structs§

Avx2
A base64 engine that unconditionally uses AVX2, without runtime detection.
Simd
A base64 engine that uses the best SIMD instruction set detected at runtime, falling back to the scalar GeneralPurpose engine.