Skip to content

Commit

Permalink
uint256: optimize AddMod (#165)
Browse files Browse the repository at this point in the history
```
AddMod/small/uint256-8   21.0ns ±44%  17.0ns ±43%     ~     (p=0.052 n=10+10)
AddMod/mod64/uint256-8   28.6ns ±36%  26.6ns ±44%     ~     (p=0.481 n=10+10)
AddMod/mod128/uint256-8  56.1ns ±43%  53.7ns ±49%     ~     (p=0.810 n=10+10)
AddMod/mod192/uint256-8  62.0ns ±44%  62.2ns ±44%     ~     (p=0.971 n=10+10)
AddMod/mod256/uint256-8  25.4ns ±25%  12.0ns ±44%  -52.74%  (p=0.000 n=10+9)
```
  • Loading branch information
AaronChen0 authored May 10, 2024
1 parent 09331ab commit 34f0760
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func BenchmarkSetBytes(b *testing.B) {
val.SetBytes(bytearr[:27])
val.SetBytes(bytearr[:28])
val.SetBytes(bytearr[:29])
val.SetBytes(bytearr[:20])
val.SetBytes(bytearr[:30])
val.SetBytes(bytearr[:31])
val.SetBytes(bytearr[:32])
}
Expand Down
6 changes: 2 additions & 4 deletions uint256.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,10 @@ func (z *Int) AddMod(x, y, m *Int) *Int {

// final sub was unnecessary
if c1 == 0 && c2 != 0 {
copy((*z)[:], res[:])
return z
return z.Set(&res)
}

copy((*z)[:], tmp[:])
return z
return z.Set(&tmp)
}

if m.IsZero() {
Expand Down

0 comments on commit 34f0760

Please sign in to comment.