Repository navigation
x86-64 vg_ecdsa_p256_verify_ifma: Q's odd multiples kept as limbs - #4983
Merged
Merged
Conversation
The loop in vectors made the entry of a digit's multiple of Q from the words of the table for each digit of Q's scalar that is not zero. The entries of 3Q, ..., 15Q are now made once, before the loop, and kept as limbs in the working space (tabEnt): a digit loads its entry (loadAPieces, loadBPieces). Q's own is still made from its words. The allocator of the blocks' registers aims each value at the register its result is wanted in (wants), which saves moves at the ends of the blocks; vg_ecdh_p256_ifma has the same blocks, so its code changes too. The working space's layout (publicJointIfma, SL, MXV, KB, TOFF) makes room for the entries; ECDH's slots stay where they were (EO). Proofs: the symbolic execution's stores are at offsets of one residue modulo 32 (Par.al); a stage's check says how much of the slots its code stores to (chkSegW, KeptW); LEnt, LTab and the lemmas of an entry stored and loaded (ConvOk, Pass); the loop's invariant has the entries (VInv.ltab, vtabs_ok); the layouts and taint checks of publicJointIfma. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHFEUkKJRQvsEBN9oBp
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.
For each digit of
Q's scalar that is not zero, the loop in vectors made the entry of the digit's multiple ofQfrom the words of the table (convQPieces: words to 52-bit limbs, for the five field elements of an entry). Now the entries of3Q, …,15Qare made once, before the loop, and kept as limbs in the working space; a digit loads its entry (seven loads and threevpermq).Q's own entry is still made from its words.The allocator of the blocks' registers (
Impl/P256/X86_64/Ifma/Vec.lean) also aims each value at the register its result is wanted in (wants,AS.getRegFor), which saves register moves at the ends of the blocks: the doubling is 736 instructions for 750, the addition 1,038 for 1,054, the conversion 127 for 138, with the samevpmadd52. The blocks arevg_ecdh_p256_ifma's too, so its generated code changes with them.vg_ecdsa_p256_verify_ifmais 23,823 instructions for 22,874 (the seven entries' code is written out), 880 of themvpmadd52luqorvpmadd52huqas before;vg_ecdh_p256_ifmais 7,249 for 7,326.No change to
TCB/orSpec/.Measurements
Benchmarks run 43134292048, against
main(57d3b56734), scoped to what changed (modules=ecdsa_p256 ecdh_p256,groups=ecdsa_p256_.*_verify ecdh_p256,arches=x86_64,cpu_features=-), on an AMD EPYC 9V74 (which has AVX512_IFMA); one run of each side, interleaved:mainecdsa_p256_sha256_verify/64ecdsa_p256_sha256_verify/1024ecdsa_p256_sha256_verify/16384ecdsa_p256_sha384_verify/64ecdsa_p256_sha384_verify/1024ecdsa_p256_sha384_verify/16384ecdh_p256/32On the machine the proofs were built on (an Emerald Rapids Xeon VM, noisy), a harness that times the verification function alone over 6,000 signatures, taking the least of the runs for each, measures less: 0.6% less time (three runs: 0.61%, 0.64%, 0.65%).
The code
Impl/P256/X86_64/Ifma/Loop.lean:tabEnt c a, forafrom 1 to 7:rcxandrdxat the words of entrya + 1of the table and of itsZ²andZ³,convQPieces, then the entry's seven vectors stored (packTPieces,storeEnt): the five ofta, the first four limbs oftb's first lane as one vector, and its fifth. An entry is 200 bytes: the last vector's three other lanes are written over by the next entry.qBody: after the digit's sign,cmp r8, 1;Q's entry as before, any other's from its limbs (entryT,loadAPieces,loadBPieces).regionAt mx:regionwith the offset of MXCSR's two words a parameter (region := regionAt MX, whichvg_ecdh_p256_ifmauses).The working space's 8,192 bytes, from the table of
Q's multiples as words (nine entries, to 3,616): the entries as limbs (TOFF, 3,616, 1,424 bytes); the vectors' slots (SL, 5,056), of which the blocks write nine; the generator's digits (5,344); MXCSR's two words (MXV, 5,864); the table'sZ²andZ³(5,920); the blocks' constants (KB, 6,432, to the end). The selected entry'sZ²andZ³, which onlyJoint.runuses, are in the first two slots, which the vectors' code has left by then (publicJointIfma).vg_ecdh_p256_ifma's slots stay where they were (EO).The proofs
Proof/P256/X86_64/Ifma/Sym.lean: the stores a run of the symbolic execution checks are at offsets of one residue modulo 32 (Par.al, zero for the blocks), so that it runs an entry's stores too, which are 200 bytes apart.Stage.lean,Step.lean,DblOk.lean: a stage's check says how much of the slots its code stores to (chkSegW,KeptW): the nine slots of the joint multiplication's blocks (chkSeg,Kept), whose working space has the generator's digits past them, or the twenty of ECDH'ssaveAcc.ConvOk.lean:LEnt, what the 25 quadwords of an entry at an address stand for, asEntOksays of the registers;loadA_ok,loadB_ok(an entry loaded) andstore_ok,lent_of(an entry stored).Pass.lean:LTab, the seven entries, of the table's words in the same memory;tabEnt_ok,vtab_ok;qEntry_okwith the branch (cmp1_ok,entryT_ok).VLoop.lean,Window.lean: the loop's invariant hasLTab(VInv.ltab), whichvtabs_okestablishes aftervinit_ok; the layout's numbers (vW,VLay).Timing.lean,JointChecks.lean,Config.lean: the taint check of the entries' code (VChecks.tab), and the layouts and checks ofpublicJointIfmathat named the selected entry's and the table'sZ²andZ³.Checks
lake build --log-level=warningandlake env lean --run Emit.lean: the regenerated x86-64 crate changes onlyecdsa_p256andecdh_p256. Every step of theStatic checksjob,ci/check_lean_public_imports.pyon the modules changed,cargo fmt --check,cargo clippy --all-targets -- -D warnings, andcargo test --releaseof the P-256, ECDSA and ECDH tests with Wycheproof on a CPU with AVX512_IFMA, where the dispatchers run the two functions.🤖 Generated with Claude Code
https://claude.ai/code/session_01TKUFHFEUkKJRQvsEBN9oBp