about summary refs log tree commit diff stats
path: root/linux/406int32.mu
diff options
context:
space:
mode:
Diffstat (limited to 'linux/406int32.mu')
-rw-r--r--linux/406int32.mu39
1 files changed, 39 insertions, 0 deletions
diff --git a/linux/406int32.mu b/linux/406int32.mu
new file mode 100644
index 00000000..d69fe8e2
--- /dev/null
+++ b/linux/406int32.mu
@@ -0,0 +1,39 @@
+# Some slow but convenient helpers
+
+# slow, iterative shift-left instruction
+# preconditions: _nr >= 0, _dr > 0
+fn repeated-shift-left nr: int, dr: int -> _/eax: int {
+  var result/eax: int <- copy nr
+  {
+    compare dr, 0
+    break-if-<=
+    result <- shift-left 1
+    decrement dr
+    loop
+  }
+  return result
+}
+
+# slow, iterative shift-right instruction
+# preconditions: _nr >= 0, _dr > 0
+fn repeated-shift-right nr: int, dr: int -> _/eax: int {
+  var result/eax: int <- copy nr
+  {
+    compare dr, 0
+    break-if-<=
+    result <- shift-right 1
+    decrement dr
+    loop
+  }
+  return result
+}
+
+fn abs n: int -> _/eax: int {
+  var result/eax: int <- copy n
+  {
+    compare n, 0
+    break-if->=
+    result <- negate
+  }
+  return result
+}