Skip to content

perf: tighter Montgomery multiplication ASM #59

Description

@MatteoMer

Problem

Montgomery mul at 22-25ns vs arkworks' 18-20ns (~25% gap). Current BMI2+ADX ASM may have suboptimal instruction scheduling.

Approach

Audit current montgomeryMulX86 against arkworks ff-asm for:

  • Pipeline stalls between dependent mulxq/adcxq/adoxq sequences
  • Unnecessary register moves or spills
  • Reduction scheduling: interleaved CIOS vs deferred reduction
  • Register allocation (currently cannot use rbp due to LLVM frame pointer)

Impact

Montgomery mul is the single most called field operation. A 20% improvement applies to every curve addition, every Miller loop step, every sumcheck polynomial evaluation. Would save ~1s on primes_large (6.6s → ~5.5s).

Files

  • src/field/mod.zigmontgomeryMulX86 in MontgomeryField and BN254Scalar

Benchmark baseline

  • Fp.mul: 22-25 ns/op
  • Fr.mul: 24-25 ns/op
  • Target: 18-20 ns/op

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions