Skip to content

Instantly share code, notes, and snippets.

@pervognsen
Last active August 5, 2021 07:58
Show Gist options
  • Save pervognsen/a002735fd626a481222e5204ac15b11e to your computer and use it in GitHub Desktop.
Save pervognsen/a002735fd626a481222e5204ac15b11e to your computer and use it in GitHub Desktop.
// For N = 11, a call to perms(p, N, 0) only takes 0.36 seconds.
// Why would a debugger seemingly hang forever when you try to
// step over the outermost recursive call to perms in the loop?
// Hint: How is "step over" ("next" in gdb/lldb) implemented?
u64 perms(u64 p[N], int n, u64 s) {
if (n == 1) {
s += signature(p);
} else {
for (int i = 0; i < n; i++) {
swap(p[0], p[i]);
s = perms(p + 1, n - 1, s);
swap(p[0], p[i]);
}
}
return s;
}
@pervognsen
Copy link
Author

I've never bothered doing CFA but the strongest case for something like that is implementing efficient "step over" for inlined calls. I haven't thought it through in detail, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment