Consensys / goff

goff (go finite field) is a unix-like tool that generates fast field arithmetic in Go.
https://hackmd.io/@zkteam/goff
Apache License 2.0
76 stars 12 forks source link

Added assembly implementations for Add, Sub and Double. Minor speed improvement to Mul and Square. #20

Closed gbotrel closed 4 years ago

gbotrel commented 4 years ago

Assembly (x86) implementations of these functions are now constant time.

Benchmarks on 6 word modulus for Mul, Square:

BenchmarkMulAssignELEMENT-8     37.9          34.2          -9.76%
BenchmarkMulAssignELEMENT-8     35.5          32.9          -7.32%
BenchmarkMulAssignELEMENT-8     35.6          33.4          -6.18%
BenchmarkSquareELEMENT-8     32.7          30.9          -5.50%
BenchmarkSquareELEMENT-8     32.3          30.2          -6.50%
BenchmarkSquareELEMENT-8     33.7          29.9          -11.28%

Benchmarks on 6 word modulus for Double, Add, Sub:

BenchmarkDoubleELEMENT-8     9.44          4.76          -49.58%
BenchmarkDoubleELEMENT-8     9.49          4.72          -50.26%
BenchmarkDoubleELEMENT-8     9.29          4.72          -49.19%
BenchmarkDoubleELEMENT-8     9.37          4.72          -49.63%
BenchmarkAddELEMENT-8     5.99          5.40          -9.85%
BenchmarkAddELEMENT-8     6.01          5.19          -13.64%
BenchmarkAddELEMENT-8     6.20          5.22          -15.81%
BenchmarkAddELEMENT-8     7.25          5.21          -28.14%
BenchmarkSubELEMENT-8     4.40          4.86          +10.45%
BenchmarkSubELEMENT-8     7.09          4.69          -33.85%
BenchmarkSubELEMENT-8     6.95          4.98          -28.35%
BenchmarkSubELEMENT-8     4.43          4.77          +7.67%