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.

ModulesΒ§

avx2 πŸ”’

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.

EnumsΒ§

Backend πŸ”’
Which instruction set an engine dispatches to.
SimdKind πŸ”’
Which accelerated alphabet family an engine uses. Selects the kernel monomorphization at runtime.
Standard πŸ”’
The STANDARD alphabet family (+// at 62/63).
UrlSafe πŸ”’
The URL_SAFE alphabet family (-/_ at 62/63).

ConstantsΒ§

BITPOS_LUT πŸ”’
pshufb decode validity table: maps a high nibble to a single set bit. Shared by both alphabets.
SIMD_MIN_INPUT_DECODE πŸ”’
SIMD_MIN_INPUT_ENCODE πŸ”’
Minimum input length before a SIMD path is used. Below these the setup cost outweighs the gain; encode needs more data than decode to break even.

TraitsΒ§

SimdAlphabet πŸ”’
A base64 alphabet family the SIMD kernels can accelerate.

FunctionsΒ§

avx2_decode πŸ”’ ⚠
Dispatch the AVX2 decode kernel to the right alphabet monomorphization.
avx2_encode πŸ”’ ⚠
Dispatch the AVX2 encode kernel to the right alphabet monomorphization.