https://github.com/akkartik/mu/blob/main/506math.mu

     1 fn abs n: int -> _/eax: int {
     2   compare n, 0
     3   {
     4     break-if->=
     5     negate n
     6   }
     7   return n
     8 }
     9
    10 fn sgn n: int -> _/eax: int {
    11   compare n, 0
    12   {
    13     break-if-<=
    14     return 1
    15   }
    16   {
    17     break-if->=
    18     return -1
    19   }
    20   return 0
    21 }
    22
    23 fn shift-left-by n: int, bits: int -> _/eax: int {
    24   var i/eax: int <- copy bits
    25   {
    26     compare i, 0
    27     break-if-<=
    28     shift-left n, 1
    29     i <- decrement
    30     loop
    31   }
    32   return n
    33 }
    34
    35 fn shift-right-by n: int, bits: int -> _/eax: int {
    36   var i/eax: int <- copy bits
    37   {
    38     compare i, 0
    39     break-if-<=
    40     shift-right n, 1
    41     i <- decrement
    42     loop
    43   }
    44   return n
    45 }
    46
    47 fn clear-lowest-bits _n: (addr int), bits: int {
    48   var dest/edi: (addr int) <- copy _n
    49   var n/eax: int <- copy *dest
    50   n <- shift-right-by n, bits
    51   n <- shift-left-by n, bits
    52   copy-to *dest, n
    53 }