summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/misc.ml8
-rw-r--r--utils/misc.mli9
2 files changed, 17 insertions, 0 deletions
diff --git a/utils/misc.ml b/utils/misc.ml
index 1cdb5dcf25..7f8d42aab4 100644
--- a/utils/misc.ml
+++ b/utils/misc.ml
@@ -84,3 +84,11 @@ let copy_file_chunk ic oc len =
if r = 0 then raise End_of_file else (output oc buff 0 r; copy(n-r))
end
in copy len
+
+(* Integer operations *)
+
+let rec log2 n =
+ if n <= 1 then 1 else 1 + log2(n asr 1)
+
+let align n a =
+ (n + a - 1) land (-a)
diff --git a/utils/misc.mli b/utils/misc.mli
index a19ea92752..4f95391904 100644
--- a/utils/misc.mli
+++ b/utils/misc.mli
@@ -27,3 +27,12 @@ val copy_file_chunk: in_channel -> out_channel -> int -> unit
(* [copy_file_chunk ic oc n] reads [n] bytes from [ic] and copies
them to [oc]. It raises [End_of_file] when encountering
EOF on [ic]. *)
+
+val log2: int -> int
+ (* [log2 n] returns [s] such that [n = 1 lsl s]
+ if [n] is a power of 2*)
+val align: int -> int -> int
+ (* [align n a] rounds [n] upwards to a multiple of [a]
+ (a power of 2). *)
+
+