Clarify licensing for Debian.
[virt-df.git] / lib / int63_on_32.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 32 bit implementation so we have to use the boxed
21  * and rather slow int64.
22  *
23  * Note that this code isn't quite correct, although not in a way
24  * that anyone is likely to notice, in that we don't truncate the
25  * underlying int64 to 63 bits on overflow.
26  *)
27 type t = int64
28
29 module Operators = struct
30   type int63 = t
31
32   external ( +^ ) : int64 -> int64 -> int64 = "%int64_add"
33   external ( -^ ) : int64 -> int64 -> int64 = "%int64_sub"
34   external ( *^ ) : int64 -> int64 -> int64 = "%int64_mul"
35   external ( /^ ) : int64 -> int64 -> int64 = "%int64_div"
36   external ( %^ ) : int64 -> int64 -> int64 = "%int64_mod"
37   external ( <^< ) : int64 -> int -> int64 = "%int64_lsl"
38   external ( >^> ) : int64 -> int -> int64 = "%int64_lsr"
39   external ( &^ ) : int64 -> int64 -> int64 = "%int64_and"
40   external ( |^ ) : int64 -> int64 -> int64 = "%int64_or"
41   external ( ^^ ) : int64 -> int64 -> int64 = "%int64_xor"
42   external ( ~^ ) : int -> int64 = "%int64_of_int"
43   let ( ~^~ ) i = Int64.neg (Int64.of_int i)
44 end
45
46 let zero = Int64.zero
47 let one = Int64.one
48 let minus_one = Int64.minus_one
49
50 external neg : int64 -> int64 = "%int64_neg"
51
52 external add : int64 -> int64 -> int64 = "%int64_add"
53 external sub : int64 -> int64 -> int64 = "%int64_sub"
54 external mul : int64 -> int64 -> int64 = "%int64_mul"
55 external div : int64 -> int64 -> int64 = "%int64_div"
56 external rem : int64 -> int64 -> int64 = "%int64_mod"
57
58 let succ = Int64.succ
59 let pred = Int64.pred
60
61 let abs = Int64.abs
62
63 (* XXX Should these return the 'real' 64 bit max/min int? *)
64 let max_int = Int64.pred (Int64.shift_left Int64.one 62)
65 let min_int = Int64.neg (Int64.shift_left Int64.one 62)
66
67 external logand : int64 -> int64 -> int64 = "%int64_and"
68 external logor : int64 -> int64 -> int64 = "%int64_or"
69 external logxor : int64 -> int64 -> int64 = "%int64_xor"
70 let lognot = Int64.lognot
71
72 external shift_left : int64 -> int -> int64 = "%int64_lsl"
73 external shift_right : int64 -> int -> int64 = "%int64_asr"
74 external shift_right_logical : int64 -> int -> int64 = "%int64_lsr"
75
76 external of_int : int -> int64 = "%int64_of_int"
77 external to_int : int64 -> int = "%int64_to_int"
78 external of_float : float -> int64 = "caml_int64_of_float"
79 external to_float : int64 -> float = "caml_int64_to_float"
80 external of_int32 : int32 -> int64 = "%int64_of_int32"
81 external to_int32 : int64 -> int32 = "%int64_to_int32"
82 external of_int64 : int64 -> int64 = "%identity"
83 external to_int64 : int64 -> int64 = "%identity"
84 external of_nativeint : nativeint -> int64 = "%int64_of_nativeint"
85 external to_nativeint : int64 -> nativeint = "%int64_to_nativeint"
86
87 external of_string : string -> int64 = "caml_int64_of_string"
88 let to_string = Int64.to_string
89
90 let compare : int64 -> int64 -> int = Int64.compare