File: type_if_bits.sail

package info (click to toggle)
sail-ocaml 0.19.1%2Bdfsg5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,008 kB
  • sloc: ml: 75,941; ansic: 8,848; python: 1,342; exp: 560; sh: 474; makefile: 218; cpp: 36
file content (37 lines) | stat: -rw-r--r-- 840 bytes parent folder | download
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
default Order dec

$include <prelude.sail>
$include <string.sail>

type some_bits = {'n, 'n in {16, 32, 64}. bits('n)}

struct if_bits('n: Int) = {
  top: bits(1),
  rest: bits(if 'n == 16 then 15 else if 'n == 32 then 31 else 63),
}

val decompose : forall 'n, 'n in {16, 32, 64}. bits('n) -> if_bits('n)

function decompose(op) = {
  if length(op) == 16 then {
    struct { top = op[15 .. 15], rest = op[14 .. 0] }
  } else if length(op) == 32 then {
    struct { top = op[31 .. 31], rest = op[30 .. 0] }
  } else {
    struct { top = op[63 .. 63], rest = op[62 .. 0] }
  }
}

val if_bits_test : some_bits -> bool

function if_bits_test(op) = {
  let struct { top = _, rest } = decompose(op);
  rest == sail_zeros(length(rest))
}

val main : unit -> unit

function main() = {
  let _ = if_bits_test(0x0000_0000);
  print_endline("ok");
}