Skip to content

Commit 52519dc

Browse files
authored
Merge pull request #154 from ethereum-optimism/cl/revert-fast-arithmetic-changes
chore: Revert #131
2 parents 1f48878 + 2748e74 commit 52519dc

File tree

2 files changed

+73
-21
lines changed

2 files changed

+73
-21
lines changed

rvgo/fast/yul256.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func beWordAsB32(v U256) [32]byte {
1717
return v.Bytes32()
1818
}
1919

20+
// nolint:unused
2021
func add(x, y U256) (out U256) {
2122
out.Add(&x, &y)
2223
return
@@ -32,21 +33,25 @@ func mul(x, y U256) (out U256) {
3233
return
3334
}
3435

36+
// nolint:unused
3537
func div(x, y U256) (out U256) {
3638
out.Div(&x, &y)
3739
return
3840
}
3941

42+
// nolint:unused
4043
func sdiv(x, y U256) (out U256) { // note: signed overflow semantics are the same between Go and EVM assembly
4144
out.SDiv(&x, &y)
4245
return
4346
}
4447

48+
// nolint:unused
4549
func mod(x, y U256) (out U256) {
4650
out.Mod(&x, &y)
4751
return
4852
}
4953

54+
// nolint:unused
5055
func smod(x, y U256) (out U256) {
5156
out.SMod(&x, &y)
5257
return
@@ -57,41 +62,47 @@ func not(x U256) (out U256) {
5762
return
5863
}
5964

65+
// nolint:unused
6066
func lt(x, y U256) (out U256) {
6167
if x.Lt(&y) {
6268
out.SetUint64(1)
6369
}
6470
return
6571
}
6672

73+
// nolint:unused
6774
func gt(x, y U256) (out U256) {
6875
if x.Gt(&y) {
6976
out.SetUint64(1)
7077
}
7178
return
7279
}
7380

81+
// nolint:unused
7482
func slt(x, y U256) (out U256) {
7583
if x.Slt(&y) {
7684
out.SetUint64(1)
7785
}
7886
return
7987
}
8088

89+
// nolint:unused
8190
func sgt(x, y U256) (out U256) {
8291
if x.Sgt(&y) {
8392
out.SetUint64(1)
8493
}
8594
return
8695
}
8796

97+
// nolint:unused
8898
func eq(x, y U256) (out U256) {
8999
if x.Eq(&y) {
90100
out.SetUint64(1)
91101
}
92102
return
93103
}
94104

105+
// nolint:unused
95106
func iszero(x U256) bool {
96107
return x.IsZero()
97108
}
@@ -106,11 +117,13 @@ func or(x, y U256) (out U256) {
106117
return
107118
}
108119

120+
// nolint:unused
109121
func xor(x, y U256) (out U256) {
110122
out.Xor(&x, &y)
111123
return
112124
}
113125

126+
// returns y << x
114127
func shl(x, y U256) (out U256) {
115128
if !x.IsUint64() && x.Uint64() >= 256 {
116129
return
@@ -129,6 +142,7 @@ func shr(x, y U256) (out U256) {
129142
}
130143

131144
// returns y >> x (signed)
145+
// nolint:unused
132146
func sar(x, y U256) (out U256) {
133147
if !x.IsUint64() && x.Uint64() >= 256 {
134148
return

rvgo/fast/yul64.go

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func shortToU256(v uint16) U256 {
2020
return *uint256.NewInt(uint64(v))
2121
}
2222

23+
// nolint:unused
2324
func longToU256(v uint64) U256 {
2425
return *uint256.NewInt(v)
2526
}
@@ -65,81 +66,118 @@ func signExtend64To256(v U64) U256 {
6566
}
6667

6768
func add64(x, y uint64) uint64 {
68-
return u256ToU64(add(longToU256(x), longToU256(y)))
69+
return x + y
6970
}
7071

7172
func sub64(x, y uint64) uint64 {
72-
return u256ToU64(sub(longToU256(x), longToU256(y)))
73+
return x - y
7374
}
7475

7576
func mul64(x, y uint64) uint64 {
76-
return u256ToU64(mul(longToU256(x), longToU256(y)))
77+
return x * y
7778
}
7879

7980
func div64(x, y uint64) uint64 {
80-
return u256ToU64(div(longToU256(x), longToU256(y)))
81+
if y == 0 {
82+
return 0
83+
}
84+
return x / y
8185
}
8286

8387
func sdiv64(x, y uint64) uint64 { // note: signed overflow semantics are the same between Go and EVM assembly
84-
return u256ToU64(sdiv(signExtend64To256(x), signExtend64To256(y)))
88+
if y == 0 {
89+
return 0
90+
}
91+
if x == uint64(1<<63) && y == ^uint64(0) {
92+
return 1 << 63
93+
}
94+
return uint64(int64(x) / int64(y))
8595
}
8696

8797
func mod64(x, y uint64) uint64 {
88-
return u256ToU64(mod(longToU256(x), longToU256(y)))
98+
if y == 0 {
99+
return 0
100+
} else {
101+
return x % y
102+
}
89103
}
90104

91105
func smod64(x, y uint64) uint64 {
92-
return u256ToU64(smod(signExtend64To256(x), signExtend64To256(y)))
106+
if y == 0 {
107+
return 0
108+
} else {
109+
return uint64(int64(x) % int64(y))
110+
}
93111
}
94112

95113
func not64(x uint64) uint64 {
96-
return u256ToU64(not(longToU256(x)))
114+
return ^x
97115
}
98116

99117
func lt64(x, y uint64) uint64 {
100-
return u256ToU64(lt(longToU256(x), longToU256(y)))
118+
if x < y {
119+
return 1
120+
} else {
121+
return 0
122+
}
101123
}
102124

103125
func gt64(x, y uint64) uint64 {
104-
return u256ToU64(gt(longToU256(x), longToU256(y)))
126+
if x > y {
127+
return 1
128+
} else {
129+
return 0
130+
}
105131
}
106132

107133
func slt64(x, y uint64) uint64 {
108-
return u256ToU64(slt(signExtend64To256(x), signExtend64To256(y)))
134+
if int64(x) < int64(y) {
135+
return 1
136+
} else {
137+
return 0
138+
}
109139
}
110140

111141
func sgt64(x, y uint64) uint64 {
112-
return u256ToU64(sgt(signExtend64To256(x), signExtend64To256(y)))
142+
if int64(x) > int64(y) {
143+
return 1
144+
} else {
145+
return 0
146+
}
113147
}
114148

115149
func eq64(x, y uint64) uint64 {
116-
return u256ToU64(eq(longToU256(x), longToU256(y)))
150+
if x == y {
151+
return 1
152+
} else {
153+
return 0
154+
}
117155
}
118156

119157
func iszero64(x uint64) bool {
120-
return iszero(longToU256(x))
158+
return x == 0
121159
}
122160

123-
func and64(x, y uint64) U64 {
124-
return u256ToU64(and(longToU256(x), longToU256(y)))
161+
func and64(x, y uint64) uint64 {
162+
return x & y
125163
}
126164

127165
func or64(x, y uint64) uint64 {
128-
return u256ToU64(or(longToU256(x), longToU256(y)))
166+
return x | y
129167
}
130168

131169
func xor64(x, y uint64) uint64 {
132-
return u256ToU64(xor(longToU256(x), longToU256(y)))
170+
return x ^ y
133171
}
134172

135173
func shl64(x, y uint64) uint64 {
136-
return u256ToU64(shl(longToU256(x), longToU256(y)))
174+
return y << x
137175
}
138176

139177
func shr64(x, y uint64) uint64 {
140-
return u256ToU64(shr(longToU256(x), longToU256(y)))
178+
return y >> x
141179
}
142180

143181
func sar64(x, y uint64) uint64 {
144-
return u256ToU64(sar(longToU256(x), signExtend64To256(y)))
182+
return uint64(int64(y) >> x)
145183
}

0 commit comments

Comments
 (0)