summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-08-15 20:54:06 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-09-15 23:01:31 -0400
commitca3dc70ff3e4caf57f32e5a0da7be29ccf222213 (patch)
treef257ca3ff61cbb47b42cd7db4ae1b9b142821601
parent2b34ec6d2455da5990433e5ba23dd12d3995d03d (diff)
downloadroux-ca3dc70ff3e4caf57f32e5a0da7be29ccf222213.tar.gz
add a large test
-rw-r--r--lisc/test/collatz.ssa69
1 files changed, 69 insertions, 0 deletions
diff --git a/lisc/test/collatz.ssa b/lisc/test/collatz.ssa
new file mode 100644
index 0000000..9696194
--- /dev/null
+++ b/lisc/test/collatz.ssa
@@ -0,0 +1,69 @@
+# a solution for N=1000 to
+# https://projecteuler.net/problem=14
+# we use a fast local array to
+# memoize small collatz numbers
+#
+# todo, insert sign extensions
+
+@start
+ %mem =l alloc4 4000
+
+@loop
+ %n =w phi @start 1, @newm %n9, @oldm %n9
+ %cmax =w phi @start 0, @newm %c, @oldm %cmax
+
+ %fin =w cslt %n, 1000
+ jnz %fin, @cloop, @end
+
+@cloop
+ %n0 =w phi @loop %n, @odd %n2, @even %n3
+ %c0 =w phi @loop 0, @odd %c1, @even %c1
+
+ %is1 =w ceq %n0, 1
+ jnz %is1, @endcl, @iter0
+
+@iter0
+ %ism =w cslt %n0, %n
+ jnz %ism, @getmemo, @iter1 # we have it in the table
+
+@iter1
+ %c1 =w add %c0, 1
+ %p =w and %n0, 1
+ jnz %p, @odd, @even
+
+@odd
+ %nn =w add %n0, %n0 # compute %n2 = 3 * %n0 + 1
+ %n1 =w add %n0, %nn
+ %n2 =w add %n1, 1
+ jmp @cloop
+
+@even
+ %n3 =w div %n0, 2 # %n3 = %n0 / 2
+ jmp @cloop
+
+@getmemo
+ %idx00 =l add %n0, %n0
+ %idx0 =l add %idx00, %idx00
+ %loc0 =l add %idx0, %mem
+ %cn0 =w load %loc0
+ %c2 =w add %c0, %cn0
+
+@endcl
+ %c =w phi @getmemo %c2, @cloop %c0
+
+ %idx10 =l add %n, %n
+ %idx1 =l add %idx10, %idx10
+ %loc1 =l add %idx1, %mem
+ storew %c, %loc1 # memorize the result
+ %n9 =w add 1, %n
+ %big =w csle %cmax, %c
+ jnz %big, @newm, @oldm
+
+@newm
+ jmp @loop
+@oldm
+ jmp @loop
+
+@end
+ storew %cmax, $a
+ ret