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/ExpressionCompiler.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/ExpressionCompiler.cpp')
-rw-r--r-- | libsolidity/codegen/ExpressionCompiler.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 3cf46a9d..a8222e21 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -548,7 +548,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) if (m_context.runtimeContext()) // We have a runtime context, so we need the creation part. - utils().rightShiftNumberOnStack(32, false); + utils().rightShiftNumberOnStack(32); else // Extract the runtime part. m_context << ((u256(1) << 32) - 1) << Instruction::AND; @@ -1706,13 +1706,23 @@ void ExpressionCompiler::appendShiftOperatorCode(Token::Value _operator, Type co m_context.appendConditionalInvalid(); } + m_context << Instruction::SWAP1; + // stack: value_to_shift shift_amount + switch (_operator) { case Token::SHL: - m_context << Instruction::SWAP1 << u256(2) << Instruction::EXP << Instruction::MUL; + if (m_context.evmVersion().hasBitwiseShifting()) + m_context << Instruction::SHL; + else + m_context << u256(2) << Instruction::EXP << Instruction::MUL; break; case Token::SAR: - m_context << Instruction::SWAP1 << u256(2) << Instruction::EXP << Instruction::SWAP1 << (c_valueSigned ? Instruction::SDIV : Instruction::DIV); + // NOTE: SAR rounds differently than SDIV + if (m_context.evmVersion().hasBitwiseShifting() && !c_valueSigned) + m_context << Instruction::SHR; + else + m_context << u256(2) << Instruction::EXP << Instruction::SWAP1 << (c_valueSigned ? Instruction::SDIV : Instruction::DIV); break; case Token::SHR: default: |