Skip to content

Commit 6c5e977

Browse files
committed
perf: fast path for mul when either of inputs is zero
1 parent 8549b3a commit 6c5e977

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

std/math/emulated/field_mul.go

+4
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ func (mc *mulCheck[T]) cleanEvaluations() {
193193
// mulMod returns a*b mod r. In practice it computes the result using a hint and
194194
// defers the actual multiplication check.
195195
func (f *Field[T]) mulMod(a, b *Element[T], _ uint, p *Element[T]) *Element[T] {
196+
// fast path - if one of the inputs is on zero limbs (it is zero), then the result is also zero
197+
if len(a.Limbs) == 0 || len(b.Limbs) == 0 {
198+
return f.Zero()
199+
}
196200
f.enforceWidthConditional(a)
197201
f.enforceWidthConditional(b)
198202
f.enforceWidthConditional(p)

0 commit comments

Comments
 (0)