aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/collatz.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-09-08 22:05:33 +0200
committerlemon <lsof@mailbox.org>2025-09-08 22:05:33 +0200
commite043811980db560fc2507bb53b644e54c80527dc (patch)
tree6ea563d81c9d3767f439e361fc2c884cf4f9b64d /test/collatz.c
parent36b5b19bf183cb01525201ccbddd6afa692f21bb (diff)
regalloc: start implementing linear scan
Diffstat (limited to 'test/collatz.c')
-rw-r--r--test/collatz.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/collatz.c b/test/collatz.c
new file mode 100644
index 0000000..9793594
--- /dev/null
+++ b/test/collatz.c
@@ -0,0 +1,29 @@
+int printf(const char *, ...);
+void *malloc(unsigned long);
+int main() {
+ int *mem = malloc(sizeof(int) * 4000);
+
+ int cmax = 0;
+ for (int nv = 1; nv < 1000; ++nv) {
+ int n = nv, c = 0;
+ while (n != 1) {
+ if (n < nv) {
+ c += mem[n];
+ break;
+ }
+ if ((n & 1) != 0) {
+ n = (3 * n) + 1;
+ } else {
+ n /= 2;
+ //n >>= 1;
+ }
+ ++c;
+ }
+ mem[nv] = c;
+ if (c > cmax) {
+ cmax = c;
+ }
+ }
+ printf("should print 178: %d\n", cmax);
+}
+