Do not use SAR instead of SDIV in shifts because it rounds differently

This commit is contained in:
Alex Beregszaszi committed 2018-04-30 20:34:43 +01:00
1 parent c3608eaf90
commit 52c9441879
3 files changed
+10 -7

No files matched your search

+4 -3
View File
@@ -1439,17 +1439,18 @@ string ABIFunctions::shiftRightFunction(size_t _numBits, bool _signed)
solAssert(_numBits < 256, "");
string functionName = "shift_right_" + to_string(_numBits) + (_signed ? "_signed" : "_unsigned");
if (m_evmVersion.hasBitwiseShifting())
// NOTE: SAR rounds differently than SDIV
if (m_evmVersion.hasBitwiseShifting() && !_signed)
{
return createFunction(functionName, [&]() {
return
Whiskers(R"(
function <functionName>(value) -> newValue {
newValue := <shiftOp>(<numBits>, value)
newValue := shr(<numBits>, value)
}
)")
("functionName", functionName)
("shiftOp", _signed ? "sar" : "shr")
("numBits", to_string(_numBits))
.render();
});