diff options
author | chriseth <chris@ethereum.org> | 2018-05-02 22:50:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-02 22:50:15 +0800 |
commit | a856135bbf709d17732ce610e086c2300783b0a9 (patch) | |
tree | c52cc5f5c2b7f263b18ac78ef3cc3760155a4726 /libsolidity/codegen/CompilerUtils.cpp | |
parent | de2c8fd684dd7c2a29460f64ffc891f1d6353cc8 (diff) | |
parent | 971941b3f6402665662d85eb9b31060f0ae230fb (diff) | |
download | dexon-solidity-a856135bbf709d17732ce610e086c2300783b0a9.tar dexon-solidity-a856135bbf709d17732ce610e086c2300783b0a9.tar.gz dexon-solidity-a856135bbf709d17732ce610e086c2300783b0a9.tar.bz2 dexon-solidity-a856135bbf709d17732ce610e086c2300783b0a9.tar.lz dexon-solidity-a856135bbf709d17732ce610e086c2300783b0a9.tar.xz dexon-solidity-a856135bbf709d17732ce610e086c2300783b0a9.tar.zst dexon-solidity-a856135bbf709d17732ce610e086c2300783b0a9.zip |
Merge pull request #3797 from ethereum/shift-constantinople
Use native shift instructions on Constantinople
Diffstat (limited to 'libsolidity/codegen/CompilerUtils.cpp')
-rw-r--r-- | libsolidity/codegen/CompilerUtils.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index 4af7d905..48b77eb3 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -599,15 +599,15 @@ void CompilerUtils::splitExternalFunctionType(bool _leftAligned) if (_leftAligned) { m_context << Instruction::DUP1; - rightShiftNumberOnStack(64 + 32, false); + rightShiftNumberOnStack(64 + 32); // <input> <address> m_context << Instruction::SWAP1; - rightShiftNumberOnStack(64, false); + rightShiftNumberOnStack(64); } else { m_context << Instruction::DUP1; - rightShiftNumberOnStack(32, false); + rightShiftNumberOnStack(32); m_context << ((u256(1) << 160) - 1) << Instruction::AND << Instruction::SWAP1; } m_context << u256(0xffffffffUL) << Instruction::AND; @@ -675,7 +675,7 @@ void CompilerUtils::convertType( // conversion from bytes to integer. no need to clean the high bit // only to shift right because of opposite alignment IntegerType const& targetIntegerType = dynamic_cast<IntegerType const&>(_targetType); - rightShiftNumberOnStack(256 - typeOnStack.numBytes() * 8, false); + rightShiftNumberOnStack(256 - typeOnStack.numBytes() * 8); if (targetIntegerType.numBits() < typeOnStack.numBytes() * 8) convertType(IntegerType(typeOnStack.numBytes() * 8), _targetType, _cleanupNeeded); } @@ -1242,7 +1242,7 @@ unsigned CompilerUtils::loadFromMemoryHelper(Type const& _type, bool _fromCallda bool leftAligned = _type.category() == Type::Category::FixedBytes; // add leading or trailing zeros by dividing/multiplying depending on alignment int shiftFactor = (32 - numBytes) * 8; - rightShiftNumberOnStack(shiftFactor, false); + rightShiftNumberOnStack(shiftFactor); if (leftAligned) leftShiftNumberOnStack(shiftFactor); } @@ -1265,13 +1265,20 @@ void CompilerUtils::cleanHigherOrderBits(IntegerType const& _typeOnStack) void CompilerUtils::leftShiftNumberOnStack(unsigned _bits) { solAssert(_bits < 256, ""); - m_context << (u256(1) << _bits) << Instruction::MUL; + if (m_context.evmVersion().hasBitwiseShifting()) + m_context << _bits << Instruction::SHL; + else + m_context << (u256(1) << _bits) << Instruction::MUL; } -void CompilerUtils::rightShiftNumberOnStack(unsigned _bits, bool _isSigned) +void CompilerUtils::rightShiftNumberOnStack(unsigned _bits) { solAssert(_bits < 256, ""); - m_context << (u256(1) << _bits) << Instruction::SWAP1 << (_isSigned ? Instruction::SDIV : Instruction::DIV); + // NOTE: If we add signed right shift, SAR rounds differently than SDIV + if (m_context.evmVersion().hasBitwiseShifting()) + m_context << _bits << Instruction::SHR; + else + m_context << (u256(1) << _bits) << Instruction::SWAP1 << Instruction::DIV; } unsigned CompilerUtils::prepareMemoryStore(Type const& _type, bool _padToWords) |