Implementation Levels & Fallback Solver¶
Every MIPP function exists for all its datatypes on every supported target, through a 4-level fallback solver: if an architecture lacks a native hardware instruction for a given datatype or operation, MIPP resolves to the best emulation available, down to a scalar loop. The few configurations where a function compiles but is not implemented are listed in Known Limitations.
1. The 4 Implementation Levels¶
Because all MIPP functions are declared static inline, the compiler inlines them directly at call sites without function call overhead. The implementation levels differentiate functions strictly by their instruction mapping, instruction count, and level of vectorization. The same badges mark the levels in the API Explorer and the Function Support pages: L0 Native Hardware, L1 Dedicated Emulation, L2 Generic Emulation, L3 Scalar Fallback.
L0 Level 0: Native Hardware¶
- Definition: Direct 1:1 mapping to a single hardware vector instruction or vendor intrinsic provided natively by the target ISA for that datatype. The constants it needs do not count: a broadcast of a literal (
_mm512_set1_epi32(INT32_MIN),vdupq_n_f32(0.5f)) or an all-true predicate (svptrue_b32()) is materialized once, out of the loops, and a reinterpretation of a register (svreinterpret_u32_s32,vreinterpretq_u32_f32, the change of LMUL__riscv_vlmul_trunc_*of RVV) generates no instruction. For examplemipp_neg_float32_maskmon AVX-512 is_mm512_mask_xor_epi32with the sign bit, and the unpredicated SVE operations are their_xform undersvptrue. - Characteristics: Lowest possible instruction count, minimum latency, and maximum hardware pipeline throughput.
- Conventions: On the scalar target, the loops over the elements are the reference implementation and are reported as Level 0. A scalar form (
add_vs,sub_sv...) gets the level of its base function for the same datatype and mask variant, whatever its body: on SVE,mipp_sub_sv_float32_maskmisselect(m, sub(set1(s), b), b)and is reported as Level 0, like the maskedsub. - Examples:
mipp_add_float32on AVX \(\to\)_mm256_add_psmipp_add_float32on RVV \(\to\)__riscv_vfadd_vv_f32m1mipp_add_float32on ARM NEON \(\to\)vaddq_f32
L1 Level 1: Dedicated Emulation¶
- Definition: Target-specific emulation tailored to an ISA's instruction set when a single direct instruction is unavailable.
- Performance: High vector efficiency using handcrafted target assembly and intrinsic sequences.
- Examples:
- Horizontal reduction on AVX (
hadd_float32), using_mm256_permute2f128_ps,_mm256_shuffle_ps, and_mm256_add_psto perform in-register tree reduction across 256-bit lanes. - Vectorized
exp/logon AVX2 (exp_float32,log_float32), written once with AVX intrinsics (range reduction and polynomial evaluation on__m256) because the ISA has no instruction for them.
- Horizontal reduction on AVX (
L2 Level 2: Generic Emulation¶
- Definition: Vectorized algorithms implemented on top of standard MIPP primitives.
- Performance: Fully vectorized execution across all SIMD lanes without scalar unrolling.
- Examples:
- Composite arithmetic primitives on ISAs lacking dedicated instructions (e.g., emulating
fmadd(a, b, c)asadd(mul(a, b), c)on SSE or AVX without native FMA hardware). - Elementary math functions (such as vectorized
exp,log,sin,cospolynomial expansions) on the ISAs that have no dedicated implementation of them. - Software emulation of masked execution on targets lacking native instruction predication (evaluating unmasked operations and applying vector blending).
- Composite arithmetic primitives on ISAs lacking dedicated instructions (e.g., emulating
L3 Level 3: Scalar Fallback¶
- Definition: Automated fallback to sequential scalar element processing.
- Performance: Functional fallback path with sequential latency.
- Mechanics: The vector register is unpacked into scalar values, processed element-by-element via scalar operators, and repacked into the output vector register. The code is written so that the compiler can auto-vectorize it, without guarantee.
- Purpose: Guarantees that MIPP function calls compile on every target, allowing developers to write generic code across all supported datatypes regardless of hardware edge cases (see Known Limitations for the few remaining exceptions).
2. Inspecting Implementation Levels¶
Users can inspect the implementation level of any function through two mechanisms:
2.1. Header Comments¶
Every generated implementation in include/mipp/internal/simd_ext/<isa>/c/functions/<category>/... contains an explicit comment declaring its level (the short names without the _m1 suffix are aliases of these functions):
static inline vd_avx_float32_m1_t mipp_avx_add_float32_m1(const vd_avx_float32_m1_t vd0, const vd_avx_float32_m1_t vd1) {
// Level 0 (Native Hardware)
vd_avx_float32_m1_t res;
res.vd = _mm256_add_ps(vd0.vd, vd1.vd);
return res;
}
x86 has no shift of 8-bit lanes by per-lane counts, so rshift on int8 (counts in a register) falls back to the scalar reference on AVX. The registers are copied to the scalar type through a union, then the result is copied back (the #if defined(MIPP_AVX512) branch, the same with a d2 scalar register, is left out):
static inline vd_avx_int8_m1_t mipp_avx_rshift_int8_m1(const vd_avx_int8_m1_t vd0, const vd_avx_int8_m1_t vd1) {
// Level 3 (Scalar Fallback)
union { vd_avx_int8_m1_t v; vd_scalar_int8_m1_t s; } s_vd0;
memset(&s_vd0, 0, sizeof(s_vd0));
s_vd0.v = vd0;
union { vd_avx_int8_m1_t v; vd_scalar_int8_m1_t s; } s_vd1;
memset(&s_vd1, 0, sizeof(s_vd1));
s_vd1.v = vd1;
vd_scalar_int8_m1_t sres = mipp_scalar_rshift_int8_m1(s_vd0.s, s_vd1.s);
vd_avx_int8_m1_t res;
memcpy(&res, &sres, MIPP_MIN_SIZEOF(res, sres));
return res;
}
2.2. Hardware Support Documentation¶
The online documentation provides complete capability breakdowns:
- Hardware Support Dashboard: Displays implementation level breakdowns and coverage statistics across all target architectures.
- Universal Intersection Matrix: Gives, for each function and datatype, the lowest level reached on every target (the worst level among the ISAs, Level 3 included).
- API Reference: Each function reference page includes an interactive implementation matrix across all ISAs and masking modes.
3. Transitive Dependency Propagation & Hybrid Execution¶
In real-world SIMD code generation, algorithms are frequently composed of smaller primitives (e.g., polynomial evaluations, horizontal reductions, masking, or type casts). MIPP employs a transitive level propagation solver to guarantee both optimal hybrid execution and honest performance reporting:
3.1. Hybrid Vector-Scalar Execution (Performance Preservation)¶
When an operation is implemented via a composite template (such as elementary math functions or generic masked wrappers):
- If the majority of sub-operations are vectorized (Levels 0, 1, or 2), but a single helper operation requires a Level 3 scalar fallback on that specific target, MIPP does not discard the vector template.
- Dropping an entire multi-step function down to an element-by-element loop (
auto_scalar) would discard the massive throughput gains provided by the 90%+ vectorized operations. - Instead, MIPP generates the hybrid SIMD + scalar implementation, preserving the hardware vector acceleration across all available instructions.
3.2. Transitive Bottleneck Propagation (Honest Classification)¶
While the hybrid implementation is emitted for optimal execution, its official implementation level in the API reference matrices, header comments, and dashboard is determined by the weakest link in its dependency graph:
- Pure Vector Path: If a Level 2 generic algorithm only invokes Level 0, 1, or 2 sub-operations, its effective level remains Level 2 (Generic Emulation).
- Transitive Scalar Fallback: If a Level 2 (or Level 1) template invokes at least one operation that transitively resolves to a Level 3 scalar fallback on the target architecture, its effective level is evaluated as: $\(\max(2, 3) = \mathbf{3}\)$ It is classified and documented as Level 3 (Scalar Fallback).
Note
Concrete Example: On AVX, the masked rshift on int8 is the generic composition select(m, rshift(a, b), a) (Level 2). select is vectorized (_mm256_blendv_epi8 with AVX2), but rshift on int8 is a scalar fallback (see §2.1), so mipp_avx_rshift_int8_maskm is reported as Level 3 even though the select stays vectorized.
4. Performance Considerations Across Levels¶
Understanding implementation levels helps users interpret profiling data and compiler assembly:
- Levels 0, 1, and 2 (Vectorized SIMD Paths):
- Level 0, Level 1, and Level 2 are all fully vectorized and highly performant.
- A function marked as Level 1 (Dedicated Emulation) or Level 2 (Generic Emulation), such as composite arithmetic (
fmaddwithout FMA hardware), horizontal reductions (hadd,hmax,hmin), or elementary math functions (exp,log,sin,cos), simply indicates that the target ISA lacks a dedicated, single hardware instruction for that operation. MIPP executes these via fully vectorized SIMD instruction sequences with no scalar serialization. One exception: the genericsin,cosandtancall the libm for the lanes with \(|x| > 8192\) (float) or \(|x| > 2^{50}\) (double), and for infinities and NaN; this path is only taken when such a lane is present.
- Level 3 (Scalar Fallback):
- Level 3 is the only level where the generated source code can be sequential element-by-element rather than explicit SIMD instructions (a Level 3 reached by propagation, §3.2, keeps its vector parts). In some cases, this code can be auto-vectorized by the compiler.
- While Level 3 guarantees complete API coverage and functional correctness, performance-critical inner loops should avoid relying on Level 3 fallbacks. If a hotspot hits a Level 3 implementation, consider:
- Checking if an alternative datatype has native hardware support on that architecture (e.g., using
float32on architectures lacking 64-bit hardware floating-point units). - Contributing a Level 1 (Dedicated Emulation) or Level 2 (Generic Emulation) implementation to the MIPP codebase.
- Checking if an alternative datatype has native hardware support on that architecture (e.g., using
5. Known Limitations¶
The fallback hierarchy covers every (function, datatype, LMUL, mask variant, ISA) combination on the main configurations of each target. In two configurations, a few functions compile but are not implemented yet:
| Configuration | Affected functions |
|---|---|
NEON on ARMv7 (32-bit Arm, no __aarch64__) |
float64 half-vectors (d2): loads and stores (storent, loadu_ff, loadu_strided, storeu_strided, loadu_unzip2 to 4 and storeu_zip2 to 4 included), gathers, scatters, reductions (argmin, argmax, findfirst and findlast included), set, set_k, iota, firstn, testz, none, any, all, count, combine (also on masks); and the functions that turn an m1 register into a d2 one or back for float64 (lo and hi, also on masks, ncvt to float32, wcvt and wmul from float32). |
RVV without 64-bit elements or with VLEN < 128 (__riscv_v_elen < 64, __riscv_v_elen_fp < 64 for float64, or __riscv_v_fixed_vlen < 128, as with the Zve32* and Zve64* embedded profiles) |
Most 64-bit half-vector (d2) operations, and lo, hi, combine (also on masks), wcvt, wmul, ncvt, ncvts and ncvtsrshiftround on 64-bit elements at every LMUL. With MIPP_RVV_LDIV_VL or MIPP_RVV_LDIV_HYBRID (Vector Types & LMUL §4.3), the 64-bit half-vectors are native when the core has 64-bit elements. |
With the standard RVV V extension (VLEN \(\ge\) 128, 64-bit elements) and on AArch64, every function is implemented. When one of the functions above is called, it reports the following message, then terminates the program in C (exit(-1)) or throws mipp::stub_exception in C++: