Developer Guide Overview¶
This guide is for contributors who add functions, implementations or targets to MIPP, or who work on the generators themselves. To use MIPP in an application, read the User Guide instead.
MIPP has no hand-written vector code. The headers in include/, the unit tests in tests/src/{c,cpp,obj}/ and the reference pages of this site are generated from a database of JSON files in generator/. Contributing to MIPP means editing that database, then regenerating. The only hand-written tests are in tests/src/manual/, with the helpers of tests/src/utils/ and tests/src/main.cpp (see Unit Tests).
| I want to... | Read |
|---|---|
| Generate the headers, build and run the tests | Setup |
Add a new function (e.g. absdiff) |
Add a Function |
| Make an existing function faster on one target | Add an Implementation |
| Support a new instruction set | Add an ISA |
| Understand a warning or an error of the generator | Audits & Validation |
| Look up an option of a generator or a field of a JSON file | Command-Line, Registries |
| Name a new function, type, parameter or template | Naming Conventions |
| Work on the generators themselves | Internals |
| Understand the CI or publish a release | Continuous Integration, Release |
1. The Generation Pipeline¶
- Inputs. The core registries declare each function once (prototype, datatypes, masking variants, scalar reference). Each ISA directory describes the registers of one target and maps functions to intrinsics. The test specifications tune the input domains and tolerances of the generated tests.
- Checks. Every file is validated against its JSON Schema, and the cross-references between files are checked. A validation error stops the generator. The audits only print warnings. See Audits & Validation.
- Candidate resolution (
generator/helpers_headers/codegen/). For each combination of function, datatype, mask variant, LMUL and ISA, the resolver collects the candidate implementations and keeps the first one whose dependencies are available, in the order L0, L1, L2, L3. The Implementation Levels page describes the four levels from the user side, and Code Generation the resolver itself. - Emission.
gen_mipp_headers.pywrites the three APIs.gen_mipp_docs.pyruns the same resolution to fill the Function Support and Hardware Support pages and the API Explorer data.gen_mipp_tests.pydoes not need the resolution: each generated test compares the API under test with the scalar reference.
2. Invariants¶
These rules hold for the whole code base. The tutorials rely on them.
- Generated files are never edited.
include/,tests/src/{c,cpp,obj}/,docs/funcs_support/,docs/isas_support/,docs/assets/data/,docs/includes/generated/,docs/developer/reference/cli.mdanddocs/developer/reference/registries/are ignored by Git and overwritten at each generation. Fix the JSON input or the generator instead. - The scalar reference is the specification. Every declared function has a scalar implementation for exactly its declared datatypes, otherwise the generator stops. This implementation is both the L3 fallback and the reference of every generated test.
- Every combination exists on every generated ISA. If no L0, L1 or L2 candidate applies, the resolver emits the L3 fallback, which converts the registers to scalar arrays and calls the scalar reference. The exceptions are a few functions on 64-bit elements in some configurations (
float64on ARMv7 NEON, 64-bit elements on RVV withELEN< 64 orVLEN< 128): they compile, but stop at run time when called, with aMIPP_PANIC_STUBmessage. Known Limitations lists them. - Conditions split, they do not replace. An entry with an
ifcondition is emitted under#if <condition>. For the rest of the condition space, the resolver keeps looking for another candidate. For instance, an AArch64-only native entry gives L0 under#if defined(__aarch64__)and the L3 fallback under#if !defined(__aarch64__). - Levels propagate. The effective level of an L1 or L2 implementation is the highest level among its dependencies. An L2 sequence that calls an L3 function is reported as L3. The summary table of
gen_mipp_headers.pyand the API Explorer report effective levels. - ISAs are discovered. Each directory of
generator/simd_ext/is an ISA. Adding a target does not require any change in the Python code. - JSON files are sorted. The top-level keys of every JSON file of
generator/, except the JSON Schemas, are sorted alphabetically (checked by thejson-structureaudit).
3. Glossary¶
| Term | Meaning |
|---|---|
| Function | An entry of registry_interfaces.json, such as add. Its C names follow mipp_<function>_<type>[_<variant>][_<lmul>] (mipp_add_float32_maskz_m2). |
| Datatype | One of the 10 element types: float64, float32, int64, int32, int16, int8, uint64, uint32, uint16, uint8. Conversions use datatype pairs (float32,int32). Aliases such as all_float or all_int are listed in DATATYPES_MAP (generator/helpers_headers/tools.py). |
| Prototype | An abstract signature of registry_protos.json, such as ret_reg_2args_reg (two registers in, one register out). |
| Mask variant | unmasked, maskm (Merge-Masked, M), maskz (Zero-Masked, Z) or masks (Source-Masked, S). A function declares the variants it supports with variants (a list of u, m, z, s that contains u). See Masking Semantics. |
| LMUL | Register multiplier: 1, 2, 4, 8, and -2 for half-vectors (d2). An ISA lists the LMUL values it emulates in software (sw_lmul) or supports in hardware (hw_lmul). See Vector Types & LMUL. |
| ISA, SIMD extension | A target backend: one directory of generator/simd_ext/ (sse, avx, avx512, neon, sve, rvv, and the special scalar). |
| Level | L0 native, L1 dedicated emulation, L2 generic emulation, L3 scalar fallback. The source of an implementation determines its level: <isa>_native_*.json (L0), <isa>_emu_*.json (L1), generic_emu_*.json (L2), scalar reference (L3). |
| Template | A code snippet (Jinja2 plus the templating DSL) stored in a *_templates.json file. |
| Implementation entry | An element of a *_implems.json file: it maps a function and a set of datatypes to a template, with an optional if condition. |
| Candidate | An implementation entry, or the automatic L3 fallback, considered by the resolver for one function, datatype, mask variant, LMUL and ISA. |
| Layer | A unit of regeneration of gen_mipp_headers.py: one per ISA, plus wrappers (the public C, C++ Functional and C++ Object headers). |
| Granularity | Layout of the public headers: coarse (one header per function) or fine (also one atom per variant and LMUL, grouped by umbrella headers). See Headers & Compile Time. |
| API, dialect | C, C++ Functional and C++ Object. The test generator calls them c, cpp and obj. |
4. Directory Layout of generator/¶
All the generators are run from this directory (see Setup).
generator/
├── gen_mipp_headers.py # Header generator (C, C++ Functional, C++ Object), public per-function headers
├── gen_mipp_tests.py # Test generator (Catch2 sources in tests/src/)
├── gen_mipp_docs.py # Generated pages of the documentation
├── gen_mipp_api_data.py # API Explorer data (called by gen_mipp_docs.py)
├── requirements.txt # Python dependencies (Jinja2, jsonschema, colorama)
│
├── helpers_docs/ # Helpers of gen_mipp_docs.py: CLI and Registries reference, Algorithm modal data,
│ # scalar simulator, tables of the hand-written pages, test properties of the
│ # Function Support pages
│
├── helpers_headers/ # Header generation engine and core registries
│ ├── registry_interfaces.json # Declaration of every function
│ ├── registry_protos.json # Abstract prototypes
│ ├── registry_categories.json # Function categories
│ ├── registry_scalar_implems.json # Scalar reference (Level 3)
│ ├── registry_scalar_isa.json # Descriptor of the scalar target
│ ├── registry_utilities.json # Hand-written utilities (mipp_malloc, dump, transpose...) for the API Explorer
│ ├── generic_emu_templates*.json # Generic emulation templates (Level 2)
│ ├── generic_emu_implems*.json # Generic emulation entries (Level 2)
│ ├── generic_ldiv_mask.json # Generic half-vector templates: LMUL-changing functions (lo, hi, combine, wcvt,
│ │ # wmul, ncvt, ncvts, ncvtsrshiftround, the _k versions), d2 loads and stores
│ │ # (strided, interleaved, first-faulting), gather, scatter, set, reductions, tests
│ ├── funcs_docs.json # Function descriptions and formulas
│ ├── jinja_keywords.json # Jinja2 keywords (not parsed as DSL placeholders)
│ ├── schemas/ # JSON Schemas of all the registries and ISA files
│ ├── templates/ # Static header templates (mipp_info, Object API, utilities, ...)
│ ├── codegen/ # Candidate resolver, LMUL orchestrator, half-vectors, immediate versions,
│ │ # emission helpers
│ ├── registry.py # Loads and validates the registries
│ ├── input_validation.py # Validation checks and header audits
│ ├── tools.py # DSL parsing, datatype aliases, ISA loading
│ ├── datatypes.py # Datatypes, categories and datatype pairs
│ ├── forms.py # Scalar forms (add_vs, ...), derived when the registry is loaded
│ ├── luts.py # Constant tables computed for the templates (compress_lut, iota, ...)
│ ├── name_builder.py # Function names, prototypes and call arguments
│ ├── cond_utils.py # Preprocessor condition parsing and simplification
│ ├── include_gen.py # IncludeManager: header layout and dependencies
│ ├── c_generator.py # Per-ISA C implementation headers
│ ├── ci_generator.py # C API dispatch headers
│ ├── cpp_generator.py # C++ Functional API (namespace mipp)
│ ├── utils_generator.py # Utilities of the three APIs, rendered from templates/ (malloc, dump, transpose...)
│ └── obj_generator.py # C++ Object API (Vd, Vm) and its internal per-function headers
│
├── helpers_tests/ # Test generation engine
│ ├── tests_builder.py # Test engine and test audits
│ ├── dialect_adapters.py # C, C++ Functional and C++ Object syntax adapters
│ ├── domain_resolver.py # Input domains and mask patterns
│ ├── indexed_tests.py # Tests of the indexed accesses (gather, scatter)
│ ├── perm_tests.py # Tests of permute, permute2, permute_b128, compress, expand, storeu_compress,
│ │ # storeuf_compress and loadu_expand
│ ├── interleaved_tests.py # Tests of loadu_unzip2/3/4 and storeu_zip2/3/4
│ ├── dot_tests.py # Tests of the functions whose registers have different types (dot2, dot4,
│ │ # dot4us, wmul)
│ ├── strided_tests.py # Tests of loadu_strided and storeu_strided
│ ├── tests_specs.json # Per-function test properties
│ ├── tests_templates.json # Test code templates
│ └── schemas/ # JSON Schemas of the two files above
│
└── simd_ext/ # One directory per target
├── scalar/ # scalar_gen.py (emits the scalar target from the registries), scalar_explorer.json
├── sse/ # SSE to SSE4.2
├── avx/ # AVX, AVX2, FMA
├── avx512/ # AVX-512F, BW, DQ, ...
├── neon/ # Arm NEON (ARMv7, ARMv8-A)
├── sve/ # Arm SVE
└── rvv/ # RISC-V Vector 1.0
Each ISA directory holds <isa>_isa.json, <isa>_native_templates.json and <isa>_native_implems.json, plus the optional <isa>_emu_*.json (L1), <isa>_imm_templates.json and <isa>_imm_implems.json (bodies for a constant integer argument), <isa>_ldiv_mask.json (half-vectors and functions that change the LMUL), <isa>_sw_lmul.json (wcvt / ncvt of the software LMUL written by the ISA) and <isa>_explorer.json (API Explorer metadata). See Add an ISA.