fix: dispatch hashtree at runtime on every x86_64 target - #13
Merged
Merged
Conversation
Select hashtree on x86_64 by target OS instead of compile-time CPU features, since `hashtree_hash` already picks its backend at runtime. - `isSupported()` returns true on x86_64 except macOS and Windows MSVC, the targets where `build.zig` does not assemble the x86 backends - baseline builds (for example published packages built with only `-Dtarget`) now use SHA-NI, AVX-512, AVX2, AVX or SSE instead of std SHA-256 - macOS keeps the std fallback whatever `-Dcpu` is, which fixes the undefined `_hashtree_sha256_*` link errors with `-Dcpu=haswell`
spiral-ladder
pushed a commit
to ChainSafe/lodestar-z
that referenced
this pull request
Oct 1, 2026
**Motivation** The current hashtree-z pin sends baseline x86_64 builds through Zig's SHA-256 fallback even though hashtree selects its backend at runtime. [ChainSafe/hashtree-z#13](ChainSafe/hashtree-z#13) enables that dispatch on supported targets and fixes x86_64 macOS linking with explicit CPU features. **Description** Update `hashtree` in `build.zig.zon` from `f5c1b81` to `9b0fdad`, including the package hash generated by `zig fetch`. **AI Assistance Disclosure** Implementation was primarily AI-authored with Codex.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
On x86_64,
isSupported()only callshashtree_hashwhen the compile-time CPU has avx512f+avx512vl, avx2+bmi2 or sha+avx. Baseline builds, including the published lodestar-z packages (built with only-Dtarget), therefore never link hashtree and hash every pair with std SHA-256, even thoughhashtree_hashselects its backend at runtime. Measured with lodestar-z on a Threadripper 1950X (SHA-NI), ReleaseSafe:Separately,
x86_64-macoswith-Dcpu=haswellfails to link today (undefined symbol: _hashtree_sha256_avx2_x8, ...) because the x86.Sfiles are not assembled for Mach-O.Description
Select hashtree on x86_64 by target OS instead of compile-time CPU features.
isSupported()returns true on x86_64 except macOS and Windows MSVC, matching the targets wherebuild.zigassembles the x86 backends-Dcpu, which also fixes the macOS link failureTested:
zig build testnatively, with-Dcpu=baseline(Debug and ReleaseSafe), the baseline test binary under qemu-x86_64qemu64,Nehalem-v2andEPYC-v1, andaarch64-linux-muslvia qemu;x86_64-macos(with and without-Dcpu=haswell),x86_64-windows-gnuandx86_64-linux-muslbuild.x86_64-windows-msvcfails the same way on main (no MSVC headers here).AI Assistance Disclosure
Primarily AI-authored with Claude Code, including the measurements.