96a4d6cb5043e5757030d825dd4c6e5de99d3b52
[virt-df.git] / lib / int63_on_64.ml
1 (* 63 bit signed integer type.
2    (C) Copyright 2008 Richard W.M. Jones, Red Hat Inc.
3
4    This library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2 of the License, or (at your option) any later version,
8    with the OCaml linking exception described in ../COPYING.LIB.
9
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with this library; if not, write to the Free Software
17    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
18  *)
19
20 (* This is the 64 bit implementation so for efficiency we used the
21  * unboxed int type directly.
22  *)
23 type t = int
24
25 module Operators = struct
26   type int63 = t
27
28   external ( +^ ) : int -> int -> int = "%addint"
29   external ( -^ ) : int -> int -> int = "%subint"
30   external ( *^ ) : int -> int -> int = "%mulint"
31   external ( /^ ) : int -> int -> int = "%divint"
32   external ( %^ ) : int -> int -> int = "%modint"
33   external ( <^< ) : int -> int -> int = "%lslint"
34   external ( >^> ) : int -> int -> int = "%lsrint"
35   external ( &^ ) : int -> int -> int = "%andint"
36   external ( |^ ) : int -> int -> int = "%orint"
37   external ( ^^ ) : int -> int -> int = "%xorint"
38   external ( ~^ ) : int -> int = "%identity"
39   external ( ~^~ ) : int -> int = "%negint"
40 end
41
42 let zero = 0
43 let one = 1
44 let minus_one = ~1
45
46 external neg : int -> int = "%negint"
47
48 external add : int -> int -> int = "%addint"
49 external sub : int -> int -> int = "%subint"
50 external mul : int -> int -> int = "%mulint"
51 external div : int -> int -> int = "%divint"
52 external rem : int -> int -> int = "%modint"
53
54 external succ : int -> int = "%succint"
55 external pred : int -> int = "%predint"
56
57 let abs = abs
58
59 let max_int = max_int
60 let min_int = min_int
61
62 external logand : int -> int -> int = "%andint"
63 external logor : int -> int -> int = "%orint"
64 external logxor : int -> int -> int = "%xorint"
65 let lognot = lnot
66
67 external shift_left : int -> int -> int = "%lslint"
68 external shift_right : int -> int -> int = "%asrint"
69 external shift_right_logical : int -> int -> int = "%lsrint"
70
71 external of_int : int -> int = "%identity"
72 external to_int : int -> int = "%identity"
73 external of_float : float -> int = "%intoffloat"
74 external to_float : int -> float = "%floatofint"
75 external of_int32 : int32 -> int = "%int32_to_int"
76 external to_int32 : int -> int32 = "%int32_of_int"
77 external of_int64 : int64 -> int = "%int64_to_int"
78 external to_int64 : int -> int64 = "%int64_of_int"
79 external of_nativeint : nativeint -> int = "%nativeint_to_int"
80 external to_nativeint : int -> nativeint = "%nativeint_of_int"
81
82 external of_string : string -> int = "caml_int_of_string"
83 let to_string = string_of_int
84
85 (*external compare : int -> int -> int = "%compare"*)
86 (* I think it should be faster to use a specialized compare: *)
87 let compare : int -> int -> int = compare