From 52c94418795f829c4a225fdf4742eec7a1961232 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 6 Apr 2018 14:54:21 +0200 Subject: Do not use SAR instead of SDIV in shifts because it rounds differently --- libsolidity/codegen/ABIFunctions.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'libsolidity/codegen/ABIFunctions.cpp') diff --git a/libsolidity/codegen/ABIFunctions.cpp b/libsolidity/codegen/ABIFunctions.cpp index f6aa714d..6c4ddc02 100644 --- a/libsolidity/codegen/ABIFunctions.cpp +++ b/libsolidity/codegen/ABIFunctions.cpp @@ -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 (value) -> newValue { - newValue := (, value) + newValue := shr(, value) } )") ("functionName", functionName) - ("shiftOp", _signed ? "sar" : "shr") ("numBits", to_string(_numBits)) .render(); }); -- cgit v1.2.3