about summary refs log tree commit diff stats
path: root/linux/406int32.mu
blob: d69fe8e2d149a7d40ba46a95ef2ff43e2cf104eb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
}