From bda409a02a90ec1c1eaea7940df613eb3db469cf Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Mon, 4 Mar 2019 08:59:17 +0100 Subject: [PATCH] core/vm: optimize push1 --- core/vm/instructions.go | 15 +++++++++++++++ core/vm/jump_table.go | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 5195e716b2..a1188848dc 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -886,6 +886,21 @@ func opSuicide(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memo return nil, nil } +// opPush1 is a specialized version of pushN +func opPush1(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { + var ( + codeLen = uint64(len(contract.Code)) + integer = interpreter.intPool.get() + ) + *pc += 1 + if *pc < codeLen { + stack.push(integer.SetUint64(uint64(contract.Code[*pc]))) + } else { + stack.push(integer.SetUint64(0)) + } + return nil, nil +} + // following functions are used by the instruction jump table // make log instruction function diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go index dde11dacf1..90d8e64dba 100644 --- a/core/vm/jump_table.go +++ b/core/vm/jump_table.go @@ -567,7 +567,7 @@ func newFrontierInstructionSet() [256]operation { valid: true, }, PUSH1: { - execute: makePush(1, 1), + execute: opPush1, constantGas: GasFastestStep, minStack: minStack(0, 1), maxStack: maxStack(0, 1),