Skip to content

Add opt-in BMI2/ADX Montgomery multiplication for the Pasta fields on x86_64 - #285

Open
lamb356 wants to merge 2 commits into
zakura-core:mainfrom
lamb356:devin/split-1-x86-asm
Open

Add opt-in BMI2/ADX Montgomery multiplication for the Pasta fields on x86_64#285
lamb356 wants to merge 2 commits into
zakura-core:mainfrom
lamb356:devin/split-1-x86-asm

Conversation

@lamb356

@lamb356 lamb356 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in BMI2/ADX inline-assembly Montgomery multiplication backend for the Pasta fields on x86_64, behind a new x86_64-asm feature (off by default). The repo already ships an aarch64 assembly path for Apple silicon; this is the x86_64 counterpart.

  • New crates/pasta_curves/src/fields/x86_64_asm.rs: 4x4-limb Montgomery multiply/square using mulx/adcx/adox carry chains, wrapped in narrow unsafe functions.
  • Fp/Fq dispatch to the asm path for mul, square, and repeated square-and-multiply when feature = "x86_64-asm" and target_arch = "x86_64"; the portable Rust path is unchanged and remains the default everywhere else.
  • No changes to representation, transcripts, proof format, or verifier behavior — this is a drop-in replacement for the field multiplication inner loop (~22ns → ~16.5ns per mul on our test box).

Measured on the Orchard k=11 prover benchmark (8 threads): roughly 10ms off the end-to-end proving time on its own. All numbers in this PR series were measured on an 8-thread VM — if you have a 16-core machine handy we'd appreciate your numbers, since the dominant stages scale with cores. Reproduce with:
RAYON_NUM_THREADS=16 ORCHARD_K11_PROVER_THREADS=16 cargo bench -p zakura-orchard --features circuit,orbits --bench orchard_k11_prover

Part of the split of #273 (piece 1 of 6, as proposed there).

Testing

  • cargo test --release --features x86_64-asm in crates/pasta_curves (91 + 1 tests pass, exercising both fields against the portable implementation).
  • Default build (no feature) unchanged; cargo check --locked --all-features --all-targets and MSRV (1.91) check clean.
  • cargo fmt --all -- --check clean.

@ValarDragon

Copy link
Copy Markdown
Contributor

Will test this same time were testing all the other x86 work in repo!

lamb356 and others added 2 commits September 2, 2026 00:17
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants