forked from cerc-io/plugeth
core/vm: improved push instructions
Improved push instructions by removing unnecessary big int allocations and by making it int instead of big.Int
This commit is contained in:
parent
3ee75bec9f
commit
a816e75662
@ -706,10 +706,23 @@ func makeLog(size int) executionFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// make push instruction function
|
// make push instruction function
|
||||||
func makePush(size uint64, bsize *big.Int) executionFunc {
|
func makePush(size uint64, pushByteSize int) executionFunc {
|
||||||
return func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
return func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
||||||
byts := getData(contract.Code, evm.interpreter.intPool.get().SetUint64(*pc+1), bsize)
|
codeLen := len(contract.Code)
|
||||||
stack.push(new(big.Int).SetBytes(byts))
|
|
||||||
|
startMin := codeLen
|
||||||
|
if int(*pc+1) < startMin {
|
||||||
|
startMin = int(*pc + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
endMin := codeLen
|
||||||
|
if startMin+pushByteSize < endMin {
|
||||||
|
endMin = startMin + pushByteSize
|
||||||
|
}
|
||||||
|
|
||||||
|
integer := evm.interpreter.intPool.get()
|
||||||
|
stack.push(integer.SetBytes(common.RightPadBytes(contract.Code[startMin:endMin], pushByteSize)))
|
||||||
|
|
||||||
*pc += size
|
*pc += size
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -421,193 +421,193 @@ func NewFrontierInstructionSet() [256]operation {
|
|||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH1: {
|
PUSH1: {
|
||||||
execute: makePush(1, big.NewInt(1)),
|
execute: makePush(1, 1),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH2: {
|
PUSH2: {
|
||||||
execute: makePush(2, big.NewInt(2)),
|
execute: makePush(2, 2),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH3: {
|
PUSH3: {
|
||||||
execute: makePush(3, big.NewInt(3)),
|
execute: makePush(3, 3),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH4: {
|
PUSH4: {
|
||||||
execute: makePush(4, big.NewInt(4)),
|
execute: makePush(4, 4),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH5: {
|
PUSH5: {
|
||||||
execute: makePush(5, big.NewInt(5)),
|
execute: makePush(5, 5),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH6: {
|
PUSH6: {
|
||||||
execute: makePush(6, big.NewInt(6)),
|
execute: makePush(6, 6),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH7: {
|
PUSH7: {
|
||||||
execute: makePush(7, big.NewInt(7)),
|
execute: makePush(7, 7),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH8: {
|
PUSH8: {
|
||||||
execute: makePush(8, big.NewInt(8)),
|
execute: makePush(8, 8),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH9: {
|
PUSH9: {
|
||||||
execute: makePush(9, big.NewInt(9)),
|
execute: makePush(9, 9),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH10: {
|
PUSH10: {
|
||||||
execute: makePush(10, big.NewInt(10)),
|
execute: makePush(10, 10),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH11: {
|
PUSH11: {
|
||||||
execute: makePush(11, big.NewInt(11)),
|
execute: makePush(11, 11),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH12: {
|
PUSH12: {
|
||||||
execute: makePush(12, big.NewInt(12)),
|
execute: makePush(12, 12),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH13: {
|
PUSH13: {
|
||||||
execute: makePush(13, big.NewInt(13)),
|
execute: makePush(13, 13),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH14: {
|
PUSH14: {
|
||||||
execute: makePush(14, big.NewInt(14)),
|
execute: makePush(14, 14),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH15: {
|
PUSH15: {
|
||||||
execute: makePush(15, big.NewInt(15)),
|
execute: makePush(15, 15),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH16: {
|
PUSH16: {
|
||||||
execute: makePush(16, big.NewInt(16)),
|
execute: makePush(16, 16),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH17: {
|
PUSH17: {
|
||||||
execute: makePush(17, big.NewInt(17)),
|
execute: makePush(17, 17),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH18: {
|
PUSH18: {
|
||||||
execute: makePush(18, big.NewInt(18)),
|
execute: makePush(18, 18),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH19: {
|
PUSH19: {
|
||||||
execute: makePush(19, big.NewInt(19)),
|
execute: makePush(19, 19),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH20: {
|
PUSH20: {
|
||||||
execute: makePush(20, big.NewInt(20)),
|
execute: makePush(20, 20),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH21: {
|
PUSH21: {
|
||||||
execute: makePush(21, big.NewInt(21)),
|
execute: makePush(21, 21),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH22: {
|
PUSH22: {
|
||||||
execute: makePush(22, big.NewInt(22)),
|
execute: makePush(22, 22),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH23: {
|
PUSH23: {
|
||||||
execute: makePush(23, big.NewInt(23)),
|
execute: makePush(23, 23),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH24: {
|
PUSH24: {
|
||||||
execute: makePush(24, big.NewInt(24)),
|
execute: makePush(24, 24),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH25: {
|
PUSH25: {
|
||||||
execute: makePush(25, big.NewInt(25)),
|
execute: makePush(25, 25),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH26: {
|
PUSH26: {
|
||||||
execute: makePush(26, big.NewInt(26)),
|
execute: makePush(26, 26),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH27: {
|
PUSH27: {
|
||||||
execute: makePush(27, big.NewInt(27)),
|
execute: makePush(27, 27),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH28: {
|
PUSH28: {
|
||||||
execute: makePush(28, big.NewInt(28)),
|
execute: makePush(28, 28),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH29: {
|
PUSH29: {
|
||||||
execute: makePush(29, big.NewInt(29)),
|
execute: makePush(29, 29),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH30: {
|
PUSH30: {
|
||||||
execute: makePush(30, big.NewInt(30)),
|
execute: makePush(30, 30),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH31: {
|
PUSH31: {
|
||||||
execute: makePush(31, big.NewInt(31)),
|
execute: makePush(31, 31),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
PUSH32: {
|
PUSH32: {
|
||||||
execute: makePush(32, big.NewInt(32)),
|
execute: makePush(32, 32),
|
||||||
gasCost: gasPush,
|
gasCost: gasPush,
|
||||||
validateStack: makeStackFunc(0, 1),
|
validateStack: makeStackFunc(0, 1),
|
||||||
valid: true,
|
valid: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user