mirror of
https://gitlab.com/pulsechaincom/go-pulse.git
synced 2025-01-11 13:10:04 +00:00
core/vm: add shortcuts for trivial exp cases (#16851)
This commit is contained in:
parent
6a7695e367
commit
a352de6a08
@ -124,10 +124,22 @@ func opSmod(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory
|
|||||||
|
|
||||||
func opExp(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
func opExp(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
||||||
base, exponent := stack.pop(), stack.pop()
|
base, exponent := stack.pop(), stack.pop()
|
||||||
|
// some shortcuts
|
||||||
|
cmpToOne := exponent.Cmp(big1)
|
||||||
|
if cmpToOne < 0 { // Exponent is zero
|
||||||
|
// x ^ 0 == 1
|
||||||
|
stack.push(base.SetUint64(1))
|
||||||
|
} else if base.Sign() == 0 {
|
||||||
|
// 0 ^ y, if y != 0, == 0
|
||||||
|
stack.push(base.SetUint64(0))
|
||||||
|
} else if cmpToOne == 0 { // Exponent is one
|
||||||
|
// x ^ 1 == x
|
||||||
|
stack.push(base)
|
||||||
|
} else {
|
||||||
stack.push(math.Exp(base, exponent))
|
stack.push(math.Exp(base, exponent))
|
||||||
|
interpreter.intPool.put(base)
|
||||||
interpreter.intPool.put(base, exponent)
|
}
|
||||||
|
interpreter.intPool.put(exponent)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user