<blake3pp/dispatch.hpp>¶
Instruction-set variants and runtime dispatch: which kernels this binary carries, which the running CPU can use, pinning, and the build introspection the tools print. Standard library only.
Functions¶
is_available¶
bool is_available(arch a) noexcept;
True if the variant is compiled into this binary and the running CPU supports it.
| Parameter | |
|---|---|
a |
Any variant; auto_detect is always available. |
cpu_supports¶
bool cpu_supports(arch a) noexcept;
True if the running CPU and OS could execute the variant, whether or not this binary carries it.
is_available(a) == (compiled_arches() contains a) && cpu_supports(a). Lets tools report "the machine supports X, this build does not carry
it" (blake3ppsum --version does).
| Parameter | |
|---|---|
a |
Any variant. |
best_available¶
arch best_available() noexcept;
The variant auto_detect resolves to on this machine.
compiled_arches¶
std::span<const arch> compiled_arches() noexcept;
The variants compiled into this binary, best-first, always ending with scalar. The table is generated by the build from the registered kernels, so a variant appears iff its code is really in the binary.
available_arches¶
std::span<const arch> available_arches() noexcept;
The compiled variants this CPU can run, best-first; never empty, and available_arches().front() == best_available().
run_trap_probes¶
bool run_trap_probes() noexcept;
Runs the deferred, trap-guarded detection probes once and upgrades the dispatch verdict with what they learn.
On most machines the default detection (auxv, hwprobe, CPUID reads) tells the whole story and this is a no-op. On RISC-V vendor-kernel shapes (T-Head boards whose kernel predates the hwprobe vendor key, and pre-6.4 kernels without hwprobe) part of the answer can only be learned by executing an instruction that may trap, under a scoped SIGILL guard. Default detection never does that, because swapping a signal disposition is briefly process-global; it reports scalar on those shapes instead. This call is the explicit opt-in: thread-safe and idempotent, it upgrades cpu_supports(), available_arches() and auto-dispatch. Call it where the application is not concurrently manipulating SIGILL handling; the shipped CLI tools call it at startup, since a standalone binary owns its process.
The BLAKE3PP_ASSUME_XTHEADVECTOR environment variable bypasses the question instead of answering it. =0 vetoes the XTheadVector kernel whatever detection says. =1 asserts the CPU has it without any check, which is the one way this library runs a kernel the CPU may lack, and a wrong assertion is a SIGILL on the first hash. It exists for the machines where no probe can answer -- a board whose kernel hides the extension, and an emulator that models neither the hwprobe key nor the trap -- and whose owner knows what is underneath. Nothing else should set it.
Returns true if anything new was learned.
to_string¶
const char * to_string(arch a) noexcept;
The canonical lowercase name of a variant ("auto", "sse42", "avx2").
| Parameter | |
|---|---|
a |
Any variant. |
arch_from_string¶
std::optional<arch> arch_from_string(std::string_view name) noexcept;
The inverse of to_string(): parses a canonical (lowercase) name.
| Parameter | |
|---|---|
name |
A variant name, as to_string() spells it. |
Returns The variant, or std::nullopt for any other string.
all_arches¶
std::span<const arch> all_arches() noexcept;
Every enumerator (auto_detect first, then best-first) regardless of what is compiled or runnable: the list to build CLIs and menus from, so consumers never hand-enumerate the enum.
version¶
std::string_view version() noexcept;
The library version, as the library was built (the git-derived stamp; see blake3ppsum --version).
simd_provider¶
std::string_view simd_provider() noexcept;
Which SIMD facade backs this build of the library: "std::simd", "std::experimental::simd", "xsimd", "xvec", or one of two "none" answers where the build resolved no project-wide provider: "none (scalar only)" when it carries the scalar kernel alone, and "none (kernels pin their own)" when every compiled kernel names its own.
execution_provider¶
std::string_view execution_provider() noexcept;
Which sender/receiver implementation backs this build of the library: "std::execution", "beman.execution" or "stdexec", or "none" where the build carries no execution provider and the multi-core entry points do not exist.
Enumerations¶
arch¶
enum class arch {
BLAKE3PP_ARCH
};
The instruction-set variants a binary may carry.
Which ones a binary carries is a build-time property, reported by compiled_arches() and decided in cmake/ArchKernels.cmake. Which ones are usable is a runtime property of the CPU, reported by available_arches(). auto_detect resolves to the best usable variant.
The enumerators, their canonical names and the dispatch preference are generated from one list, detail/arch.def, which documents each entry. Its line order is the ABI order, and append-only.
Macros¶
BLAKE3PP_ARCH¶
#define BLAKE3PP_ARCH