diff options
author | chriseth <chris@ethereum.org> | 2017-05-03 17:54:12 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-03 17:54:11 +0800 |
commit | 00933b99cc64a5af1e00ed4b119fc725ddbb3513 (patch) | |
tree | f9c9abfb8a0e944f342f1d0a0fb11d6a55b9a352 /libevmasm/ConstantOptimiser.cpp | |
parent | 1aa0f77af91143b0a083949e230dab9e0376ed65 (diff) | |
parent | 794a390c34d44e9f93d9735a82aa11f8cc2fde48 (diff) | |
download | dexon-solidity-00933b99cc64a5af1e00ed4b119fc725ddbb3513.tar dexon-solidity-00933b99cc64a5af1e00ed4b119fc725ddbb3513.tar.gz dexon-solidity-00933b99cc64a5af1e00ed4b119fc725ddbb3513.tar.bz2 dexon-solidity-00933b99cc64a5af1e00ed4b119fc725ddbb3513.tar.lz dexon-solidity-00933b99cc64a5af1e00ed4b119fc725ddbb3513.tar.xz dexon-solidity-00933b99cc64a5af1e00ed4b119fc725ddbb3513.tar.zst dexon-solidity-00933b99cc64a5af1e00ed4b119fc725ddbb3513.zip |
Merge pull request #2206 from ethereum/fixoptimizer
Constant optimizer fix
Diffstat (limited to 'libevmasm/ConstantOptimiser.cpp')
-rw-r--r-- | libevmasm/ConstantOptimiser.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/libevmasm/ConstantOptimiser.cpp b/libevmasm/ConstantOptimiser.cpp index d2ed4faf..0c093ebf 100644 --- a/libevmasm/ConstantOptimiser.cpp +++ b/libevmasm/ConstantOptimiser.cpp @@ -203,8 +203,13 @@ AssemblyItems ComputeMethod::findRepresentation(u256 const& _value) u256 powerOfTwo = u256(1) << bits; u256 upperPart = _value >> bits; bigint lowerPart = _value & (powerOfTwo - 1); - if (abs(powerOfTwo - lowerPart) < lowerPart) + if ((powerOfTwo - lowerPart) < lowerPart) + { lowerPart = lowerPart - powerOfTwo; // make it negative + upperPart++; + } + if (upperPart == 0) + continue; if (abs(lowerPart) >= (powerOfTwo >> 8)) continue; @@ -212,7 +217,7 @@ AssemblyItems ComputeMethod::findRepresentation(u256 const& _value) if (lowerPart != 0) newRoutine += findRepresentation(u256(abs(lowerPart))); newRoutine += AssemblyItems{u256(bits), u256(2), Instruction::EXP}; - if (upperPart != 1 && upperPart != 0) + if (upperPart != 1) newRoutine += findRepresentation(upperPart) + AssemblyItems{Instruction::MUL}; if (lowerPart > 0) newRoutine += AssemblyItems{Instruction::ADD}; |