mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
vm: optimize EXP
Optimize EXP performance by using simple algorithm that replaces division with a bit mask.
This commit is contained in:
parent
8048f4d4f6
commit
2ae2a78f38
1 changed files with 10 additions and 2 deletions
|
|
@ -192,8 +192,16 @@ func opSmod(instr instruction, pc *uint64, env Environment, contract *Contract,
|
|||
}
|
||||
|
||||
func opExp(instr instruction, pc *uint64, env Environment, contract *Contract, memory *Memory, stack *Stack) {
|
||||
x, y := stack.pop(), stack.pop()
|
||||
stack.push(U256(x.Exp(x, y, Pow256)))
|
||||
base, exponent := stack.pop(), stack.pop()
|
||||
result := big.NewInt(1)
|
||||
for exponent.Cmp(common.Big0) != 0 {
|
||||
if exponent.Bit(0) == 1 {
|
||||
U256(result.Mul(result, base))
|
||||
}
|
||||
U256(base.Mul(base, base))
|
||||
exponent.Rsh(exponent, 1)
|
||||
}
|
||||
stack.push(result)
|
||||
}
|
||||
|
||||
func opSignExtend(instr instruction, pc *uint64, env Environment, contract *Contract, memory *Memory, stack *Stack) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue