core/vm: opt opPushx

This commit is contained in:
cuiweixie 2025-08-09 00:46:57 +08:00
parent c3ef6c77c2
commit 0308afc443
2 changed files with 22 additions and 6 deletions

View file

@ -990,12 +990,9 @@ func makePush(size uint64, pushByteSize int) executionFunc {
start = min(codeLen, int(*pc+1))
end = min(codeLen, start+pushByteSize)
)
a := new(uint256.Int).SetBytes(scope.Contract.Code[start:end])
// Missing bytes: pushByteSize - len(pushData)
if missing := pushByteSize - (end - start); missing > 0 {
a.Lsh(a, uint(8*missing))
}
var b [32]byte
copy(b[:], scope.Contract.Code[start:end])
a := new(uint256.Int).SetBytes(b[:pushByteSize])
scope.Stack.push(a)
*pc += size
return nil, nil

View file

@ -973,6 +973,25 @@ func TestPush(t *testing.T) {
}
}
func BenchmarkPush(b *testing.B) {
code := common.FromHex("ff")
push32 := makePush(32, 32)
scope := &ScopeContext{
Memory: nil,
Stack: newstack(),
Contract: &Contract{
Code: code,
},
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
pc := new(uint64)
_, _ = push32(pc, nil, scope)
}
}
func TestOpCLZ(t *testing.T) {
evm := NewEVM(BlockContext{}, nil, params.TestChainConfig, Config{})