summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Norton2019-06-17 14:25:01 +0100
committerRobert Norton2019-06-17 14:25:01 +0100
commit2dd28164e40241a2117142fbb197c967740f196d (patch)
tree5aa43303ab9f6c88de96b01743295abb36c82ceb /src
parent5de71f5be6e729184e122cf26bcb9a8ed0a40416 (diff)
Implement a count_leading_zeros builtin for ocaml and c. This may be a slight performance improvement and keeps compatibility with smt backend that already had a builtin for this because it can't handle the loop in the sail version. Will need implementations for prover backends.
Diffstat (limited to 'src')
-rw-r--r--src/sail_lib.ml7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/sail_lib.ml b/src/sail_lib.ml
index 2e00f980..76c2f59b 100644
--- a/src/sail_lib.ml
+++ b/src/sail_lib.ml
@@ -138,6 +138,13 @@ let rec take n xs =
| n, (x :: xs) -> x :: take (n - 1) xs
| n, [] -> []
+let count_leading_zeros xs =
+ let rec clz = function
+ | [] -> 0
+ | (B1 :: xs') -> clz xs'
+ | (B0 :: xs') -> 1 + clz xs' in
+ Big_int.of_int (clz xs)
+
let subrange (list, n, m) =
let n = Big_int.to_int n in
let m = Big_int.to_int m in