Repository navigation
Conversation
"Variants flow to callers" asked for a function named `g_<s>` for each variant `f_<s>` of a function `g` calls. Once duplicate instances are no longer emitted, the implementation a CPU runs is often named otherwise (AES-GCM-SIV's `vg_aes_gcm_siv_seal_vaes_pclmul_avx2` for `vg_aes_gcm_siv_seal_pclmul` and `vg_aes_ctr32_vaes`), and the name rule then wanted a duplicate back. Where `g`'s function has a dispatcher, the check now replays its arms (`file_arms`) on a CPU with `g`'s features and `f_<s>`'s: it passes if the implementation run calls `f_<s>`, one `f`'s dispatcher tries before it, or none of `f`'s implementations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHE2dqL6Q2PDogxfD5f
|
Now that we have dispatch in verified code, do we need check_variants at all? |
|
Only part of it. One property still matters; the rest was about the Rust choosing, and that's gone. Still needed: a dispatcher can only pick among implementations that were emitted. If a caller isn't instantiated over a callee's variant (say No longer needed:
All of these approximate the question "on this CPU, does the code that runs call the best callee?" without being able to see what runs. The dispatchers now answer it directly. So rather than layering this PR on top of the old rules, I'd replace One gap to handle: internal functions have no dispatcher, so their callers' choices are what count. The rule follows calls through them. Want me to close this PR and do that rewrite instead? Generated by Claude Code |
|
Sure |
|
Closing in favour of rewriting Generated by Claude Code |
Why
check_variants.py's "variants flow to callers" rule needs, for each variantf_<s>of a functiongcalls, a function ofgnamedg_<s>(or a name composed with_<s>).Removing the duplicate instances means the implementation a CPU actually runs often has a different name. For example, after AES-GCM-SIV's aliases go,
vg_aes_gcm_siv_seal_vaes_pclmul_avx2is the variant ofvg_aes_gcm_siv_seal_pclmulforvg_aes_ctr32_vaes. The name rule then asks for the duplicate back. Session C's branch removing GCM-SIV's 14 aliases (claude/aes-gcm-siv-no-aliases) got 12 such reports.What changes
Where
g's function has a generated dispatcher, the check now replays the dispatcher's arms (file_arms) on a CPU withg's features plusf_<s>'s. Since CPU detection reports BMI2 and ADX only with AVX2, AVX2 is added when either is present. It passes if the implementation the dispatcher runs:f_<s>, orf's dispatcher tries beforef_<s>, orf's implementations.The name rule still applies first, and alone where there is no dispatcher, such as for internal functions. An arm whose condition depends on the compilation target (
cfg!, Apple's_neon) is not counted.This is untrusted CI tooling, not a TCB or Spec change. It doesn't touch the generated code, and main passes as before.
Effect
On session C's branch, the 12 reports drop to 2:
vg_aes_gcm_siv_{seal,open}_avx2withvg_aes_encrypt_blocks_vaesThese two are real. With
VG_CPU_FEATURES=aes,avx,avx2,vaes(no SSSE3), the dispatcher runs the baseline AES blocks, because every VAES instance of seal and open also needs SSSE3. Main runs the same baseline code there today; the old rule passed only by name, through an alias whose code needs SSSE3 too.No real CPU has VAES without SSSE3. The faithful fix is for detection to report VAES only with SSSE3, as it already does for BMI2 and ADX with AVX2, and for
VG_CPU_FEATURESto refuse VAES without SSSE3. That would change the CPU crate and theaes,avx,avx2,avx512f,vaes | aes_cbcmatrix line, so it belongs in a separate change.Tests
New tests in
ci/test_check_variants.py(Dispatched) cover:cfg!condition.All 48 tests of the module pass, as does
run_unit_tests.py.check_variants.pypasses on main.Generated by Claude Code