diff options
author | Martin Holst Swende <martin@swende.se> | 2018-06-14 17:23:37 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-06-14 17:23:37 +0800 |
commit | 947e0afeb3bce9c52548979daddd1e00aa0d7ba8 (patch) | |
tree | ab3e44f8cf74d60e541df07c5ef81ad0ca9797d2 /core/vm/instructions_test.go | |
parent | 1836366ac19e30f157570e61342fae53bc6c8a57 (diff) | |
download | go-tangerine-947e0afeb3bce9c52548979daddd1e00aa0d7ba8.tar.gz go-tangerine-947e0afeb3bce9c52548979daddd1e00aa0d7ba8.tar.zst go-tangerine-947e0afeb3bce9c52548979daddd1e00aa0d7ba8.zip |
core/vm: optimize MSTORE and SLOAD (#16939)
* vm/test: add tests+benchmarks for mstore
* core/vm: less alloc and copying for mstore
* core/vm: less allocs in sload
* vm: check for errors more correctly
Diffstat (limited to 'core/vm/instructions_test.go')
-rw-r--r-- | core/vm/instructions_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/core/vm/instructions_test.go b/core/vm/instructions_test.go index 0de558612..f51e6363f 100644 --- a/core/vm/instructions_test.go +++ b/core/vm/instructions_test.go @@ -425,3 +425,42 @@ func BenchmarkOpIsZero(b *testing.B) { x := "FBCDEF090807060504030201ffffffffFBCDEF090807060504030201ffffffff" opBenchmark(b, opIszero, x) } + +func TestOpMstore(t *testing.T) { + var ( + env = NewEVM(Context{}, nil, params.TestChainConfig, Config{}) + stack = newstack() + mem = NewMemory() + ) + mem.Resize(64) + pc := uint64(0) + v := "abcdef00000000000000abba000000000deaf000000c0de00100000000133700" + stack.pushN(new(big.Int).SetBytes(common.Hex2Bytes(v)), big.NewInt(0)) + opMstore(&pc, env, nil, mem, stack) + if got := common.Bytes2Hex(mem.Get(0, 32)); got != v { + t.Fatalf("Mstore fail, got %v, expected %v", got, v) + } + stack.pushN(big.NewInt(0x1), big.NewInt(0)) + opMstore(&pc, env, nil, mem, stack) + if common.Bytes2Hex(mem.Get(0, 32)) != "0000000000000000000000000000000000000000000000000000000000000001" { + t.Fatalf("Mstore failed to overwrite previous value") + } +} + +func BenchmarkOpMstore(bench *testing.B) { + var ( + env = NewEVM(Context{}, nil, params.TestChainConfig, Config{}) + stack = newstack() + mem = NewMemory() + ) + mem.Resize(64) + pc := uint64(0) + memStart := big.NewInt(0) + value := big.NewInt(0x1337) + + bench.ResetTimer() + for i := 0; i < bench.N; i++ { + stack.pushN(value, memStart) + opMstore(&pc, env, nil, mem, stack) + } +} |