MIPP is a header-only SIMD library for C11 and C++11. The same code compiles for SSE, AVX, AVX-512, NEON, SVE and RVV, and falls back to emulation or scalar code where an instruction is missing. The headers are generated from a declarative registry of functions and implementations.
Note
MIPPv2 is under active development on the develop branch: its API may still
change between v2.x tags. MIPPv1 remains available on the master branch.
- Three APIs, one implementation: C (
<mipp.h>), C++ Functional (<mipp.hpp>) and C++ Object with overloaded operators (<mipp_obj.hpp>). - Fallback guarantee: every function compiles on every target for each of its datatypes (most functions take the 10 datatypes), through native instructions, a dedicated emulation, a generic emulation built on other MIPP functions, or a scalar loop (known limitations).
- Register grouping and masking: LMUL 2, 4, 8 and half-vectors, and four masking variants (unmasked, merge, zero, source) on all targets.
- Header-only: no library to build. Fine-grained headers (one function, variant and LMUL) make compilation 2× to 4× faster than the umbrella header.
| Architecture | Instruction sets |
|---|---|
| x86 | SSE, AVX, AVX-512 |
| ARM | NEON, SVE (vector length fixed at compile time) |
| RISC-V | RVV 1.0 (vector length fixed at compile time) |
| Any | Scalar fallback |
Leaky ReLU (y = x > 0 ? x : alpha * x) with the C++ Object API:
#include <cstdlib>
#include <iostream>
#include <vector>
#include <mipp_obj.hpp>
void leaky_relu(float alpha, const float* x, float* y, size_t size)
{
constexpr size_t N = mipp::Vd<float>::N(); // elements per register (e.g. 8 with AVX2)
const size_t vec_end = (size / N) * N;
// 1. Vector main loop
for (size_t i = 0; i < vec_end; i += N) {
mipp::Vd<float> vx(&x[i]); // load
mipp::Vm<float> pos = vx > 0.f; // comparison -> mask
mipp::Vd<float> vy = mipp::select(pos, vx, vx * alpha); // branch-free
mipp::storeu(&y[i], vy);
}
// 2. Scalar tail loop for the remaining elements
for (size_t i = vec_end; i < size; i++)
y[i] = x[i] > 0.f ? x[i] : alpha * x[i];
}
int main()
{
std::vector<float> x(1007), y(1007);
for (size_t i = 0; i < x.size(); i++)
x[i] = (i % 2) ? 2.0f : -2.0f;
leaky_relu(0.1f, x.data(), y.data(), x.size());
std::cout << "y[0] = " << y[0] << ", y[1] = " << y[1] << " (expected -0.2, 2)" << std::endl;
return (y[1006] == -0.2f && y[1005] == 2.0f) ? EXIT_SUCCESS : EXIT_FAILURE;
}The same loop body with the C API and the C++ Functional API (vzero and
valpha hold the broadcast constants):
vd_float32_m1_t vx = mipp_loadu_float32_m1(&x[i]);
vm_float32_m1_t pos = mipp_cmpgt_float32_m1(vx, vzero);
vd_float32_m1_t vy = mipp_select_float32_m1(pos, vx, mipp_mul_float32_m1(vx, valpha));
mipp_storeu_float32_m1(&y[i], vy);mipp::vd<float> vx = mipp::loadu<float>(&x[i]);
mipp::vm<float> pos = mipp::cmpgt(vx, vzero);
mipp::vd<float> vy = mipp::select(pos, vx, mipp::mul(vx, valpha));
mipp::storeu(&y[i], vy);The headers are generated and not stored in the repository. Either download
mipp-<version>-headers.tar.gz (or .zip) from the
releases, or generate them:
cd generator
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
./gen_mipp_headers.py # writes ../include/Then add the include/ directory to the include path and select the target
with the usual compiler flags:
g++ -std=c++11 -O3 -march=native -I/path/to/mipp/include leaky_relu.cpp -o leaky_reluSee Getting Started for the flags of each instruction set and Headers & Compile Time for the fine-grained headers.
The documentation is online at aff3ct.github.io/MIPP:
- Getting Started: installation, compiler flags, a first vectorized loop
- API Explorer: search every function, including by vendor intrinsic
- Programming Model: the C, C++ Functional and C++ Object APIs
- Why MIPPv2: design and comparison with Highway, xsimd, Eve and others
- Migrating from MIPPv1: what changes, the functions whose result changes, the correspondence tables
- Specifications: semantics and implementation matrix of each function
- Developer Guide: generation pipeline, adding a function, an implementation or an ISA
MIPP is supported by:
MIPP is released under the MIT License.
