mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[Sol->Yul] Refactor shift functions to be consistent
This commit is contained in:
parent
89c435a167
commit
6a0976ed5e
@ -224,35 +224,25 @@ string YulUtilFunctions::shiftLeftFunction(size_t _numBits)
|
|||||||
solAssert(_numBits < 256, "");
|
solAssert(_numBits < 256, "");
|
||||||
|
|
||||||
string functionName = "shift_left_" + to_string(_numBits);
|
string functionName = "shift_left_" + to_string(_numBits);
|
||||||
if (m_evmVersion.hasBitwiseShifting())
|
|
||||||
{
|
|
||||||
return m_functionCollector->createFunction(functionName, [&]() {
|
return m_functionCollector->createFunction(functionName, [&]() {
|
||||||
return
|
return
|
||||||
Whiskers(R"(
|
Whiskers(R"(
|
||||||
function <functionName>(value) -> newValue {
|
function <functionName>(value) -> newValue {
|
||||||
newValue := shl(<numBits>, value)
|
newValue :=
|
||||||
|
<?hasShifts>
|
||||||
|
shl(<numBits>, value)
|
||||||
|
<!hasShifts>
|
||||||
|
mul(value, <multiplier>)
|
||||||
|
</hasShifts>
|
||||||
}
|
}
|
||||||
)")
|
)")
|
||||||
("functionName", functionName)
|
("functionName", functionName)
|
||||||
("numBits", to_string(_numBits))
|
("numBits", to_string(_numBits))
|
||||||
.render();
|
("hasShifts", m_evmVersion.hasBitwiseShifting())
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return m_functionCollector->createFunction(functionName, [&]() {
|
|
||||||
return
|
|
||||||
Whiskers(R"(
|
|
||||||
function <functionName>(value) -> newValue {
|
|
||||||
newValue := mul(value, <multiplier>)
|
|
||||||
}
|
|
||||||
)")
|
|
||||||
("functionName", functionName)
|
|
||||||
("multiplier", toCompactHexWithPrefix(u256(1) << _numBits))
|
("multiplier", toCompactHexWithPrefix(u256(1) << _numBits))
|
||||||
.render();
|
.render();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
string YulUtilFunctions::dynamicShiftLeftFunction()
|
string YulUtilFunctions::dynamicShiftLeftFunction()
|
||||||
{
|
{
|
||||||
@ -282,7 +272,7 @@ string YulUtilFunctions::shiftRightFunction(size_t _numBits)
|
|||||||
// Note that if this is extended with signed shifts,
|
// Note that if this is extended with signed shifts,
|
||||||
// the opcodes SAR and SDIV behave differently with regards to rounding!
|
// the opcodes SAR and SDIV behave differently with regards to rounding!
|
||||||
|
|
||||||
string functionName = "shift_right_" + to_string(_numBits) + "_unsigned_" + m_evmVersion.name();
|
string functionName = "shift_right_" + to_string(_numBits) + "_unsigned";
|
||||||
return m_functionCollector->createFunction(functionName, [&]() {
|
return m_functionCollector->createFunction(functionName, [&]() {
|
||||||
return
|
return
|
||||||
Whiskers(R"(
|
Whiskers(R"(
|
||||||
|
Loading…
Reference in New Issue
Block a user