| 474 | } |
| 475 | |
| 476 | std::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 | |
| 504 | std::string YulUtilFunctions::shiftRightFunctionDynamic() |
| 505 | { |
no test coverage detected