Repository navigation
AES-GCM: call the dispatchers, not a table of selected functions - #4629
Conversation
Each generated dispatcher (`<function>_auto`, `VG.Rust.dispatcher`) used to test the CPU's features against each of its implementations' on every call, inlined into every caller. It now holds a pointer to the implementation to call, `CHOSEN`, which starts out pointing at `first`: a function of the implementations' type that chooses one (`select`, with the same conditions in the same order as before), records it in `CHOSEN` and runs it. Every later call is a load and an indirect call, however many implementations the function has, as in an ELF IFUNC but portable to every target and object format. The pointer, `select` and `first` are items inside the dispatcher, so their names are its own and its lines are still one span from its `pub unsafe fn` to its closing `}` for `ci/merge_rust_coverage.py`. This is a change to the trusted base (`TCB/Rust.lean`): which implementation runs is chosen exactly as before, and `detected()` already returned the same features for the life of the process, so the choice is the same; only when it is made changes. Fixes #4609. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFCSTvQuX83u32Ae29
…ms case `main` dropped `Rank.skip` (#4618), so a dispatcher with variants always has arms: the case of none, which called the base directly, is gone. The generated files are regenerated over main's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFCSTvQuX83u32Ae29
02b9927 to
28bd86f
Compare
A dispatcher's `first` (`VG.Rust.dispatcher`) is an `extern` function
inside it, which `fnNames` read as a function of the file named `first`,
and `unreadFns` then refused every dispatchers' file with one ("cannot
read the names of its functions"). Read only the lines that are not
indented, as every item of a generated file is.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHFCSTvQuX83u32Ae29
|
Benchmarks: run 42488035545, this PR with #4623 under it vs. their base (3cf1f61), x86-64 and AArch64, every
(The other x86-64 configurations are the same: medians within ±0.1%.) One outlier to explain: under Generated by Claude Code |
A key used to hold a pointer to a table of the implementations its functions' dispatchers would run (`Fns`), chosen once per process by their selectors (`<function>_select`) behind a hand-written once-cell (`Selected`), so that no call tested the CPU's features again. The dispatchers now choose once themselves and call through a function pointer (`VG.Rust.dispatcher`), so the key calls them as every other module does, and the table, the once-cell, the function pointer types and the key's pointer to the table go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFCSTvQuX83u32Ae29
28bd86f to
1ee0a6e
Compare
|
The
So the +10% at 256–257 B in the first run was that job's draw, not the change: the same rows on the same runner type are within ±3.5% both ways, about the spread of this configuration. Every other configuration in the first run was within ±0.1% median. Generated by Claude Code |
Stacked on #4623 (only the top commit is this PR's).
AesGcmheldfns: &'static Fns, a table of the implementations its functions' dispatchers would run, which it filled once per process from their selectors (<function>_select) behind a hand-written once-cell (Selected: anAtomicU8state machine,UnsafeCell<MaybeUninit<Fns>>, anunsafe impl Sync), so that no call tested the CPU's features again. Since #4623 every dispatcher chooses once itself and calls through a function pointer, so all of that is now what_autodoes, and the key calls the dispatchers like every other module:Fns,Selected,SELECTED, theverified_fn!macro and the eleven function-pointer types (−248 lines, +38);fnsfield (one pointer smaller per key, and one dependent load less per call: the dispatcher reads a static, not the key's pointer to the table and then the table);updatepicks_stream_encrypt…_autoor_stream_decrypt…_autoon theDECRYPTconst instead of a field.No change to what runs: each call goes to the implementation
_selectreturned before. Rust only;VG.Dispatch.selectedand the_selectfunctions are removed from the TCB by #4635.Testing
cargo clippy --all-targets -D warningsfor x86-64, aarch64 (Linux, Apple), i686, armv7, riscv64 and powerpc64le.cargo test --releasewith Wycheproof on x86-64 (AVX-512, VAES), with all features,VG_CPU_FEATURES=none, andaes,pclmulqdq,ssse3.Benchmarks
Run 42488035545: this PR with #4623 vs. their base, x86-64 and AArch64, every configuration of
aes_gcm, groupsaes-(128|256)-gcm-tls-(seal|open)andaes-128-gcm-stream: the median change is within ±0.1% in every job, andaes-128-gcm-stream/64is 3–5% faster on most x86-64 configurations. One outlier (aes-128-gcm-tls-seal/256+10% underaes,avx,avx2,pclmulqdq,ssse3) did not reproduce when this PR alone was measured on the same runner type (+2.1%, with neighbouring sizes 2–3% faster). Details in the comments.🤖 Generated with Claude Code
https://claude.ai/code/session_01TKUFHFCSTvQuX83u32Ae29