1 (* 63 bit signed integer type.
2 (C) Copyright 2008 Richard W.M. Jones, Red Hat Inc.
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.
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.
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
20 (* This is the 32 bit implementation so we have to use the boxed
21 * and rather slow int64.
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.
29 module Operators = struct
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)
48 let minus_one = Int64.minus_one
50 external neg : int64 -> int64 = "%int64_neg"
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"
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)
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
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"
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"
87 external of_string : string -> int64 = "caml_int64_of_string"
88 let to_string = Int64.to_string
90 let compare : int64 -> int64 -> int = Int64.compare