Skip to content

Add opt-in AVX-512 IFMA batched field arithmetic for the Pasta fields - #286

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

Add opt-in AVX-512 IFMA batched field arithmetic for the Pasta fields#286
lamb356 wants to merge 2 commits into
zakura-core:mainfrom
lamb356:devin/split-2-ifma

Conversation

@lamb356

@lamb356 lamb356 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds opt-in AVX-512 IFMA batched field arithmetic for the Pasta fields behind a new ifma feature (off by default, runtime CPU detection, scalar fallback always available).

  • New crates/pasta_curves/src/fields/ifma.rs: 8-way radix-52 kernels for Fp/Fq batched multiplication, squaring, and scaling (fp_mul_slice, fp_sqr_slice, fq_mul_slice, fq_sqr_slice, ...). Inputs/outputs stay in the canonical 4x64 Montgomery form; the radix-52 transpose happens inside the kernel.
  • Deferred dot-product kernel in crates/pasta_curves/src/deferred.rs: accumulates unreduced 576-bit sums matching the scalar deferred accumulator exactly (composes with the deferred inner products that landed in Add deferred field inner products #277/Process deferred inner products in 32-product blocks #280), exposed as fp_inner_product/fq_inner_product.
  • Runtime is_x86_feature_detected! dispatch — non-AVX-512 CPUs and non-x86 targets take the scalar path; default builds don't compile any of it.

Isolated speedup ~1.85x per field mul (21.05ns → 11.41ns); end-to-end Orchard k=11 proving improved ~147ms → ~137ms at the point this was measured in the full stack (8 threads). Benchmarks in this series were 8-thread only — 16-core numbers from your side would be appreciated:
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 2 of 6). The FFT/evaluator PR (piece 6) builds on the batched slice ops added here.

Testing

  • cargo test --release --features ifma in crates/pasta_curves: batch-op tests sweep lengths 0→5000 including carry-normalization boundaries, validated against the scalar path on an AVX-512 IFMA box.
  • Scalar fallback validated by running the same suites with the feature off / detection failing.
  • cargo check --locked --all-features --all-targets, MSRV (1.91) check, and cargo fmt --all -- --check clean.

@ValarDragon

Copy link
Copy Markdown
Contributor

Nice work! Excited to test this soon!

lamb356 and others added 2 commits September 2, 2026 00:19
Adds an ifma feature to zakura-pasta-curves with 8-way AVX-512 IFMA
kernels for batched Montgomery multiplication, squaring, scaling, and a
deferred-reduction dot product over Fp/Fq, with runtime CPU detection
and scalar fallbacks. halo2 gains a TypeId-dispatched batch module used
for iFFT divisor scaling and deferred inner products.

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