Header Layout¶
This page describes the tree that gen_mipp_headers.py writes in include/, and how the IncludeManager (generator/helpers_headers/include_gen.py) decides which file receives each function and which headers it includes. The user side of the same tree (which header to include, compile times) is described in Headers & Compile Time.
1. Tree¶
include/
├── mipp.h, mipp.hpp, mipp_obj.hpp # Global headers: C, C++ Functional, C++ Object
└── mipp/
├── c/ {cat,fun}/, utils.h # Public headers of the C API
├── cpp/ {cat,fun}/, utils.hpp # Public headers of the C++ Functional API
├── obj/ {cat,fun}/, utils.hpp # Public headers of the C++ Object API
└── internal/
├── interfaces/
│ ├── c/ # C API: dispatch to the selected ISA
│ ├── cpp/ # C++ Functional API: dispatch to the selected ISA
│ └── obj/ # C++ Object API (Vd, Vm)
├── templates/cpp/ # Declarations of the C++ function templates
└── simd_ext/<isa>/
├── c/ # Resolved implementations of one ISA
│ ├── common.h # Register types and ISA macros
│ ├── mipp_<isa>.h # Includes every function of the ISA
│ └── functions/<category>/...
└── cpp/ # C++ overloads of one ISA (mipp::vd<T,LMUL,ISA>)
The public headers contain nothing but #include lines to mipp/internal/: mipp/cpp/fun/add.hpp includes mipp/internal/interfaces/cpp/functions/arithmetic/add.hpp. Users never include mipp/internal/ directly. The utils.h(pp) headers are the exception: they hold the hand-written utilities of each API (aligned allocation, printing, reduce), rendered by utils_generator.py from generator/helpers_headers/templates/mipp_utils.tpl.h, mipp_utils.tpl.hpp and mipp_obj_utils.tpl.hpp, on top of the generated functions; the global headers include them. So do mipp/cpp/patterns.hpp and mipp/obj/patterns.hpp (mipp_patterns.tpl.hpp, mipp_obj_patterns.tpl.hpp): the permutations whose pattern is known at compile time, permute<P> and permute2<P>, under #if __cplusplus >= 201703L (C++17 extras of a C++11 API). They pull about 20 rearrangement functions, so only mipp.hpp and mipp_obj.hpp include them, not the utils.hpp headers; with fine-grained headers, they include the unmasked granules only (mipp/cpp/fun/u/<function>.hpp, found with __has_include). mipp/c/transpose.h, mipp/cpp/transpose.hpp and mipp/obj/transpose.hpp (mipp_transpose.tpl.h, mipp_transpose.tpl.hpp, mipp_obj_transpose.tpl.hpp) are included the same way, by the three global headers: transpose and transpose_b128, steps of ziplo / ziphi on an array of registers (one C function per datatype and LMUL).
2. Layers¶
The IncludeManager handles one layer per output directory of the C and C++ Functional code. A function is written once per layer:
| Layer | Directory (in include/mipp/internal/) |
Written by |
|---|---|---|
<isa> |
simd_ext/<isa>/c/ |
c_generator.py (Code Generation), simd_ext/scalar/scalar_gen.py |
<isa>_cpp |
simd_ext/<isa>/cpp/ |
cpp_generator.py |
c |
interfaces/c/ |
ci_generator.py |
cpp |
interfaces/cpp/ |
cpp_generator.py |
templates |
templates/cpp/ |
cpp_generator.py |
For these layers, the generators do not open the function headers themselves: they ask the manager for a file object with get_fd(layer, function, variant, lmul), and the manager chooses the path according to the granularity. The other files are written directly, outside the IncludeManager:
- the C++ Object API,
interfaces/obj/(obj_generator.py), with its own atoms and umbrellas in fine granularity; - the global headers
mipp.handmipp.hpp(generate_mipp_h()ininclude_gen.py,cpp_generator.py),mipp_obj.hpp(obj_generator.py) andtemplates/cpp/common.hpp(cpp_generator.py); - the public headers of
mipp/{c,cpp,obj}/(generate_public_headers()ingen_mipp_headers.py); - the utilities, patterns and transpositions (
utils_generator.py).
3. Coarse Granularity¶
With --granularity coarse (default), each layer has one header per function, functions/<category>/<function>.h (.hpp for the C++ layers). This header contains every datatype, mask variant and LMUL of the function. Its includes are computed after the layer is generated, from the dependencies recorded during the resolution (resolve_all_dependencies()), plus:
- the scalar header of the function, for the L3 fallbacks (and the scalar
tovd/tovmheaders when the fallback converts hardware masks); - the header of the
sub_isafor the ISAs whose half-vectors are built on it ("sw_ldiv_type": "sub_isa"); - the headers of the functions called by the code that the resolution does not see (the half-vector templates, the software LMUL bodies of the functions that change the LMUL), recorded with
add_call_dependency().
4. Fine Granularity¶
With --granularity fine, the functions are split into atoms, one per function, mask variant and LMUL (the templates layer stays coarse):
functions/<category>/<v>/<l>/<function>.h
<v>: u (unmasked), m (Merge-Masked), z (Zero-Masked), s (Source-Masked)
<l>: m1 (LMUL 0 and 1), m2, m4, m8, d2
Each atom includes exactly what its functions call: the atoms of its dependencies (same ISA), the scalar atoms for the L3 fallbacks, the atom of half the LMUL for the software LMUL wrappers, the sub_isa atom for the half-vectors, the scalar d2 atom for the lane-crossing half-vectors by mask, the atoms recorded with add_call_dependency() (in the atom of the caller's LMUL: m1 for ncvtsrshiftround, whose argument is m1 and result d2), and the atoms whose functions appear in the emitted body. The atoms are written to memory first and flushed with their includes at the end of the layer; an atom left empty (no wcvt from m8, no lo from d2) is not written, and the umbrellas do not include it.
Umbrella headers group the atoms (generate_umbrella_headers()):
| Umbrella | Includes |
|---|---|
functions/<category>/<v>/<function>.h |
the atoms of one mask variant, every LMUL |
functions/<category>/<l>/<function>.h |
the atoms of one LMUL, every mask variant |
functions/<category>/<function>.h |
the whole function (same path as the coarse header) |
The public headers follow the same scheme: mipp/cpp/fun/m/m2/add.hpp includes one atom, mipp/cpp/fun/add.hpp the whole function. The coarse public headers therefore exist with both granularities.
5. ISA Dispatch¶
The interface layers select the ISA at compile time:
interfaces/c/common.htests the compiler macros and defines oneMIPP_<ISA>macro (__AVX512F__→MIPP_AVX512,__AVX__→MIPP_AVX, ...), unlessMIPP_SCALARis already defined. The detection block of each ISA comes from its descriptor (define,mipp_definitions).- Each interface header includes the implementation of the selected ISA:
// interfaces/c/functions/arithmetic/u/m1/add.h
#if defined(MIPP_SSE)
#include "mipp/internal/simd_ext/sse/c/functions/arithmetic/u/m1/add.h"
#elif defined(MIPP_AVX)
#include "mipp/internal/simd_ext/avx/c/functions/arithmetic/u/m1/add.h"
...
#endif
- The C interface functions (
mipp_add_float32) call the ISA functions (mipp_avx_add_float32) under the same#ifchain; the C++ overloads ofsimd_ext/<isa>/cpp/wrap them formipp::vd<T, LMUL, ISA>.
Only the ISAs selected with --simd-ext appear in these chains. The C++ mipp::ISA enum lists every directory of simd_ext/, whatever the selection.
6. Category Headers¶
--header-type category_header writes one header per category instead of one per function. This mode is experimental: the code marks it as work in progress, and it is not tested by the CI. Use the default function_header.