Skip to content

Building

← blake3pp

Three presets cover most of what you will want: a current GCC, a current clang, and the C++20 polyfill path. Everything past that is the matrix that proves the kernels, the remote-execution driver, and the switches that let you re-measure the tuning decisions on your own hardware.

cmake --preset linux-gcc16-cxx26 && cmake --build --preset linux-gcc16-cxx26
ctest --preset linux-gcc16-cxx26

Any name from cmake/toolchains/ works as a preset (see CMakePresets-toolchains.json). Test presets exist for:

  • linux-gcc16-cxx26 and linux-clang22-cxx26
  • linux-clang18-cxx20-libstdcxx: the C++20 polyfill path
  • the -asan variants: one per compiler at the plain matrix's -O2 -g, and -asan-release for the -O3 the matrix also builds, because an optimiser-dependent defect only exists under the optimiser that made it
  • linux-clang22-cxx23-fuzzer: the differential fuzz harness (tests/fuzz_paths.cpp), which feeds the same bytes through every path the library has and compares them. Its ctest leg is a few thousand inputs; a campaign is blake3pp_fuzz_paths -max_total_time=<s> <corpus>. libFuzzer's runtime is built against libstdc++, which is why this lane is not a libc++ one.

On Windows, from a vcvars64 shell:

  • windows-clangcl-cxx23 and windows-msvc2026-cxx23
  • windows-msvc2026-cxx23-asan: the same cl.exe build under AddressSanitizer, which is what would exercise the IOCP backend under a sanitizer at all. cl rather than clang-cl, for the reason cmake/toolchains/windows-common.cmake gives where it refuses the other spelling: on Windows the clang driver is what links clang's sanitizer runtimes, and CMake does not link through it. Known slow and not in CI: cl plus ASan on the kernel translation units has not produced an object in 500 s of CPU per unit, so the lane waits on instrumenting everything except the kernels.

On a Mac:

  • macos-appleclang-cxx23: the native preset (Apple clang, GCD + F_NOCACHE I/O)
  • macos-clang22-cxx26: Homebrew LLVM 22 against its bundled libc++ (brew install llvm)
  • macos-clang22-cxx26-tsan: the same under ThreadSanitizer

On FreeBSD, with the base system's compiler (pkg install cmake ninja):

  • freebsd-clang-cxx23: the native preset (base clang and libc++, POSIX AIO on a kqueue, O_DIRECT)
  • freebsd-clang-cxx23-asan and freebsd-clang-cxx23-tsan: the same build under the base system's clang_rt runtimes, which is what exercises the AIO backend's buffer lifetime and its one cross-thread member (wake()) under a sanitizer. ASan works. TSan is built and not run on 14.5-RELEASE (base clang 21.1.8): a TSan-instrumented binary hangs before main() there, a ten-line one included, with and without ASLR (proccontrol -m aslr -s disable), so the preset exists for a toolchain where the runtime starts.

FreeBSD can also be built from Linux, for either architecture, which is what CI does:

  • freebsd-zig-cxx23: zig's clang targeting x86_64-freebsd.14.0, built in the zig toolchain image like the static musl presets (tools/tc linux-zigmusl-cxx23-static -- cmake --preset freebsd-zig-cxx23 runs it, since both presets live in that image).
  • freebsd-arm64-zig-cxx23: the same, targeting aarch64-freebsd.14.0. It carries the arm64 kernels — neon, sve256, sve512 and sve2_128 — which cmake/KernelVariants.cmake registers from compiler probes the moment the toolchain declares CMAKE_SYSTEM_PROCESSOR aarch64; nothing in the toolchain file asks for them by name. Dispatch offers the SVE ones only on a kernel that publishes HWCAP_SVE, which FreeBSD does from 15.0; on 14.x the same binary takes neon.

Neither is static, and neither can be: zig refuses -static for both targets with "libc of the specified target requires dynamic linking", so the binaries link against libc.so.7 and libthr.so.3 and the ABI version in the triple becomes the floor — they run on FreeBSD 14.0 and newer. Nothing on the build host can execute them, so the presets' CMAKE_CROSSCOMPILING_EMULATOR is empty and ctest runs nothing; tools/freebsd-guest.sh is what runs them, by booting an actual FreeBSD under qemu:

tools/freebsd-guest.sh prepare      # once: build the guest image
tools/freebsd-guest.sh start
tools/freebsd-guest.sh wait
tar cf - -C build/freebsd-zig-cxx23 tests cli bench \
  | tools/freebsd-guest.sh run 'mkdir -p /root/b3 && tar xf - -C /root/b3'
tools/freebsd-guest.sh run '/root/b3/tests/blake3pp_tests'
tools/freebsd-guest.sh stop

Put FBSD_ARCH=arm64 in front of each of those for the arm64 guest; it is one script and the two guests have different default directories and ports, so both can exist in one checkout.

prepare needs qemu, root for nbd, and the EFI firmware for the architecture (ovmf on amd64, qemu-efi-aarch64 on arm64). The amd64 guest also needs /dev/kvm: it takes about a minute to prepare and boots to ssh in roughly fifteen seconds. The arm64 guest runs under TCG — nothing can KVM an aarch64 guest on an x86 host, and GitHub has no arm64 runner that exposes /dev/kvm — so it is slower throughout: measured on a 16-core x86 box, about four and a half minutes to prepare (of which a minute and a quarter is the download), a hundred seconds to boot to ssh, and under a minute for the whole test suite. CI does not run prepare per build: the prepared images are published to GHCR alongside the toolchain images and the lanes pull them. The script's header explains why the guest configures itself from the inside rather than being seeded offline (short version: Linux cannot write UFS), and why the two architectures differ in exactly four places.

Without a preset, a bare cmake -S . -B build configures the C++20 baseline with the default compiler.

The devcontainer carries only the default gcc/clang pair; every other preset runs inside its per-compiler toolchain image via tools/tc <preset>; see docker/README.md for the image matrix and its glibc-floor design. The cross presets (linux-arm64-gcc15-cxx23, linux-riscv64-gcc15-cxx23, and the static musl set linux-{,arm64-,riscv64-,ppc64le-,s390x-,loongarch64-}zigmusl-cxx23-static) run their whole test suites under qemu-user with a selectable vector length, so one build exercises every SVE VL or RVV VLEN; the emulator recipes are in docker/README.md too. Two kernel sets are opt-in:

  • -DBLAKE3PP_SVE_ALL_VARIANTS=ON adds the SVE variants matching no shipping silicon (emulator targets)
  • -DBLAKE3PP_XTHEAD_KERNEL=ON compiles the hand-written T-Head XTheadVector (draft RVV 0.7.1) kernel, which only T-Head's qemu fork can execute

Provider and polyfill selection

Two cache variables, each an explicit choice with an auto default, pick what the SIMD facade and the sender/receiver pipeline compile against. cmake/StdFeatures.cmake is the sole authority: it probes the active toolchain by compiling real usage rather than trusting feature-test macros, and the resolved choice is what every preset above actually builds with. The reasoning behind the defaults and the toolchain-specific overrides is in Polyfills; this is the configure-time surface.

-DBLAKE3PP_SIMD_PROVIDER=auto|std|std-experimental|xsimd|xvec
-DBLAKE3PP_EXECUTION_PROVIDER=auto|std|beman|stdexec

BLAKE3PP_SIMD_PROVIDER=auto tries native std::simd (C++26 <simd>) first, falls back to the Parallelism TS v2 std::experimental::simd, and falls back again to xsimd, which is always buildable since it is a fetched header-only dependency with no toolchain requirement of its own. std and std-experimental each fail the configure outright if the probe behind them does not pass, rather than silently substituting something else; xsimd skips the std probes entirely, and so does xvec, which auto never reaches for -- it is Intel's implementation of the same C++26 library, fetched at a pinned commit, and exists to run the library against a second implementation of the standard interface. See Polyfills for what a provider choice may and may not change.

BLAKE3PP_EXECUTION_PROVIDER=auto picks std::execution when the standard library has a usable one and NVIDIA stdexec otherwise; beman.execution is never chosen by auto and needs the explicit -DBLAKE3PP_EXECUTION_PROVIDER=beman (it also needs C++23 or newer, which the project's C++20 presets cannot offer).

BLAKE3PP_SIZED_PARALLEL_SCHEDULER (auto, ON or OFF) builds blake3pp::parallel_backend, which sizes the process-wide scheduler (API). auto, the default, builds it under beman when the toolchain has OS threads, and not otherwise:

  • Under beman it replaces beman's own default backend, which is then built out, and blake3pp::blake3pp links it, so every program has one backend and --threads sizes the pool as it does under stdexec. OFF keeps beman's own backend, for a program that defines its own replacement.
  • Under stdexec ON builds it for an executable that wants to size blake3pp's process pool; the tools size their own pools without it.
  • Under std::execution it must be off.
  • Without OS threads (BLAKE3PP_HAS_STD_THREAD off, as on a freestanding toolchain) it must be off: the backend is a thread pool.

The installed package exports it as blake3pp::parallel_backend. A build directory configured before the option took auto holds OFF, its old default, and keeps it; it opts into the new default by reconfiguring with -DBLAKE3PP_SIZED_PARALLEL_SCHEDULER=auto.

A configure reports every probe and the resolved choice regardless of whether either variable was touched:

-- blake3pp: BLAKE3PP_HAS_STD_SIMD = yes
-- blake3pp: simd provider choice = auto
-- blake3pp: BLAKE3PP_HAS_STD_SENDERS = no (polyfill path)
-- blake3pp: execution provider = stdexec (BLAKE3PP_EXECUTION_PROVIDER=auto)
-- blake3pp: sized parallel scheduler = OFF (BLAKE3PP_SIZED_PARALLEL_SCHEDULER=auto)

and a running binary reports which provider it was actually built with, independent of the configure log:

blake3pp::simd_provider();       // "std::simd", "std::experimental::simd",
                                  // "xsimd", "xvec", "none (scalar only)",
                                  // or "none (kernels pin their own)"
blake3pp::execution_provider();  // "std::execution", "beman.execution",
                                  // "stdexec", or "none"

(blake3ppsum --version prints both; so does the wasm module's b3pp.simd_provider()/b3pp.execution_provider(), see Architectures and kernels.) A handful of cross-compiling toolchains pin BLAKE3PP_SIMD_PROVIDER themselves instead of leaving it on auto -- linux-riscv64-gcc15-cxx23, linux-ppc64le-gcc15-cxx23, linux-s390x-gcc15-cxx23 and the ppc64le/s390x zigmusl presets set it to xsimd, and linux-mips64el-gcc14-cxx23 sets std-experimental -- because each one's vector kernel already pins a provider for reasons specific to that ISA which auto's probes cannot see. On auto nothing would fall back to a project-wide provider, so none would be resolved and simd_provider() would answer "none (kernels pin their own)"; naming the provider the vector kernel uses is the more informative answer.

Override either on a preset that does not need it to re-measure the choice.

Coverage

The linux-clang22-cxx26-coverage preset instruments at the plain matrix's optimisation level, so the numbers describe the code that ships:

tools/tc linux-clang22-cxx26 -- bash -c '
  cmake --preset linux-clang22-cxx26-coverage &&
  cmake --build --preset linux-clang22-cxx26-coverage &&
  LLVM_PROFILE_FILE="$PWD/build/linux-clang22-cxx26-coverage/profraw/%p.profraw" \
    ctest --test-dir build/linux-clang22-cxx26-coverage'
llvm-profdata merge -sparse build/linux-clang22-cxx26-coverage/profraw/*.profraw \
  -o build/linux-clang22-cxx26-coverage/all.profdata
llvm-cov report build/linux-clang22-cxx26-coverage/tests/blake3pp_tests \
  -instr-profile=build/linux-clang22-cxx26-coverage/all.profdata src/io include

If an LLVM tool sits there burning no CPU, it is waiting on a descriptor, not working: the base image sets DEBUGINFOD_URLS to Canonical's server, the connect never completes from here, and the tool polls for it for ever. The devcontainer sets the variable empty for that reason; outside it, put env -u DEBUGINFOD_URLS in front of the command.

Building through cmake-re

Every containerized preset also builds through tipi cmake-re. It runs the compile actions on a remote-execution cluster, EngFlow through reclient, and serves repeats from its action cache. The tests, emulator matrices and artifacts come out the same as with plain cmake.

cmake-re ships in every x86_64 toolchain image, with TIPI_DISTRO_MODE=none so that it drives the image's own compilers. It knows nothing about presets, so tools/preset-args.py unrolls one into plain configure arguments:

tools/tc linux-gcc16-cxx26 -- bash -c '
  cmake-re --host -S . $(python3 tools/preset-args.py linux-gcc16-cxx26)
  cmake-re --build build/linux-gcc16-cxx26 --host -j"$(nproc)"
  ctest --test-dir build/linux-gcc16-cxx26 --output-on-failure'

--host builds inside the image the command runs in; add --distributed to send the compiles to the cluster, with the mTLS credentials in RBE_service, RBE_tls_client_auth_key and RBE_tls_client_auth_cert, and TIPI_DISABLE_AR_RANLIB_DRIVER=ON and USER set. The build directory becomes a symlink into cmake-re's mirror of the checkout under .tipi, which is why ctest --test-dir is the spelling above.

The toolchain folders

Each toolchain lives in its own folder under cmake/toolchains/, with the .pkr.js and .layers.json that name its image at the content tag and the manifest digest that tag resolves to. That folder is the environment cmake-re copies when it is not told --host, and the cluster pulls the same image for the compile actions.

tools/gen-environments.py writes those files. --check reports stale ones, and the digests come from the registry or from a --digests map. BLAKE3PP_TC_REGISTRY and BLAKE3PP_TC_IMAGE_TEMPLATE retarget them at a registry mirror the cluster can reach.

CI does not depend on them being current:

  • Every run writes the tag and digests it builds with into them, and builds on that.
  • When the committed files lag, a run of main opens one draft pull request proposing the update. It is ci/toolchain-environments, updated in place while the tag keeps moving, and marking it ready for review runs CI on it.
  • A release built on injected files is named and annotated as a dirty build.

In CI the repository variable BLAKE3PP_CI_DRIVER=cmake-re (or the driver input of a manual run) switches every Linux container lane to cmake-re, building with --host alone (the image's own compilers, no cluster involved) unless BLAKE3PP_CMAKE_RE_MODE (or the cmake-re-mode input) says distributed. The settings behind it:

Setting Kind Purpose
BLAKE3PP_CMAKE_RE_MODE variable host (default) or distributed; everything below matters only for distributed
RBE_SERVICE secret cluster address
RBE_TLS_CLIENT_AUTH_KEY, RBE_TLS_CLIENT_AUTH_CERT secrets the mTLS client credentials, PEM
BLAKE3PP_RBE_ENV_REGISTRY variable the public mirror the cluster pulls the environment images from: a Docker Hub namespace, spelled without docker.io/ (cmake-re matches the daemon's digests, which never carry that host); toolchains.yml copies every image it builds there
DOCKERHUB_USERNAME, DOCKERHUB_TOKEN secrets the mirror's credentials

cmake-re's mirror of the checkout is restored from the actions cache per lane, so a rerun configures in seconds and builds only what changed. Windows and macOS stay native. tools/make-release.sh takes the same switch (BLAKE3PP_CMAKE_RE=1, BLAKE3PP_CMAKE_RE_FLAGS choosing --host or --host --distributed).

Kernel tuning switches

Nine cache variables turn measured kernel optimizations on or off. Each is auto|on|off and defaults to auto, which is the fastest setting on every machine it has been measured on. These are not performance options to tune, they are measurement controls, and turning one off makes the library slower. They exist so a result can be re-checked on hardware its original measurement did not cover; the resolved value is reported at configure time when it is not the default.

variable default off means
BLAKE3PP_KERNEL_INLINE_ENFORCEMENT on, all targets Drop always_inline/__forceinline from the round core. Every compiler measured then outlines it (clang the whole all_rounds, GCC the index_sequence lambda), costing 6-40% depending on compiler and variant.
BLAKE3PP_KERNEL_SRI_ROTATE on, aarch64 Spell rot12/rot7 as the generic shift-or, which selects shl+usra instead of shl+sri. sri is worth ~6% on Apple M2 (clang 22), 12% on Neoverse V2 and 8% on Neoverse N1 (clang 21, static build), measured as alternating A/B pairs.
BLAKE3PP_KERNEL_STAGED_ROUNDS on, aarch64 Run each round as sequential g calls instead of quartet-staged. A small win on Apple M2 / clang 22, and provably inert on GCC 15 (same schedule, different register names). Loses on x86, where it is off regardless.
BLAKE3PP_KERNEL_XAR_ROTATE on, SVE2 variants Spell rot(x ^ y) as eor + rotate instead of one fused XAR. Off costs the SVE2 kernels their entire margin over NEON: measured 1.89 vs 1.61 GiB/s on Neoverse V2 (GCP Axion).
BLAKE3PP_KERNEL_SHUFFLE_TREE on, all SIMD targets Stage every transpose through a scalar array and spell the byte rotates as shift-or, the code before the shuffle-tree bypass. Off costs SSE4.2 about half its throughput on clang.
BLAKE3PP_KERNEL_ROT16_PER_COMPILER on, x86 clang Spell rot16 as the byte shuffle on clang too, which LLVM lowers to pshuflw+pshufhw where the shift-or folds to one pshufb. The pre-split spelling, kept for the A/B.
BLAKE3PP_KERNEL_VROR_ROTATE on, RVV Zvbb variants Spell the rotate as the 4-op shift-or (base RVV has no rotate) instead of vxor+vror. The RISC-V counterpart of the XAR switch; not yet measured on Zvbb silicon, which this switch makes possible.
BLAKE3PP_KERNEL_VEXT_W8_GATHER on, GCC at eight lanes with AVX-512 available Transpose through the shuffle network there too. GCC lowers the network's cross-lane stage to an index-register permute per stage when the register is a raw vector extension and AVX-512 is in reach, so the staging gather is faster in exactly that corner; the switch is the A/B, and in AVX2-only builds the network wins by 19%.
BLAKE3PP_KERNEL_PIN_MESSAGE on, AVX-512 width on GCC and clang Hold the message block in registers. At sixteen lanes the state takes half the register file and the message cannot fit beside it, so letting its address escape once makes the compiler read it through memory operands: worth 7.8% on the kernel row and 8.5% end-to-end on Zen 5, and 2-4% at 32 threads (3-6% measured on the chunk shape by itself).
# Re-run the inlining A/B on a new machine:
cmake --preset macos-clang22-cxx26 -DBLAKE3PP_KERNEL_INLINE_ENFORCEMENT=off

Two benchmark comparisons are build options of their own. BLAKE3PP_BENCH_UPSTREAM (on) builds the upstream BLAKE3 C library, so every run shows blake3pp's variants against the hand-written assembly on the same machine. BLAKE3PP_BENCH_COMPARE (off, needs cargo) builds the reference implementation's own rayon bench from bench/compare/, one binary per compile-time SIMD cap, which is the comparison against the implementation as its users get it.

BLAKE3PP_KERNEL_EXTRA_FLAGS (a semicolon-separated list) appends raw compiler flags to the kernel TUs only, for one-off flag trials that have not earned a switch.

Two more cache variables shape the tree reduction rather than the kernel.

BLAKE3PP_SUBTREE_GROUP=<power of two> sets how many chunk batches a reduction hashes before it compresses their parents; 8 is the default. The kernel's chunk loop and its one-block parent call do not stay hot together, so the burst pays for the locality it gives up. Measured on Zen 5 AVX-512 with the parent work unchanged and only its grouping varied: 6.7 GiB/s at one batch per burst, 7.6 at eight, 7.8 at thirty-two.

BLAKE3PP_SUBTREE_FOLD=<levels> goes the other way, for targets that cannot spare the burst's staging buffers. The frames are in Freestanding and RTOS builds.

One more shapes the I/O geometry. BLAKE3PP_MAX_QUEUE_DEPTH=<n> (at least 2, 256 by default) is the deepest queue a caller may ask for, and with it the largest window the engines accept, since the arena is the product of the two: a window in flight costs window_bytes plus its own tables, so 256 at the default 8 MiB window is already over 2 GiB. It is a guard against a typo rather than a device limit -- NVMe takes tens of thousands of outstanding commands -- and the measured devices land at a depth of four to eight, or sixteen where they want more bytes in flight (Performance). An installed package carries the value it was built with, because the constants it sets are used by inline functions on both sides of that boundary.

Layout:

  • include/blake3pp/: the public API; the canonical variant list (enum, names, preference ranking) is generated from detail/arch.def
  • src/core/: arch-agnostic tree logic
  • src/kernel/: the per-architecture kernel, one TU compiled once per variant by cmake/ArchKernels.cmake; variants are registered per ISA family in cmake/KernelVariants.cmake
  • src/dispatch/: runtime routing, with per-platform CPU probes in cpu_detect_*.cpp
  • cmake/StdFeatures.cmake: probes what the active standard library really ships, by compiling usage rather than trusting feature-test macros
  • tests/: verifies every configuration against the official BLAKE3 test vectors