about summary refs log tree commit diff stats
path: root/406try-divide.mu
diff options
context:
space:
mode:
Diffstat (limited to '406try-divide.mu')
-rw-r--r--406try-divide.mu28
1 files changed, 28 insertions, 0 deletions
diff --git a/406try-divide.mu b/406try-divide.mu
index e5034e55..d8588162 100644
--- a/406try-divide.mu
+++ b/406try-divide.mu
@@ -99,6 +99,34 @@ fn test-try-modulo-negative-nr {
   check-ints-equal result, 3, "F - test-try-modulo-negative-nr"
 }
 
+# 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
   {