summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>1995-06-05 13:44:14 +0000
committerXavier Leroy <xavier.leroy@inria.fr>1995-06-05 13:44:14 +0000
commit2ccd7f48fb6f48d888bf577defd922771907e908 (patch)
tree8d3b77f4b21bd6f8cc97e3c49bc52de19d7a3f3a /utils
parent39104f333cff5c9ed33bfdb091f9b609629e3455 (diff)
downloadocaml-2ccd7f48fb6f48d888bf577defd922771907e908.tar.gz
Ajout de qques fonctions sur entiers pour le compilateur natif.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@25 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
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). *)
+
+