github.com/consensys/gnark-crypto@v0.14.0/field/generator/internal/templates/element/reduce.go (about) 1 package element 2 3 const Reduce = ` 4 {{ define "reduce" }} 5 // if z ⩾ q → z -= q 6 if !z.smallerThanModulus() { 7 {{- if eq $.NbWords 1}} 8 z[0] -= q 9 {{- else}} 10 var b uint64 11 z[0], b = bits.Sub64(z[0], q0, 0) 12 {{- range $i := .NbWordsIndexesNoZero}} 13 {{- if eq $i $.NbWordsLastIndex}} 14 z[{{$i}}], _ = bits.Sub64(z[{{$i}}], q{{$i}}, b) 15 {{- else }} 16 z[{{$i}}], b = bits.Sub64(z[{{$i}}], q{{$i}}, b) 17 {{- end}} 18 {{- end}} 19 {{- end }} 20 } 21 22 {{- end }} 23 24 `