github.com/xfond/eth-implementation@v1.8.9-0.20180514135602-f6bc65fc6811/core/vm/instructions_test.go (about) 1 // Copyright 2017 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package vm 18 19 import ( 20 "math/big" 21 "testing" 22 23 "github.com/ethereum/go-ethereum/common" 24 "github.com/ethereum/go-ethereum/params" 25 ) 26 27 type twoOperandTest struct { 28 x string 29 y string 30 expected string 31 } 32 33 func testTwoOperandOp(t *testing.T, tests []twoOperandTest, opFn func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error)) { 34 var ( 35 env = NewEVM(Context{}, nil, params.TestChainConfig, Config{}) 36 stack = newstack() 37 pc = uint64(0) 38 ) 39 for i, test := range tests { 40 x := new(big.Int).SetBytes(common.Hex2Bytes(test.x)) 41 shift := new(big.Int).SetBytes(common.Hex2Bytes(test.y)) 42 expected := new(big.Int).SetBytes(common.Hex2Bytes(test.expected)) 43 stack.push(x) 44 stack.push(shift) 45 opFn(&pc, env, nil, nil, stack) 46 actual := stack.pop() 47 if actual.Cmp(expected) != 0 { 48 t.Errorf("Testcase %d, expected %v, got %v", i, expected, actual) 49 } 50 // Check pool usage 51 // 1.pool is not allowed to contain anything on the stack 52 // 2.pool is not allowed to contain the same pointers twice 53 if env.interpreter.intPool.pool.len() > 0 { 54 55 poolvals := make(map[*big.Int]struct{}) 56 poolvals[actual] = struct{}{} 57 58 for env.interpreter.intPool.pool.len() > 0 { 59 key := env.interpreter.intPool.get() 60 if _, exist := poolvals[key]; exist { 61 t.Errorf("Testcase %d, pool contains double-entry", i) 62 } 63 poolvals[key] = struct{}{} 64 } 65 } 66 } 67 } 68 69 func TestByteOp(t *testing.T) { 70 var ( 71 env = NewEVM(Context{}, nil, params.TestChainConfig, Config{}) 72 stack = newstack() 73 ) 74 tests := []struct { 75 v string 76 th uint64 77 expected *big.Int 78 }{ 79 {"ABCDEF0908070605040302010000000000000000000000000000000000000000", 0, big.NewInt(0xAB)}, 80 {"ABCDEF0908070605040302010000000000000000000000000000000000000000", 1, big.NewInt(0xCD)}, 81 {"00CDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff", 0, big.NewInt(0x00)}, 82 {"00CDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff", 1, big.NewInt(0xCD)}, 83 {"0000000000000000000000000000000000000000000000000000000000102030", 31, big.NewInt(0x30)}, 84 {"0000000000000000000000000000000000000000000000000000000000102030", 30, big.NewInt(0x20)}, 85 {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 32, big.NewInt(0x0)}, 86 {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 0xFFFFFFFFFFFFFFFF, big.NewInt(0x0)}, 87 } 88 pc := uint64(0) 89 for _, test := range tests { 90 val := new(big.Int).SetBytes(common.Hex2Bytes(test.v)) 91 th := new(big.Int).SetUint64(test.th) 92 stack.push(val) 93 stack.push(th) 94 opByte(&pc, env, nil, nil, stack) 95 actual := stack.pop() 96 if actual.Cmp(test.expected) != 0 { 97 t.Fatalf("Expected [%v] %v:th byte to be %v, was %v.", test.v, test.th, test.expected, actual) 98 } 99 } 100 } 101 102 func TestSHL(t *testing.T) { 103 // Testcases from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-145.md#shl-shift-left 104 tests := []twoOperandTest{ 105 {"0000000000000000000000000000000000000000000000000000000000000001", "00", "0000000000000000000000000000000000000000000000000000000000000001"}, 106 {"0000000000000000000000000000000000000000000000000000000000000001", "01", "0000000000000000000000000000000000000000000000000000000000000002"}, 107 {"0000000000000000000000000000000000000000000000000000000000000001", "ff", "8000000000000000000000000000000000000000000000000000000000000000"}, 108 {"0000000000000000000000000000000000000000000000000000000000000001", "0100", "0000000000000000000000000000000000000000000000000000000000000000"}, 109 {"0000000000000000000000000000000000000000000000000000000000000001", "0101", "0000000000000000000000000000000000000000000000000000000000000000"}, 110 {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "00", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"}, 111 {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "01", "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"}, 112 {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ff", "8000000000000000000000000000000000000000000000000000000000000000"}, 113 {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0100", "0000000000000000000000000000000000000000000000000000000000000000"}, 114 {"0000000000000000000000000000000000000000000000000000000000000000", "01", "0000000000000000000000000000000000000000000000000000000000000000"}, 115 {"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "01", "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"}, 116 } 117 testTwoOperandOp(t, tests, opSHL) 118 } 119 120 func TestSHR(t *testing.T) { 121 // Testcases from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-145.md#shr-logical-shift-right 122 tests := []twoOperandTest{ 123 {"0000000000000000000000000000000000000000000000000000000000000001", "00", "0000000000000000000000000000000000000000000000000000000000000001"}, 124 {"0000000000000000000000000000000000000000000000000000000000000001", "01", "0000000000000000000000000000000000000000000000000000000000000000"}, 125 {"8000000000000000000000000000000000000000000000000000000000000000", "01", "4000000000000000000000000000000000000000000000000000000000000000"}, 126 {"8000000000000000000000000000000000000000000000000000000000000000", "ff", "0000000000000000000000000000000000000000000000000000000000000001"}, 127 {"8000000000000000000000000000000000000000000000000000000000000000", "0100", "0000000000000000000000000000000000000000000000000000000000000000"}, 128 {"8000000000000000000000000000000000000000000000000000000000000000", "0101", "0000000000000000000000000000000000000000000000000000000000000000"}, 129 {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "00", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"}, 130 {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "01", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"}, 131 {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ff", "0000000000000000000000000000000000000000000000000000000000000001"}, 132 {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0100", "0000000000000000000000000000000000000000000000000000000000000000"}, 133 {"0000000000000000000000000000000000000000000000000000000000000000", "01", "0000000000000000000000000000000000000000000000000000000000000000"}, 134 } 135 testTwoOperandOp(t, tests, opSHR) 136 } 137 138 func TestSAR(t *testing.T) { 139 // Testcases from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-145.md#sar-arithmetic-shift-right 140 tests := []twoOperandTest{ 141 {"0000000000000000000000000000000000000000000000000000000000000001", "00", "0000000000000000000000000000000000000000000000000000000000000001"}, 142 {"0000000000000000000000000000000000000000000000000000000000000001", "01", "0000000000000000000000000000000000000000000000000000000000000000"}, 143 {"8000000000000000000000000000000000000000000000000000000000000000", "01", "c000000000000000000000000000000000000000000000000000000000000000"}, 144 {"8000000000000000000000000000000000000000000000000000000000000000", "ff", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"}, 145 {"8000000000000000000000000000000000000000000000000000000000000000", "0100", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"}, 146 {"8000000000000000000000000000000000000000000000000000000000000000", "0101", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"}, 147 {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "00", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"}, 148 {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "01", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"}, 149 {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ff", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"}, 150 {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0100", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"}, 151 {"0000000000000000000000000000000000000000000000000000000000000000", "01", "0000000000000000000000000000000000000000000000000000000000000000"}, 152 {"4000000000000000000000000000000000000000000000000000000000000000", "fe", "0000000000000000000000000000000000000000000000000000000000000001"}, 153 {"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "f8", "000000000000000000000000000000000000000000000000000000000000007f"}, 154 {"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "fe", "0000000000000000000000000000000000000000000000000000000000000001"}, 155 {"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ff", "0000000000000000000000000000000000000000000000000000000000000000"}, 156 {"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0100", "0000000000000000000000000000000000000000000000000000000000000000"}, 157 } 158 159 testTwoOperandOp(t, tests, opSAR) 160 } 161 162 func TestSGT(t *testing.T) { 163 tests := []twoOperandTest{ 164 165 {"0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000"}, 166 {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000000"}, 167 {"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000000"}, 168 {"0000000000000000000000000000000000000000000000000000000000000001", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000001"}, 169 {"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000"}, 170 {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000001"}, 171 {"0000000000000000000000000000000000000000000000000000000000000001", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000000"}, 172 {"8000000000000000000000000000000000000000000000000000000000000001", "8000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000"}, 173 {"8000000000000000000000000000000000000000000000000000000000000001", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000001"}, 174 {"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "8000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000"}, 175 {"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb", "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd", "0000000000000000000000000000000000000000000000000000000000000001"}, 176 {"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd", "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb", "0000000000000000000000000000000000000000000000000000000000000000"}, 177 } 178 testTwoOperandOp(t, tests, opSgt) 179 } 180 181 func TestSLT(t *testing.T) { 182 tests := []twoOperandTest{ 183 {"0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000"}, 184 {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000000"}, 185 {"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000000"}, 186 {"0000000000000000000000000000000000000000000000000000000000000001", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000000"}, 187 {"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000001"}, 188 {"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000"}, 189 {"0000000000000000000000000000000000000000000000000000000000000001", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000001"}, 190 {"8000000000000000000000000000000000000000000000000000000000000001", "8000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000000"}, 191 {"8000000000000000000000000000000000000000000000000000000000000001", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "0000000000000000000000000000000000000000000000000000000000000000"}, 192 {"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "8000000000000000000000000000000000000000000000000000000000000001", "0000000000000000000000000000000000000000000000000000000000000001"}, 193 {"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb", "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd", "0000000000000000000000000000000000000000000000000000000000000000"}, 194 {"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd", "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb", "0000000000000000000000000000000000000000000000000000000000000001"}, 195 } 196 testTwoOperandOp(t, tests, opSlt) 197 } 198 199 func opBenchmark(bench *testing.B, op func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error), args ...string) { 200 var ( 201 env = NewEVM(Context{}, nil, params.TestChainConfig, Config{}) 202 stack = newstack() 203 ) 204 // convert args 205 byteArgs := make([][]byte, len(args)) 206 for i, arg := range args { 207 byteArgs[i] = common.Hex2Bytes(arg) 208 } 209 pc := uint64(0) 210 bench.ResetTimer() 211 for i := 0; i < bench.N; i++ { 212 for _, arg := range byteArgs { 213 a := new(big.Int).SetBytes(arg) 214 stack.push(a) 215 } 216 op(&pc, env, nil, nil, stack) 217 stack.pop() 218 } 219 } 220 221 func BenchmarkOpAdd64(b *testing.B) { 222 x := "ffffffff" 223 y := "fd37f3e2bba2c4f" 224 225 opBenchmark(b, opAdd, x, y) 226 } 227 228 func BenchmarkOpAdd128(b *testing.B) { 229 x := "ffffffffffffffff" 230 y := "f5470b43c6549b016288e9a65629687" 231 232 opBenchmark(b, opAdd, x, y) 233 } 234 235 func BenchmarkOpAdd256(b *testing.B) { 236 x := "0802431afcbce1fc194c9eaa417b2fb67dc75a95db0bc7ec6b1c8af11df6a1da9" 237 y := "a1f5aac137876480252e5dcac62c354ec0d42b76b0642b6181ed099849ea1d57" 238 239 opBenchmark(b, opAdd, x, y) 240 } 241 242 func BenchmarkOpSub64(b *testing.B) { 243 x := "51022b6317003a9d" 244 y := "a20456c62e00753a" 245 246 opBenchmark(b, opSub, x, y) 247 } 248 249 func BenchmarkOpSub128(b *testing.B) { 250 x := "4dde30faaacdc14d00327aac314e915d" 251 y := "9bbc61f5559b829a0064f558629d22ba" 252 253 opBenchmark(b, opSub, x, y) 254 } 255 256 func BenchmarkOpSub256(b *testing.B) { 257 x := "4bfcd8bb2ac462735b48a17580690283980aa2d679f091c64364594df113ea37" 258 y := "97f9b1765588c4e6b69142eb00d20507301545acf3e1238c86c8b29be227d46e" 259 260 opBenchmark(b, opSub, x, y) 261 } 262 263 func BenchmarkOpMul(b *testing.B) { 264 x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 265 y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 266 267 opBenchmark(b, opMul, x, y) 268 } 269 270 func BenchmarkOpDiv256(b *testing.B) { 271 x := "ff3f9014f20db29ae04af2c2d265de17" 272 y := "fe7fb0d1f59dfe9492ffbf73683fd1e870eec79504c60144cc7f5fc2bad1e611" 273 opBenchmark(b, opDiv, x, y) 274 } 275 276 func BenchmarkOpDiv128(b *testing.B) { 277 x := "fdedc7f10142ff97" 278 y := "fbdfda0e2ce356173d1993d5f70a2b11" 279 opBenchmark(b, opDiv, x, y) 280 } 281 282 func BenchmarkOpDiv64(b *testing.B) { 283 x := "fcb34eb3" 284 y := "f97180878e839129" 285 opBenchmark(b, opDiv, x, y) 286 } 287 288 func BenchmarkOpSdiv(b *testing.B) { 289 x := "ff3f9014f20db29ae04af2c2d265de17" 290 y := "fe7fb0d1f59dfe9492ffbf73683fd1e870eec79504c60144cc7f5fc2bad1e611" 291 292 opBenchmark(b, opSdiv, x, y) 293 } 294 295 func BenchmarkOpMod(b *testing.B) { 296 x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 297 y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 298 299 opBenchmark(b, opMod, x, y) 300 } 301 302 func BenchmarkOpSmod(b *testing.B) { 303 x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 304 y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 305 306 opBenchmark(b, opSmod, x, y) 307 } 308 309 func BenchmarkOpExp(b *testing.B) { 310 x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 311 y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 312 313 opBenchmark(b, opExp, x, y) 314 } 315 316 func BenchmarkOpSignExtend(b *testing.B) { 317 x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 318 y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 319 320 opBenchmark(b, opSignExtend, x, y) 321 } 322 323 func BenchmarkOpLt(b *testing.B) { 324 x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 325 y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 326 327 opBenchmark(b, opLt, x, y) 328 } 329 330 func BenchmarkOpGt(b *testing.B) { 331 x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 332 y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 333 334 opBenchmark(b, opGt, x, y) 335 } 336 337 func BenchmarkOpSlt(b *testing.B) { 338 x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 339 y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 340 341 opBenchmark(b, opSlt, x, y) 342 } 343 344 func BenchmarkOpSgt(b *testing.B) { 345 x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 346 y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 347 348 opBenchmark(b, opSgt, x, y) 349 } 350 351 func BenchmarkOpEq(b *testing.B) { 352 x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 353 y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 354 355 opBenchmark(b, opEq, x, y) 356 } 357 func BenchmarkOpEq2(b *testing.B) { 358 x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff" 359 y := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201fffffffe" 360 opBenchmark(b, opEq, x, y) 361 } 362 func BenchmarkOpAnd(b *testing.B) { 363 x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 364 y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 365 366 opBenchmark(b, opAnd, x, y) 367 } 368 369 func BenchmarkOpOr(b *testing.B) { 370 x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 371 y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 372 373 opBenchmark(b, opOr, x, y) 374 } 375 376 func BenchmarkOpXor(b *testing.B) { 377 x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 378 y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 379 380 opBenchmark(b, opXor, x, y) 381 } 382 383 func BenchmarkOpByte(b *testing.B) { 384 x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 385 y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 386 387 opBenchmark(b, opByte, x, y) 388 } 389 390 func BenchmarkOpAddmod(b *testing.B) { 391 x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 392 y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 393 z := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 394 395 opBenchmark(b, opAddmod, x, y, z) 396 } 397 398 func BenchmarkOpMulmod(b *testing.B) { 399 x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 400 y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 401 z := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" 402 403 opBenchmark(b, opMulmod, x, y, z) 404 } 405 406 func BenchmarkOpSHL(b *testing.B) { 407 x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff" 408 y := "ff" 409 410 opBenchmark(b, opSHL, x, y) 411 } 412 func BenchmarkOpSHR(b *testing.B) { 413 x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff" 414 y := "ff" 415 416 opBenchmark(b, opSHR, x, y) 417 } 418 func BenchmarkOpSAR(b *testing.B) { 419 x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff" 420 y := "ff" 421 422 opBenchmark(b, opSAR, x, y) 423 } 424 func BenchmarkOpIsZero(b *testing.B) { 425 x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff" 426 opBenchmark(b, opIszero, x) 427 }