Skip to content

Commit

Permalink
arithmetic: Add Ctz function
Browse files Browse the repository at this point in the history
Signed-off-by: Valentin Ilie <valentin.ilie@intel.com>
  • Loading branch information
vilie committed Aug 17, 2015
1 parent fef60b4 commit ab50d2f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ml-proto/src/arithmetic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ sig
type t
val of_value : int -> value -> t
val to_value : t -> value
val zero : t
val one : t
val size : int
val neg : t -> t
val abs : t -> t
Expand Down Expand Up @@ -50,7 +52,13 @@ struct
| Abs -> Int.abs
| Not -> Int.lognot
| Clz -> fun i -> i (* TODO *)
| Ctz -> fun i -> i (* TODO *)
| Ctz -> fun i ->
if i = Int.zero then Int.zero else
let rec loop j =
if Int.logand i j = Int.zero
then Int.add Int.one (loop (Int.shift_left j 1))
else Int.zero
in loop Int.one
in fun v -> Int.to_value (f (Int.of_value 1 v))

let binop op =
Expand Down

0 comments on commit ab50d2f

Please sign in to comment.