solidity/test/libyul/yulOptimizerTests/fullSuite/ackermann_function_if.yul

52 lines
1.1 KiB
Plaintext
Raw Normal View History

2020-11-26 17:52:25 +00:00
// https://en.wikipedia.org/wiki/Ackermann_function
// Test to see how FunctionSpecializer deals with functions that are too recursive / resource intensive.
// Unlike the test ackermann_function.yul, this one implements it using `if` and leave
2020-11-26 17:52:25 +00:00
{
// 5
sstore(0, A(2, 1))
// 7
sstore(1, A(2, 2))
// Too many unrolling needed. In arbitrary precision, the value is 2**65536 - 3.
sstore(2, A(4, 2))
function A(m, n) -> ret {
if eq(m, 0) {
ret := add(n, 1)
leave
}
if eq(n, 0) {
ret := A(sub(m, 1), 1)
leave
}
ret := A(sub(m, 1), A(m, sub(n, 1)))
}
}
// ----
// step: fullSuite
//
// {
// {
// sstore(0, A(2, 1))
// sstore(1, A(2, 2))
// sstore(2, A(4, 2))
2020-11-26 17:52:25 +00:00
// }
// function A(m, n) -> ret
// {
// if iszero(m)
// {
// ret := add(n, 1)
// leave
// }
// if iszero(n)
// {
// ret := A(add(m, not(0)), 1)
2020-11-26 17:52:25 +00:00
// leave
// }
// let _1 := not(0)
// ret := A(add(m, _1), A(m, add(n, _1)))
// }
// }