Use native shift instructions on Constantinople#3797
Conversation
|
@pirapira this will help in testing cpp-ethereum 😉 |
|
Before merging this we need to adjust test to run on constantinople: https://github.com/ethereum/solidity/blob/develop/scripts/tests.sh#L106 |
|
@chriseth do you have instructions somewhere how do you compile the |
|
@axic no special instructions for building... But yeah, we should perhaps automate that. |
|
Ran this with a local cpp-ethereum copy and weirdly enough it seems to be passing :) |
|
Conflict in the changelog. Also you might want to do a similar change in ABIFunctions.cpp |
|
In |
0f6e529 to
b931931
Compare
libsolidity/codegen/ABIFunctions.cpp
Outdated
| } | ||
| )") | ||
| ("functionName", functionName) | ||
| ("shiftOp", _signed ? "sar" : "shl") |
f6d2f9c to
69ce190
Compare
69ce190 to
9794c50
Compare
libsolidity/codegen/ABIFunctions.cpp
Outdated
| .render(); | ||
| Whiskers templ(R"( | ||
| function <functionName>(value) -> newValue { | ||
| newValue := <shiftOp>(value, <secondArg>) |
There was a problem hiding this comment.
Actually I think this is broken because the top of the stack is secondArg for shifts, which in inline assembly would be shl(<secondArg>, value)
9794c50 to
9a6a94e
Compare
|
@chriseth pushed the old version, but with the correct operand order |
| case Token::SHL: | ||
| m_context << Instruction::SWAP1 << u256(2) << Instruction::EXP << Instruction::MUL; | ||
| if (m_context.evmVersion().hasBitwiseShifting()) | ||
| m_context << Instruction::SHL; |
There was a problem hiding this comment.
This needs a SWAP1 then.
There was a problem hiding this comment.
The swap is added above.
2ea8c65 to
b5e879e
Compare
|
The |
| 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 |
There was a problem hiding this comment.
And because of that, this would be a breaking change, wouldn't it?
There was a problem hiding this comment.
Yes. We could think about having that as a breaking change though to fix signed right shifts.
| case Token::SHL: | ||
| m_context << Instruction::SWAP1 << u256(2) << Instruction::EXP << Instruction::MUL; | ||
| if (m_context.evmVersion().hasBitwiseShifting()) | ||
| m_context << Instruction::SWAP1 << Instruction::SHL; |
There was a problem hiding this comment.
I think this SWAP1 is invalid here, it is done outside the switch already.
84afba5 to
ac9f667
Compare
ac9f667 to
49c0ae1
Compare
49c0ae1 to
599c2b2
Compare
Changelog.md
Outdated
| Features: | ||
| * Code Generator: Initialize arrays without using ``msize()``. | ||
| * Code Generator: More specialized and thus optimized implementation for ``x.push(...)`` | ||
| * Code Generator: Use native shift instructions on target Constantinople. |
599c2b2 to
1c79613
Compare
|
For example this test fails "regular_functions_exclude_fallback - GasMeterTests". Code: Byzantium mode: Constantinople I am not sure what is causing the 6000 higher gas cost on deployment, given the constant optimiser i not turned on, and the byzantium version has a large number with a lot zeroes for which no gas should be charged. |
|
zeros are only free in transaction data, but not for code deployment. |
1c79613 to
971941b
Compare
|
@chriseth this seems to be working now |
No description provided.