1 (* 63 bit signed integer type.
2 (C) Copyright 2008 Richard W.M. Jones, Red Hat Inc.
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.
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.
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.
19 (* This is the 32 bit implementation so we have to use the boxed
20 * and rather slow int64.
22 * Note that this code isn't quite correct, although not in a way
23 * that anyone is likely to notice, in that we don't truncate the
24 * underlying int64 to 63 bits on overflow.
28 module Operators = struct
31 external ( +^ ) : int64 -> int64 -> int64 = "%int64_add"
32 external ( -^ ) : int64 -> int64 -> int64 = "%int64_sub"
33 external ( *^ ) : int64 -> int64 -> int64 = "%int64_mul"
34 external ( /^ ) : int64 -> int64 -> int64 = "%int64_div"
35 external ( %^ ) : int64 -> int64 -> int64 = "%int64_mod"
36 external ( <^< ) : int64 -> int -> int64 = "%int64_lsl"
37 external ( >^> ) : int64 -> int -> int64 = "%int64_lsr"
38 external ( &^ ) : int64 -> int64 -> int64 = "%int64_and"
39 external ( |^ ) : int64 -> int64 -> int64 = "%int64_or"
40 external ( ^^ ) : int64 -> int64 -> int64 = "%int64_xor"
41 external ( ~^ ) : int -> int64 = "%int64_of_int"
42 let ( ~^~ ) i = Int64.neg (Int64.of_int i)
47 let minus_one = Int64.minus_one
49 external neg : int64 -> int64 = "%int64_neg"
51 external add : int64 -> int64 -> int64 = "%int64_add"
52 external sub : int64 -> int64 -> int64 = "%int64_sub"
53 external mul : int64 -> int64 -> int64 = "%int64_mul"
54 external div : int64 -> int64 -> int64 = "%int64_div"
55 external rem : int64 -> int64 -> int64 = "%int64_mod"
62 (* XXX Should these return the 'real' 64 bit max/min int? *)
63 let max_int = Int64.pred (Int64.shift_left Int64.one 62)
64 let min_int = Int64.neg (Int64.shift_left Int64.one 62)
66 external logand : int64 -> int64 -> int64 = "%int64_and"
67 external logor : int64 -> int64 -> int64 = "%int64_or"
68 external logxor : int64 -> int64 -> int64 = "%int64_xor"
69 let lognot = Int64.lognot
71 external shift_left : int64 -> int -> int64 = "%int64_lsl"
72 external shift_right : int64 -> int -> int64 = "%int64_asr"
73 external shift_right_logical : int64 -> int -> int64 = "%int64_lsr"
75 external of_int : int -> int64 = "%int64_of_int"
76 external to_int : int64 -> int = "%int64_to_int"
77 external of_float : float -> int64 = "caml_int64_of_float"
78 external to_float : int64 -> float = "caml_int64_to_float"
79 external of_int32 : int32 -> int64 = "%int64_of_int32"
80 external to_int32 : int64 -> int32 = "%int64_to_int32"
81 external of_int64 : int64 -> int64 = "%identity"
82 external to_int64 : int64 -> int64 = "%identity"
83 external of_nativeint : nativeint -> int64 = "%int64_of_nativeint"
84 external to_nativeint : int64 -> nativeint = "%int64_to_nativeint"
86 external of_string : string -> int64 = "caml_int64_of_string"
87 let to_string = Int64.to_string
89 let compare : int64 -> int64 -> int = Int64.compare