Skip to content

Commit

Permalink
perf: fast path for mul when either of inputs is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
ivokub committed Feb 6, 2025
1 parent 8549b3a commit 6c5e977
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions std/math/emulated/field_mul.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ func (mc *mulCheck[T]) cleanEvaluations() {
// mulMod returns a*b mod r. In practice it computes the result using a hint and
// defers the actual multiplication check.
func (f *Field[T]) mulMod(a, b *Element[T], _ uint, p *Element[T]) *Element[T] {
// fast path - if one of the inputs is on zero limbs (it is zero), then the result is also zero
if len(a.Limbs) == 0 || len(b.Limbs) == 0 {
return f.Zero()
}
f.enforceWidthConditional(a)
f.enforceWidthConditional(b)
f.enforceWidthConditional(p)
Expand Down

0 comments on commit 6c5e977

Please sign in to comment.