Repository navigation
AArch64 Montgomery products of 4 words: no clearing of the accumulator words the first row sets - #2747
Merged
Conversation
… first row sets 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
The first row by rowInit made ecdh_p384 1.1% slower on Neoverse N2. 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
reaperhulk
enabled auto-merge
October 18, 2026 07:08
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.
What
AArch64 Montgomery products of 4-word moduli (
mulR,Impl/Mont/AArch64.lean) no longer clear the accumulator words that their first row writes anyway.rowInit, writes words0ton - 1bymul. The setup now clears only the top two words (accClear), not all six: 4 fewermovzper multiplication.mulRis shared, so this reaches P-192, P-224, P-256, secp256k1 and brainpoolP256r1 alike. In all, 1832movzgo from the generated code.orr x1, x8, x8, becausex8is no longer cleared and the existing forwarding pass can reuse it.rowInitnow takes the register its chain reads through as a parameter;mulRpassesx0, so its code is otherwise unchanged.No
TCB/orSpec/changes.Proof
RowInit.lean:mulsLo_okandrowInit_okneed only the words past the multiplicand's cleared, i.e. the top one.rowInit_oktakes anyPtrregister.Round.lean:accV, the accumulator's value entering roundi(zero entering the first);AccInit, what the first round needs: the top two words cleared, and all of them unless the first row isrowInit.prodRow_okandround_okare stated with them.Rounds.lean:rounds_ok's invariant usesaccVfromAccInit.Ops.lean:setup_okprovesAccInit(wins_zero_lt,accClear_sub).mulR_okWand the P-256 verifier'smul_ok(VerifySparse/Ops.lean) readaccVatn > 0as the window's value.Performance
Benchmarks run 39103992124: aarch64,
cpu_features='-', againstmain(e3794cde7), withmodules=ecdh_p256 ecdsa_p256 ec_p256 ecdh_p384 ecdsa_p384 ec_p384 ecdh_secp256k1(secp256k1 as a canary for the other 4-word curves). The other 4-word curves (P-192, P-224, brainpoolP256r1) sharemulRand were not benchmarked.ec_p256_public_key/65ecdh_p256/32ecdh_secp256k1/32ecdsa_p256_sha256_sign/64ecdsa_p256_sha256_sign/1024ecdsa_p256_sha256_sign/16384ecdsa_p256_sha256_verify/64ecdsa_p256_sha256_verify/1024ecdsa_p256_sha256_verify/16384ecdsa_p256_sha384_sign/64ecdsa_p256_sha384_sign/1024ecdsa_p256_sha384_sign/16384ecdsa_p256_sha384_verify/64ecdsa_p256_sha384_verify/1024ecdsa_p256_sha384_verify/16384The cleared registers'
movz(zero idioms) are nearly free on Neoverse N2, hence the small change.P-384, measured and dropped. That run's head also gave P-384's product and square the same first row (
rowInitstraight into the words, then the chain of high words), dropping 6movzand 6addsper product and 5 of each per square. It was slower on N2:ecdh_p384/48: 189.42 → 191.54 µs (1.1% slower);ecdsa_p384_sha384_sign/16384: 63.08 → 63.95 µs (1.4% slower).The interleaved
mul/addsrow, as in s2n-bignum's_alt, schedules better there. So this PR leaves P-384 as it is:src/asm/aarch64/p384_mont.rsis byte-identical tomain's, and its rows above don't apply.Tests
lake build,Emit.lean --checkand theci/check_*.pyscripts pass.cargo test --release --target aarch64-unknown-linux-gnu), both by default and withVG_CPU_FEATURES=none.🤖 Generated with Claude Code
https://claude.ai/code/session_01Ma2fA9rUTPXEEQjYyCMCRw