base64 using SIMD instructions
Repository contains code for encoding and decoding base64 using SIMD instructions. Depending on CPU's architecture, vectorized encoding is faster than scalar versions by factor from 2 to 4; decoding is faster 2 .. 2.7 times.
There are several versions of procedures utilizing following instructions sets:
- BMI2, and
- ARM Neon.
Vectorization approaches were described in a series of articles:
- Base64 encoding with SIMD instructions,
- Base64 decoding with SIMD instructions,
- Base64 encoding & decoding using AVX512BW instructions (includes AVX512VBMI and AVX512VL),
- AVX512F base64 coding and decoding.
Daniel Lemire and I wrote also paper Faster Base64 Encoding and Decoding Using AVX2 Instructions which was published by ACM Transactiona on the Web.
Performance results from various machines are located
There are separate subdirectories for both algorithms, however both have the same structure. Each project contains four programs:
verify--- does simple validation of particular parts of algorithms,
check--- validates whole procedures,
speed--- compares speed of different variants of procedures,
benchmark--- similarly to
speedbut works on small buffers and calculates CPU cycle rate (available only for Intel architectures).
Change to either directory
decode and then use following
||scalar, SSE, BMI2|
||scalar, SSE, BMI2, AVX2|
||scalar, SSE, BMI2, AVX2, AVX512F|
||scalar, SSE, BMI2, AVX2, AVX512F, AVX512BW|
||scalar, SSE, BMI2, AVX2, AVX512F, AVX512BW, AVX512VBMI|
||scalar, SSE and AMD XOP|
||scalar, ARM Neon|
make run (for SSE) or
make run_ARCH to run all programs for given
ARCH can be "sse", "avx2", "avx512", "avx512bw",
BMI2 presence is determined based on
/proc/cpuinfo or a counterpart.
When an AVX2 or AVX512 targets are used then BMI2 is enabled by default.
To compile AVX512 versions of the programs at least GCC 5.3 is required. GCC 4.9.2 doesn't have AVX512 support.
Please download Intel Software Development Emulator in order to run AVX512
The emulator path should be added to the
Both encoding and decoding don't match the base64 specification, there is no processing of data tail, i.e. encoder never produces '=' chars at the end, and decoder doesn't handle them at all.
All these shortcoming are not present in a brilliant library by Alfred Klomp: https://github.com/aklomp/base64.
- Daniel's benchmarks and comparison with state of the art solutions https://github.com/lemire/fastbase64