Repository navigation
Argon2 and BLAKE2: one implementation per CPU level, chosen by their dispatchers - #4502
Merged
Merged
Conversation
Argon2 on x86-64 was instantiated for every BLAKE2b backend with every implementation of G, nine functions, of which the Rust code chose five (listing four as never chosen) by matching on both backends. The generic registration now pairs each BLAKE2b backend with G's of the same suffix, the baseline, `_avx2` and `_avx512`: any other pair needs the features of one of these, which runs both its parts with them. `src/kdf/argon2.rs` calls `vg_argon2_auto`; `CompressBackend`, its choice and its tests go. A CPU with AVX-512F but not AVX512VL (Knights Landing) ran BLAKE2b's `_avx2` with G's `_avx512` and now runs `_avx2` for both; one with AVX-512F but not AVX2 (none exists) runs the baseline. The matrix's `avx,avx512f` line, which chose that pair, goes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHE2dqL6Q2PDogxfD5f
alex
enabled auto-merge
November 7, 2026 17:55
`blake2!` calls `vg_blake2<b|s>_{init,update,finalize}_auto`
(`crate::arch::dispatch::blake2<b|s>`) instead of matching on
`Blake2bBackend` or `Blake2sBackend`, which it chose in Rust when a
computation started. The enums, their `REQUIRES` and `select`, and the
computations' `backend` field go; Argon2, their last other user, calls its
own dispatcher (#4502).
The choice is today's: on x86-64, BLAKE2b's `_avx512`, then `_avx2`, and
BLAKE2s's `_avx`; the baseline elsewhere. `update` and `finalize` each
check their own features, so they could differ only on feature sets no
CPU has; both have the same contract over the same state.
Claude-Session: https://claude.ai/code/session_01TKUFHFuGsz7F32Tm9DLkuP
Co-authored-by: Claude <noreply@anthropic.com>
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.
What changes
On x86-64, Argon2 was built for every BLAKE2b backend paired with every implementation of G, nine functions in all.
src/kdf/argon2.rsmatched on both backends to pick one of five. It marked the other four as never chosen and excluded them from coverage. Those four are combinations no CPU would ever pick: they existed only because Argon2 was generic over the full product of the two.The generic registration (
Generic/Blake2b/Argon2Compress/X86_64/Argon2.lean) now pairs each BLAKE2b backend only with G's implementation of the same suffix: the baseline,_avx2and_avx512. Any other pair needs the features of one of these three, which runs both of its parts with them. That leaves three functions,vg_argon2,vg_argon2_blake2b_avx2_g_avx2andvg_argon2_blake2b_avx512_g_avx512, and one generated dispatcher.src/kdf/argon2.rscallsvg_argon2_auto.CompressBackend, its choice, its compile-time assertions, the coverage exclusion and its unit test are all removed.Choices
_avx512+_avx512_avx2+_avx2_avx2+ G_avx512_avx2+_avx2VG_CPU_FEATURES)_avx512The
ci/rust_matrix.tomllineavx,avx512f, which existed only to select that last pair, is removed. The comment describing theavx,avx2,avx512fline now names Argon2's AVX2 code.Benchmark
Run of
argon2on x86_64 against da38ca4, this branch's base. AArch64 and x86 have only one Argon2 implementation.The run has three jobs: all features,
avx,avx2,bmi1,bmi2,adx, andnone. Each covers the 14 Argon2 benchmarks, and none regresses:These numbers come from the jobs' uploaded samples: the median estimate of each benchmark, head against base. The artifacts don't record which job ran which configuration, so the rows are numbered rather than named. Every CPU these runners have runs the same machine code as before, since only the never-chosen pairs and the Rust choice went.
Also: BLAKE2 (#4511, merged into this branch)
#4511 was stacked on this PR and merged into its branch, so this PR lands both.
blake2!(BLAKE2b and BLAKE2s) callsvg_blake2{b,s}_{update,finalize}_auto, andBlake2bBackendandBlake2sBackendare removed: once Argon2 calls its own dispatcher, it was their last user outsidesrc/hashes. Benchmark: https://github.com/pyca/verified-garbage/actions/runs/42398981897.No TCB or Spec change.
Checks
lake build;Emit.lean --checkcheck_variants.pyand every other static checkcargo fmt --check;cargo clippy --all-targets -D warningson x86-64, AArch64, i686, ARMv7, RISC-V 64 and PPC64LEargon2andrfc9106tests (release) withVG_CPU_FEATURESunset and set to:avx,avx2,avx512f,avx512vlavx,avx2,avx512favx,avx2nonehttps://claude.ai/code/session_01TKUFHE2dqL6Q2PDogxfD5f
Generated by Claude Code