Repository navigation
AArch64 comb: select each entry in registers, as s2n-bignum does - #2638
Merged
Merged
Conversation
alex
force-pushed
the
claude/a64-comb-sel
branch
from
October 17, 2026 17:06
1ab6ae0 to
f1feab1
Compare
alex
force-pushed
the
claude/a64-comb-sel
branch
from
October 17, 2026 17:50
f1feab1 to
3cd6e14
Compare
combEntry loads every candidate's words in pairs and keeps the digit's with csel, from the identity's, then negates 2dT as p - 2dT and exchanges Y - X and Y + X for a negative digit, and stores the entry once (combEntry_ok). src/asm is not regenerated yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ma2fA9rUTPXEEQjYyCMCRw
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ma2fA9rUTPXEEQjYyCMCRw
combSelect, its masks (combMasks, selectMasks, maskV, candV), combNeg and their proofs are no longer used: delete them, keeping the tables' lemmas (TblAt, combWord_eq) and the digit's sign, and describe the new selection. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ma2fA9rUTPXEEQjYyCMCRw
alex
force-pushed
the
claude/a64-comb-sel
branch
from
October 17, 2026 18:38
3cd6e14 to
41d1507
Compare
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.
Part of #991.
Stacked on #2635 (base
claude/a64-comb-alt).The AArch64 comb behind
vg_ed25519_scalar_baseandvg_x25519_baseselected each digit's entry with NEON masks: per-magnitude masks in registers, copied into vector lanes, and each candidate inserted with BIT. Afterwards it negated the entry with a vector swap. This PR selects in general-purpose registers instead, as s2n-bignum'sedwards25519_scalarmulbase_altdoes.ldp, at addresses from the static's address and the loop's public counter only.cselwhere the digit's magnitude equals the entry's index, starting from the identity.2dTis negated andY - X/Y + Xare exchanged under the sign, withcsel, and the entry is stored once.There is no early exit and no secret-indexed address; the artifacts' constant-time proofs (
taint_decide) cover the new selection.Impl/Ed25519/AArch64/Comb.lean:combDigitS(the digit without masks),tblAddrS,scanInit,scanCand,scanNeg,scanSign,combEntry;combStepusescombEntry. The vector selection (magRegs,combMasks,combDigit,tblAddr,combNeg) is removed.Proof/Ed25519/AArch64/CombEntry.lean(new),combEntry_ok: slots 4–6 hold the selected entry, with the sign applied (Y - XandY + Xexchanged,2dTnegated). The rest of the workspace and the saved registers are kept.CombLoop.lean,CombDigit.lean,CombSelect.lean: the loop's invariant usescombEntry_ok; the proofs of the vector selection are removed (−578 lines), and the tables' lemmas (TblAt,combWord_eq) stay.src/asm/aarch64/{ed25519,x25519}.rsregenerated.Not trust changes: nothing under
TCB/orSpec/.Benchmarks
N2 (
aarch64), three runs, base eb6885e (#2635's code)ed25519_keygen/32ed25519_sign/64ed25519_sign/1024ed25519_sign/16384ed25519_verify/64ed25519_verify/1024ed25519_verify/16384x25519/32x25519_generate/32x25519_public_key/32x25519_raw/32¹ At 82bae89, before the commit that removes the dead vector selection; the generated code (
src/) is identical to this PR's.Apple M1 (
aarch64-apple)Rule: a job counts only if every row this PR does not touch (
x25519,x25519_rawand the threeed25519_verifyrows) moved by at most ±3% base → head. Pass: at least two clean runs, no row's mean more than 3% slower, and no row more than 3% slower in every clean run. If two clean runs could not be had within about 3 hours, the evidence is N2 plus llvm-mca's M1 model. That is the case here: of six Apple runs, one is clean, and no further Apple runs were dispatched while the macOS runners were starving the repository's CI. An A/A run (identical code on both sides, run 39031471393) moved the control rows by up to 13% onmacos-latest.The clean run, 39018936660 (default configuration):
ed25519_keygen/32ed25519_sign/64ed25519_sign/1024ed25519_sign/16384x25519_generate/32x25519_public_key/32x25519/x25519_rawed25519_verify64 / 1024 / 16384llvm-mca on the comb loop as emitted (from
21:tocbnz x8, 21binvg_ed25519_scalar_base, 64 iterations a call):apple-m1neoverse-n2All Apple runs, including those whose controls failed (default configuration, unless marked
noneforVG_CPU_FEATURES=none, which counts only for the X25519 rows because Ed25519 uses a SHA-512 variant there):x25519,x25519_raw,ed25519_verify64/1024/16384)none:x25519_raw−3.8,ed25519_verify/64+23.6, rejectedx25519+18.1x25519−7.1;none:ed25519_verify/1024−3.4ed25519_verify/64+3.2;none:x25519+9.0x25519+13.4;none:ed25519_verify/1024−8.9x25519_raw+6.9² From the fastest of 8 fresh copies of each binary (
claude/tmp-comb-sel-copies, this PR plus a measurement-only change toci/bench_compare.py).Checks
lake build, the emitter (with its audits) regeneratingsrc/asmto exactly this PR's files, everyci/check_*.py, and the X25519 and Ed25519 Wycheproof tests (aarch64, under qemu) pass.Generated by Claude Code