File: int64Scalar.ml

package info (click to toggle)
herdtools7 7.58-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,732 kB
  • sloc: ml: 128,583; ansic: 3,827; makefile: 670; python: 407; sh: 212; awk: 14
file content (71 lines) | stat: -rw-r--r-- 2,396 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
(****************************************************************************)
(*                           the diy toolsuite                              *)
(*                                                                          *)
(* Jade Alglave, University College London, UK.                             *)
(* Luc Maranget, INRIA Paris-Rocquencourt, France.                          *)
(*                                                                          *)
(* Copyright 2017-present Institut National de Recherche en Informatique et *)
(* en Automatique and the authors. All rights reserved.                     *)
(*                                                                          *)
(* This software is governed by the CeCILL-B license under French law and   *)
(* abiding by the rules of distribution of free software. You can use,      *)
(* modify and/ or redistribute the software under the terms of the CeCILL-B *)
(* license as circulated by CEA, CNRS and INRIA at the following URL        *)
(* "http://www.cecill.info". We also give a copy in LICENSE.txt.            *)
(****************************************************************************)


include Int64

let unique_zero = true

let printable c = c

let shift_right_arithmetic = Int64.shift_right

let addk x k = match k with
  | 0 -> x
  | 1 -> succ x
  | _ -> add x (of_int k)

let machsize = MachSize.Quad

let pp hexa v =
  Printf.sprintf (if hexa then "0x%Lx" else "%Li") v

let pp_unsigned hexa v =
  Printf.sprintf (if hexa then "0x%Lx" else "%Lu") v

let lt v1 v2 = compare v1 v2 < 0
let le v1 v2 = compare v1 v2 <= 0
let bit_at k v = Int64.logand v (Int64.shift_left Int64.one k)
let mask sz =
  let open MachSize in
  match sz with
  | Byte -> fun v -> logand v 0xffL
  | Short -> fun v -> logand v 0xffffL
  | Word -> fun v ->  logand v 0xffffffffL
  | Quad -> fun v -> v
  | S128 -> fun v -> Warn.fatal "mask 64 bit value %s with s128 mask" (pp_unsigned true v)

let sxt sz v =
  let open MachSize in
  match sz with
  | Quad -> v
  | _ ->
     let v = mask sz v in
     let nb = nbits sz in
     let m = shift_left one (nb-1) in
     sub (logxor v m) m

let of_int64 = Misc.identity
let to_int64 = Misc.identity

let as_bool v = Some (Bool.not (Int64.equal Int64.zero v))
let s_true = one
let s_false = zero

let get_tag _ = assert false
let set_tag _ = assert false

include NoPromote