MCPcopy Create free account
hub / github.com/argotorg/solidity / shiftRightFunction

Method shiftRightFunction

libsolidity/codegen/YulUtilFunctions.cpp:476–502  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

474}
475
476std::string YulUtilFunctions::shiftRightFunction(size_t _numBits)
477{
478 solAssert(_numBits < 256, "");
479
480 // Note that if this is extended with signed shifts,
481 // the opcodes SAR and SDIV behave differently with regards to rounding!
482
483 std::string functionName = "shift_right_" + std::to_string(_numBits) + "_unsigned";
484 return m_functionCollector.createFunction(functionName, [&]() {
485 return
486 Whiskers(R"(
487 function <functionName>(value) -> newValue {
488 newValue :=
489 <?hasShifts>
490 shr(<numBits>, value)
491 <!hasShifts>
492 div(value, <multiplier>)
493 </hasShifts>
494 }
495 )")
496 ("functionName", functionName)
497 ("hasShifts", m_evmVersion.hasBitwiseShifting())
498 ("numBits", std::to_string(_numBits))
499 ("multiplier", toCompactHexWithPrefix(u256(1) << _numBits))
500 .render();
501 });
502}
503
504std::string YulUtilFunctions::shiftRightFunctionDynamic()
505{

Callers 1

dispatchRoutineMethod · 0.80

Calls 6

WhiskersClass · 0.85
toCompactHexWithPrefixFunction · 0.85
renderMethod · 0.80
hasBitwiseShiftingMethod · 0.80
to_stringFunction · 0.50
createFunctionMethod · 0.45

Tested by

no test coverage detected