aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/codegen/ABIFunctions.cpp
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-04-06 22:25:13 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-05-01 03:34:43 +0800
commit2968639406888d97bfae70e4adf41674ac60fd83 (patch)
treecabaf0aff5bfd64fb067b6b537534fc851bc1b41 /libsolidity/codegen/ABIFunctions.cpp
parent52c94418795f829c4a225fdf4742eec7a1961232 (diff)
downloaddexon-solidity-2968639406888d97bfae70e4adf41674ac60fd83.tar.gz
dexon-solidity-2968639406888d97bfae70e4adf41674ac60fd83.tar.zst
dexon-solidity-2968639406888d97bfae70e4adf41674ac60fd83.zip
Removed signed shift right from the utilities.
Diffstat (limited to 'libsolidity/codegen/ABIFunctions.cpp')
-rw-r--r--libsolidity/codegen/ABIFunctions.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/libsolidity/codegen/ABIFunctions.cpp b/libsolidity/codegen/ABIFunctions.cpp
index 6c4ddc02..3e3aa0ae 100644
--- a/libsolidity/codegen/ABIFunctions.cpp
+++ b/libsolidity/codegen/ABIFunctions.cpp
@@ -371,7 +371,7 @@ string ABIFunctions::conversionFunction(Type const& _from, Type const& _to)
if (toCategory == Type::Category::Integer)
body =
Whiskers("converted := <convert>(<shift>(value))")
- ("shift", shiftRightFunction(256 - from.numBytes() * 8, false))
+ ("shift", shiftRightFunction(256 - from.numBytes() * 8))
("convert", conversionFunction(IntegerType(from.numBytes() * 8), _to))
.render();
else
@@ -458,8 +458,8 @@ string ABIFunctions::splitExternalFunctionIdFunction()
}
)")
("functionName", functionName)
- ("shr32", shiftRightFunction(32, false))
- ("shr64", shiftRightFunction(64, false))
+ ("shr32", shiftRightFunction(32))
+ ("shr64", shiftRightFunction(64))
.render();
});
}
@@ -831,7 +831,7 @@ string ABIFunctions::abiEncodingFunctionCompactStorageArray(
templ("encodeToMemoryFun", encodeToMemoryFun);
std::vector<std::map<std::string, std::string>> items(itemsPerSlot);
for (size_t i = 0; i < itemsPerSlot; ++i)
- items[i]["shiftRightFun"] = shiftRightFunction(i * storageBytes * 8, false);
+ items[i]["shiftRightFun"] = shiftRightFunction(i * storageBytes * 8);
templ("items", items);
return templ.render();
}
@@ -927,7 +927,7 @@ string ABIFunctions::abiEncodingFunctionStruct(
}
else
memberTempl("preprocess", "");
- memberTempl("retrieveValue", shiftRightFunction(intraSlotOffset * 8, false) + "(slotValue)");
+ memberTempl("retrieveValue", shiftRightFunction(intraSlotOffset * 8) + "(slotValue)");
}
else
{
@@ -1434,14 +1434,15 @@ string ABIFunctions::shiftLeftFunction(size_t _numBits)
}
}
-string ABIFunctions::shiftRightFunction(size_t _numBits, bool _signed)
+string ABIFunctions::shiftRightFunction(size_t _numBits)
{
solAssert(_numBits < 256, "");
- string functionName = "shift_right_" + to_string(_numBits) + (_signed ? "_signed" : "_unsigned");
+ // Note that if this is extended with signed shifts,
+ // the opcodes SAR and SDIV behave differently with regards to rounding!
- // NOTE: SAR rounds differently than SDIV
- if (m_evmVersion.hasBitwiseShifting() && !_signed)
+ string functionName = "shift_right_" + to_string(_numBits) + "_unsigned";
+ if (m_evmVersion.hasBitwiseShifting())
{
return createFunction(functionName, [&]() {
return
@@ -1461,11 +1462,10 @@ string ABIFunctions::shiftRightFunction(size_t _numBits, bool _signed)
return
Whiskers(R"(
function <functionName>(value) -> newValue {
- newValue := <div>(value, <multiplier>)
+ newValue := div(value, <multiplier>)
}
)")
("functionName", functionName)
- ("div", _signed ? "sdiv" : "div")
("multiplier", toCompactHexWithPrefix(u256(1) << _numBits))
.render();
});