mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Removed signed shift right from the utilities.
This commit is contained in:
1 parent
52c9441879
commit
2968639406
6 files changed
+24
-24
No files matched your search
@@ -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();
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user