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,
- 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 three programs:
verify--- does simple validation of particular parts of algorithms,
check--- validates whole procedures,
speed--- compares speed of different variants of procedures.
||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_avx512 or
to run all programs.
BMI2 presence is determined based on
/proc/cpuinfo or 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 hasn't got 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