CCTLib
Calling-context and data-object attribution library for Intel Pin
rec_ackermann.cpp
Go to the documentation of this file.
1 // Ackermann function: A(3, 4) has stack depth ~11 and exercises deep
2 // single-argument recursion with two direct self-call sites in the
3 // m>0 branches. Kept under cctlib's MAX_CCT_PRINT_DEPTH=20 so the
4 // shape-check assertion isn't blunted by chain truncation when the
5 // collapse mechanism is intentionally disabled for the sensitivity
6 // test. Fib is high-branching-low-depth; Ackermann is low-branching-
7 // high-depth. Both must collapse to O(1) TraceNodes for the routine.
8 #include <cstdint>
9 #include <cstdio>
10 
11 static volatile uint64_t sink;
12 
13 static uint64_t A(uint64_t m, uint64_t n) {
14  if (m == 0) return n + 1;
15  if (n == 0) return A(m - 1, 1);
16  return A(m - 1, A(m, n - 1));
17 }
18 
19 int main(int argc, char** argv) {
20  (void)argc; (void)argv;
21  uint64_t r = A(3, 4);
22  sink ^= r;
23  fprintf(stderr, "rec_ackermann: A(3,4)=%llu sink=%llx\n",
24  (unsigned long long)r, (unsigned long long)sink);
25  return r == 125 ? 0 : 1;
26 }
int main(int argc, char **argv)
static uint64_t A(uint64_t m, uint64_t n)
static volatile uint64_t sink