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