diff options
author | chriseth <chris@ethereum.org> | 2017-04-03 20:40:17 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2017-05-02 18:22:11 +0800 |
commit | 5c4f3f6d0b5d289accb3fb51964a44eca2b9d818 (patch) | |
tree | 6aa9849ecb1c333c15265fc36e602c91b2de6846 /libevmasm/ConstantOptimiser.cpp | |
parent | e2f00c96d5c333a20f67c5aed5787f8b9dd65d56 (diff) | |
download | dexon-solidity-5c4f3f6d0b5d289accb3fb51964a44eca2b9d818.tar.gz dexon-solidity-5c4f3f6d0b5d289accb3fb51964a44eca2b9d818.tar.zst dexon-solidity-5c4f3f6d0b5d289accb3fb51964a44eca2b9d818.zip |
Fix number representation bug.
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..f574ab4a 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}; |