Skip to main content

Module base64

Module base64 

Source
Expand description

Base64 (RFC 4648) encode and decode: NEON on ARM64, AVX2/SSSE3 on x86_64, scalar elsewhere.

Decoding is strict: no whitespace, padding exactly as the engine says, and the unused bits of the last group must be zero, so every byte string has one accepted encoding.

§Performance (x86_64 AVX2, encode_to_string / decode_to_vec, allocation included)

bytesencodedecodedecode, base64-simd 0.8
4820 ns17 ns25 ns
60071 ns55 ns93 ns
64 K6.2 µs4.9 µs8.5 µs

Encoding is level with base64-simd from 32 bytes up.

§Algorithm

NEON: vld3/vst4 de-interleave 48 bytes into 64 indices, and a 64-entry tbl4 maps them to the alphabet. Decoding runs the same in reverse over a 128-entry tbl4/tbx4 table.

SSSE3/AVX2: Muła and Lemire’s multiply-shift split and pshufb offset lookup. Decode validation classifies each byte by nibble pair (lut_lo[lo] & lut_hi[hi]), with tables built at compile time from the alphabet, so the URL-safe engine uses the same code.

Structs§

DecodeError
Engine

Constants§

STANDARD
The standard alphabet, padded.
URL_SAFE_NO_PAD
The URL-safe alphabet, unpadded.