mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 21:26:42 +00:00
core/vm: improve comments
This commit is contained in:
parent
f8b8610d6d
commit
3932b1ca35
1 changed files with 4 additions and 4 deletions
|
|
@ -396,24 +396,24 @@ func byzantiumMultComplexity(x uint64) uint64 {
|
||||||
case x <= 1024:
|
case x <= 1024:
|
||||||
// x^2 / 4 + 96*x - 3072
|
// x^2 / 4 + 96*x - 3072
|
||||||
return x*x/4 + 96*x - 3072
|
return x*x/4 + 96*x - 3072
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// For large x, use uint256 arithmetic to avoid overflow
|
// For large x, use uint256 arithmetic to avoid overflow
|
||||||
// x^2 / 16 + 480*x - 199680
|
// x^2 / 16 + 480*x - 199680
|
||||||
// xSqr = x^2
|
|
||||||
|
// xSqr = x^2 / 16
|
||||||
carry, xSqr := bits.Mul64(x, x)
|
carry, xSqr := bits.Mul64(x, x)
|
||||||
if carry != 0 {
|
if carry != 0 {
|
||||||
return math.MaxUint64
|
return math.MaxUint64
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate x^2 / 16
|
|
||||||
xSqr = xSqr >> 4
|
xSqr = xSqr >> 4
|
||||||
|
|
||||||
// Calculate 480 * x (can't overflow if x^2 didn't overflow)
|
// Calculate 480 * x (can't overflow if x^2 didn't overflow)
|
||||||
x480 := x * 480
|
x480 := x * 480
|
||||||
|
|
||||||
// Calculate 480 * x - 199680 (will not underflow, since x > 1024)
|
// Calculate 480 * x - 199680 (will not underflow, since x > 1024)
|
||||||
x480 = x480 - 199680
|
x480 = x480 - 199680
|
||||||
|
|
||||||
|
// xSqr + x480
|
||||||
sum, carry := bits.Add64(xSqr, x480, 0)
|
sum, carry := bits.Add64(xSqr, x480, 0)
|
||||||
if carry != 0 {
|
if carry != 0 {
|
||||||
return math.MaxUint64
|
return math.MaxUint64
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue