Skip to content

Commit ebbece3

Browse files
authored
Merge pull request #2323 from CortexFoundation/dev
optimized push2
2 parents dd1dff6 + 6d6a733 commit ebbece3

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

core/vm/instructions.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,23 @@ func opPush1(pc *uint64, interpreter *CVMInterpreter, scope *ScopeContext) ([]by
12161216
return nil, nil
12171217
}
12181218

1219+
// opPush2 is a specialized version of pushN
1220+
func opPush2(pc *uint64, interpreter *CVMInterpreter, scope *ScopeContext) ([]byte, error) {
1221+
var (
1222+
codeLen = uint64(len(scope.Contract.Code))
1223+
integer = new(uint256.Int)
1224+
)
1225+
if *pc+2 < codeLen {
1226+
scope.Stack.push(integer.SetBytes2(scope.Contract.Code[*pc+1 : *pc+3]))
1227+
} else if *pc+1 < codeLen {
1228+
scope.Stack.push(integer.SetUint64(uint64(scope.Contract.Code[*pc+1]) << 8))
1229+
} else {
1230+
scope.Stack.push(integer.Clear())
1231+
}
1232+
*pc += 2
1233+
return nil, nil
1234+
}
1235+
12191236
// make push instruction function
12201237
func makePush(size uint64, pushByteSize int) executionFunc {
12211238
return func(pc *uint64, interpreter *CVMInterpreter, scope *ScopeContext) ([]byte, error) {

core/vm/jump_table.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ func newFrontierInstructionSet() JumpTable {
501501
validateStack: makeStackFunc(0, 1),
502502
},
503503
PUSH2: {
504-
execute: makePush(2, 2),
504+
execute: opPush2,
505505
gasCost: gasPush,
506506
validateStack: makeStackFunc(0, 1),
507507
},

0 commit comments

Comments
 (0)