···11+### v0.3.0 2022-12-16 Paris (France)
22+33+- Add infix operators for bitwise operations (@reynir, #23)
44+- Add a deprecation about old infix operators
55+ They will be removed at the next minor release
66+77+### v0.2.0 2022-04-08 Paris (France)
88+99+- Fix the README.md (@sidkshatriya, #19)
1010+- Fix fuzzers (@dinosaure, #20)
1111+- Add a proof to introspect the type of `Optint.t` (@dinosaure, #21)
1212+1313+### v0.1.0 2021-03-30 Paris (France)
1414+1515+- Annotate integer types with `[@@immediate64]` (@CraigFe, #13)
1616+- Move unwrapped module `Int63` to `Optint.Int63` (@CraigFe, #13)
1717+1818+### v0.0.5 2021-02-22 Paris (France)
1919+2020+- Update the README.md (@CraigFe, #9)
2121+- Add a representation of 63-bit integers (@CraigFe, #9)
2222+- Allow to compile fuzzers on 32-bit architectures (@dinosaure, #9)
2323+- Add encode / decode functions for integers (@CraigFe, #9)
2424+- Fix `optint` about sign and cast on all architectures (@dinosaure, #9)
2525+- **breaking changes**, rename and handle properly sign-bit:
2626+ `{of,to}_int` become `{of,to}_unsigned_int`
2727+ `{of,to}_int32` become `{of,to}_unsigned_int32`
2828+ Previous functions handle sign-bit correctly
2929+3030+### v0.0.4 2020-03-09 Paris (France)
3131+3232+- Fix 32bit backend where we miss to fully apply
3333+ an `invalid_arg`
3434+- Fix 64bit backend where `Native.unsigned_compare`
3535+ and `Nativeint.unsigned_div` exists (OCaml 4.08.0)
3636+3737+### v0.0.3 2010-09-12 Paris (France)
3838+3939+- Avoid partial application of function (#2, @dinosaure)
4040+- Add `[@immediate]` tag (#4, @dinosaure)
4141+- Fix `select.ml` in 32bit (#5, @IndiscriminateCoding)
4242+- Fix typo (#6, @hannesm)
4343+- Add fuzzer (#8, @dinosaure)
4444+- Fix `lsr` and `asr` in 64bit (#8, @cfcs, @dinosaure)
4545+- Optimization on `of_int` function (64bit) (#8, @cfcs, @dinosaure)
4646+- Optimization on `abs` function (64bit) (#8, @cfcs, @dinosaure)
4747+- Fix 32bit architecture, keep bit-sign in the same place (#8, @dinosaure, review @cfcs)
4848+4949+### v0.0.2 2018-10-15 Paris (France)
5050+5151+- _Dunify_ project
5252+- Fix dependencies on `dune` file when we select impl. (@rgrinberg)
5353+5454+### v0.0.1 2018-06-28 Paris (France)
5555+5656+- First version of `optint`
+20
vendor/opam/optint/LICENSE.md
···11+The MIT License (MIT)
22+33+Copyright (c) 2018 Romain Calascibetta
44+55+Permission is hereby granted, free of charge, to any person obtaining a copy of
66+this software and associated documentation files (the "Software"), to deal in
77+the Software without restriction, including without limitation the rights to
88+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
99+the Software, and to permit persons to whom the Software is furnished to do so,
1010+subject to the following conditions:
1111+1212+The above copyright notice and this permission notice shall be included in all
1313+copies or substantial portions of the Software.
1414+1515+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
1717+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
1818+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
1919+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2020+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+40
vendor/opam/optint/README.md
···11+Optint - Efficient integer types on 64-bit architectures
22+========================================================
33+44+This library provides two new integer types, `Optint.t` and `Optint.Int63.t`,
55+which guarantee efficient representation on 64-bit architectures and provide a
66+best-effort boxed representation on 32-bit architectures.
77+88+## Goal
99+1010+The standard `Int32.t` and `Int64.t` types provided by the standard library have
1111+the same heap-allocated representation on all architectures. This consistent
1212+representation has costs in both memory and run-time performance.
1313+1414+On 64-bit architectures, it's often more efficient to use the native `int`
1515+directly.
1616+This library provides types to do exactly this:
1717+1818+- `Optint.t`: an integer containing _at least_ 32 bits. On 64-bit, this is an
1919+ immediate integer; on 32-bit, it is a boxed 32-bit value. The overflow
2020+ behaviour is platform-dependent.
2121+2222+- `Optint.Int63.t`: an integer containing _exactly_ 63 bits. On 64-bit, this is
2323+ an immediate integer; on 32-bit, it is a boxed 64-bit integer that is wrapped
2424+ to provide 63-bit two's complement semantics. The two implementations are
2525+ observationally equivalent, modulo use of `Marshal` and `Obj`.
2626+2727+In summary:
2828+2929+| Integer type | 32-bit representation | 64-bit representation | Semantics |
3030+| -- | -- | -- | -- |
3131+| `Stdlib.Int.t` | 31-bit immediate ✅ | 63-bit immediate ✅ | Always immediate |
3232+| `Stdlib.Nativeint.t` | 32-bit boxed ❌ | 64-bit boxed ❌ | Exactly word size |
3333+| `Stdlib.Int32.t` | 32-bit boxed ❌ | 32-bit boxed ❌ | Exactly 32 bits |
3434+| `Stdlib.Int64.t` | 64-bit boxed ❌ | 64-bit boxed ❌ | Exactly 64 bits |
3535+| `Optint.t` (_new_) | 32-bit boxed ❌ | 63-bit immediate ✅ | _At least_ 32 bits |
3636+| `Optint.Int63.t` (_new_) | 64-bit boxed ❌ | 63-bit immediate ✅ | Exactly 63 bits |
3737+3838+These new types are safe and well-tested, but their architecture-dependent
3939+implementation makes them unsuitable for use with the `Marshal` module. Use the
4040+provided encode and decode functions instead.
···11+let max_intl = 0x3fffffff
22+33+let () =
44+ Crowbar.add_test ~name:"identity with int32" Crowbar.[ int32 ] @@ fun i32 ->
55+ let v = Optint.of_int32 i32 in
66+ let u = Optint.to_int32 v in
77+ Crowbar.check_eq ~pp:Fmt.int32 ~eq:Int32.equal ~cmp:Int32.compare i32 u
88+99+let () =
1010+ Crowbar.add_test ~name:"identity with int" Crowbar.[ bool; range max_intl ] @@ fun s i ->
1111+ let i = if s then - i else i in
1212+ let v = Optint.of_int i in
1313+ let u = Optint.to_int v in
1414+ Crowbar.check_eq ~pp:Fmt.int ~eq:(=) ~cmp:compare i u
1515+1616+let binary_operator =
1717+ Crowbar.(choose [ const `Add
1818+ ; const `Sub
1919+ ; const `Mul
2020+ ; const `Div
2121+ ; const `Rem
2222+ ; const `Lor
2323+ ; const `Land
2424+ ; const `Lxor ])
2525+let unary_operator =
2626+ Crowbar.(choose [ const `Neg
2727+ ; const `Succ
2828+ ; const `Pred
2929+ ; const `Lnot ])
3030+3131+type binary = [ `Add | `Sub | `Mul | `Div | `Rem | `Lor | `Land | `Lxor ]
3232+type unary = [ `Neg | `Succ | `Pred | `Lnot ]
3333+3434+let generate ~of_int =
3535+ let edge = Crowbar.map Crowbar.[ bool; range max_intl ] @@ fun sign v -> match sign with
3636+ | false -> `V (of_int v)
3737+ | true -> `V (of_int (- v)) in
3838+3939+ let edge_binary = Crowbar.map [ edge; edge; binary_operator ] @@ fun a b o -> [ a; b; o ] in
4040+ let node_binary = Crowbar.map [ edge; binary_operator ] @@ fun x o -> [ x; o ] in
4141+4242+ let edge_unary = Crowbar.map [ edge; unary_operator ] @@ fun x o -> [ x; o ] in
4343+ let node_unary = Crowbar.map [ unary_operator ] @@ fun o -> [ o ] in
4444+4545+ let edge = Crowbar.map [ edge ] @@ fun x -> [ x ] in
4646+ let edge = Crowbar.choose [ edge; edge_binary; edge_unary ] in
4747+ let node = Crowbar.choose [ node_binary; node_unary ] in
4848+4949+ Crowbar.(map [ edge; list node ] @@ fun x r -> List.concat (x :: r))
5050+5151+module type ARITHMETIC = sig
5252+ type t
5353+5454+ val add : t -> t -> t
5555+ val sub : t -> t -> t
5656+ val mul : t -> t -> t
5757+ val div : t -> t -> t
5858+ val rem : t -> t -> t
5959+ val logor : t -> t -> t
6060+ val logand : t -> t -> t
6161+ val logxor : t -> t -> t
6262+6363+ val abs : t -> t
6464+ val neg : t -> t
6565+ val succ : t -> t
6666+ val pred : t -> t
6767+ val lognot : t -> t
6868+end
6969+7070+type 'v p = [ binary | unary | `V of 'v ]
7171+7272+let pp_p ~pp_v ppf = function
7373+ | `Add -> Fmt.string ppf "+" | `Sub -> Fmt.string ppf "-" | `Mul -> Fmt.string ppf "*" | `Div -> Fmt.string ppf "/" | `Rem -> Fmt.string ppf "%"
7474+ | `Lor -> Fmt.string ppf "|" | `Land -> Fmt.string ppf "&" | `Lxor -> Fmt.string ppf "^"
7575+ | `Neg -> Fmt.string ppf "neg" | `Succ -> Fmt.string ppf "succ" | `Pred -> Fmt.string ppf "pred"
7676+ | `Lnot -> Fmt.string ppf "~"
7777+ | `V v -> pp_v ppf v
7878+7979+let rec binary
8080+ : type v. (module ARITHMETIC with type t = v) -> v -> v -> binary -> v p list -> v
8181+ = fun (module Arith) a b o r ->
8282+ let open Arith in
8383+8484+ match o with
8585+ | `Add -> eval (module Arith) (`V (add a b) :: r)
8686+ | `Sub -> eval (module Arith) (`V (sub a b) :: r)
8787+ | `Mul -> eval (module Arith) (`V (mul a b) :: r)
8888+ | `Div -> eval (module Arith) (`V (div a b) :: r)
8989+ | `Rem -> eval (module Arith) (`V (rem a b) :: r)
9090+ | `Lor -> eval (module Arith) (`V (logor a b) :: r)
9191+ | `Land -> eval (module Arith) (`V (logand a b) :: r)
9292+ | `Lxor -> eval (module Arith) (`V (logxor a b) :: r)
9393+9494+and unary
9595+ : type v. (module ARITHMETIC with type t = v) -> v -> unary -> v p list -> v
9696+ = fun (module Arith) x o r ->
9797+ let open Arith in
9898+9999+ match o with
100100+ | `Neg -> eval (module Arith) (`V (neg x) :: r)
101101+ | `Succ -> eval (module Arith) (`V (succ x) :: r)
102102+ | `Pred -> eval (module Arith) (`V (pred x) :: r)
103103+ | `Lnot -> eval (module Arith) (`V (lognot x) :: r)
104104+105105+and eval
106106+ : type v. (module ARITHMETIC with type t = v) -> v p list -> v
107107+ = fun arith -> function
108108+ | (`V a) :: (`V b) :: (#binary as o) :: r -> binary arith a b o r
109109+ | (`V x) :: (#unary as o) :: r -> unary arith x o r
110110+ | [ `V v ] -> v
111111+ | _ -> Crowbar.bad_test ()
112112+113113+let () =
114114+ Crowbar.add_test ~name:"computation" Crowbar.[ generate ~of_int:(fun x -> x) ] @@ fun l ->
115115+ (* XXX(dinosaure): FIXME even if it's not used. *)
116116+ if Sys.word_size = 32
117117+ then
118118+ let la = List.map
119119+ (function `V x -> `V (Optint.of_int x)
120120+ | (#binary | #unary) as x -> (x :> Optint.t p)) l in
121121+ let lb = List.map
122122+ (function `V x -> `V (Int32.of_int x)
123123+ | (#binary | #unary) as x -> (x :> int32 p)) l in
124124+125125+ let a = try Some (eval (module Optint) la) with Division_by_zero -> None in
126126+ let b = try Some (eval (module Int32) lb) with Division_by_zero -> None in
127127+ match a, b with
128128+ | None, None -> ()
129129+ | Some _, None | None, Some _ -> Crowbar.bad_test ()
130130+ | Some a, Some b ->
131131+ if (b > 0x3fffffffl || b < -0x3fffffffl) then Crowbar.bad_test () ;
132132+ let a = Optint.to_int a in
133133+ let b = Int32.to_int b in
134134+135135+ Crowbar.check_eq ~pp:(Fmt.fmt "%x") ~eq:(=) ~cmp:compare a b
+105
vendor/opam/optint/fuzz/fuzz_int63.ml
···11+open Monolith
22+33+let int = le Int.max_int
44+55+let int32 =
66+ let gen_random =
77+ let open Int32 in
88+ let bits () = of_int (Gen.bits ()) in
99+ fun () -> logxor (bits ()) (shift_left (bits ()) 30)
1010+ in
1111+ let pos = easily_constructible gen_random PPrint.OCaml.int32 in
1212+ let neg = deconstructible PPrint.OCaml.int32 in
1313+ ifpol pos neg
1414+1515+let float = deconstructible PPrint.OCaml.float
1616+let string = deconstructible PPrint.string
1717+1818+module type INTEGER = module type of Optint.Int63.Boxed
1919+2020+module Fuzz_integer_equivalence (Reference : INTEGER) (Candidate : INTEGER) =
2121+struct
2222+ module R = Reference
2323+ module C = Candidate
2424+2525+ let encoded_string : (string, string) spec =
2626+ let check_valid r c =
2727+ let exception Incorrect_length of string in
2828+ let exception Different of string * string in
2929+ if not (String.length c = R.encoded_size) then raise (Incorrect_length c);
3030+ if not (String.equal r c) then raise (Different (r, c))
3131+ in
3232+ declare_abstract_type
3333+ ~check:(fun r -> (check_valid r, document (PPrint.string r)))
3434+ ()
3535+3636+ module Wrap = struct
3737+ let pp f x =
3838+ f Format.str_formatter x;
3939+ Format.flush_str_formatter ()
4040+4141+ let encode f x =
4242+ let buf = Bytes.create R.encoded_size in
4343+ f buf ~off:0 x;
4444+ Bytes.unsafe_to_string buf
4545+4646+ let decode f s = f s ~off:0
4747+ end
4848+4949+ let run t fuel =
5050+ let endo = t ^> t in
5151+ let binop = t ^> t ^> t in
5252+ let binop_exn = t ^> t ^!> t in
5353+5454+ declare "zero" t R.zero C.zero;
5555+ declare "one" t R.one C.one;
5656+ declare "minus_one" t R.minus_one C.minus_one;
5757+ declare "max_int" t R.max_int C.max_int;
5858+ declare "min_int" t R.min_int C.min_int;
5959+6060+ declare "succ" endo R.succ C.succ;
6161+ declare "pred" endo R.pred C.pred;
6262+ declare "abs" endo R.abs C.abs;
6363+ declare "neg" endo R.neg C.neg;
6464+ declare "add" binop R.add C.add;
6565+ declare "sub" binop R.sub C.sub;
6666+ declare "mul" binop R.mul C.mul;
6767+ declare "div" binop_exn R.div C.div;
6868+ declare "rem" binop_exn R.rem C.rem;
6969+ declare "logand" binop R.logand C.logand;
7070+ declare "logor" binop R.logor C.logor;
7171+ declare "logxor" binop R.logxor C.logxor;
7272+ declare "lognot" endo R.lognot C.lognot;
7373+ declare "shift_left" (t ^> int ^> t) R.shift_left C.shift_left;
7474+ declare "shift_right" (t ^> int ^> t) R.shift_right C.shift_right;
7575+ declare "shift_right_logical"
7676+ (t ^> int ^> t)
7777+ R.shift_right_logical C.shift_right_logical;
7878+7979+ declare "compare" (t ^> t ^> int) R.compare C.compare;
8080+ declare "equal" (t ^> t ^> bool) R.equal C.equal;
8181+8282+ declare "of_int" (int ^> t) R.of_int C.of_int;
8383+ declare "to_int" (t ^> int) R.to_int C.to_int;
8484+ declare "of_int32" (int32 ^> t) R.of_int32 C.of_int32;
8585+ declare "to_int32" (t ^> int32) R.to_int32 C.to_int32;
8686+ declare "to_float" (t ^> float) R.to_float C.to_float;
8787+ declare "to_string" (t ^> string) R.to_string C.to_string;
8888+8989+ declare "pp" (t ^> string) (Wrap.pp R.pp) (Wrap.pp C.pp);
9090+ declare "encoded_size" int R.encoded_size C.encoded_size;
9191+ declare "encode" (t ^> encoded_string) (Wrap.encode R.encode)
9292+ (Wrap.encode C.encode);
9393+ declare "decode" (encoded_string ^> t) (Wrap.decode R.decode)
9494+ (Wrap.decode C.decode);
9595+9696+ main fuel
9797+end
9898+9999+module Reference = Optint.Int63
100100+module Candidate = Optint.Int63.Boxed
101101+module Int63_equiv = Fuzz_integer_equivalence (Reference) (Candidate)
102102+103103+let () =
104104+ let t : (Reference.t, Candidate.t) spec = declare_abstract_type () in
105105+ Int63_equiv.run t 5
···11+(* On 32-bit systems, we emulate a 63-bit integer via a boxed 64-bit integer
22+ with its lowest bit set to 0. The remaining 63 bits are left-shifted by one
33+ place. This is analogous to the standard encoding of [int], with the bottom
44+ bit set to 0 rather than 1.
55+66+ See {{:https://github.com/janestreet/base/blob/master/src/int63_emul.ml}[Base.Int63_emul]}
77+ for a similar encoding that has subtly different guarantees. This
88+ implementation seeks to be strictly observationally equivalent to the
99+ unemulated one (on 64-bit architectures), at the cost of performance of
1010+ certain functions.
1111+*)
1212+1313+type t = int64
1414+1515+(* The following all preserve semantics under our chosen encoding. *)
1616+include (Int64 : sig
1717+ val add : t -> t -> t
1818+ val sub : t -> t -> t
1919+ val rem : t -> t -> t
2020+ val neg : t -> t
2121+ val abs : t -> t
2222+ val logand : t -> t -> t
2323+ val logor : t -> t -> t
2424+ val shift_left : t -> int -> t
2525+ val equal : t -> t -> bool
2626+ val compare : t -> t -> int
2727+end)
2828+2929+let invalid_arg fmt = Format.kasprintf invalid_arg fmt
3030+3131+module Conv : sig
3232+ val wrap_exn : int64 -> t (* Raises if the [int64] has its topmost bit set. *)
3333+ val wrap_modulo : int64 -> t (* Discards the topmost bit of the [int64]. *)
3434+3535+ val unwrap : t -> int64 (* Lossless, assuming [t] satisfies the encoding. *)
3636+end = struct
3737+ let int64_fits_on_int63 =
3838+ let min = Int64.(shift_right min_int) 1 in
3939+ let max = Int64.(shift_right max_int) 1 in
4040+ fun x -> Int64.compare min x <= 0 && Int64.compare x max <= 0
4141+4242+ let wrap_modulo x = Int64.mul x 2L
4343+ let wrap_exn x =
4444+ if int64_fits_on_int63 x then
4545+ Int64.mul x 2L
4646+ else
4747+ Printf.ksprintf failwith
4848+ "Conversion from int64 to int63 failed: %Ld is out of range" x
4949+5050+ let unwrap x = Int64.shift_right x 1
5151+end
5252+5353+let unset_bottom_bit =
5454+ let mask = 0xffff_ffff_ffff_fffEL in
5555+ fun x -> Int64.logand x mask
5656+5757+let min_int = unset_bottom_bit Int64.min_int
5858+let max_int = unset_bottom_bit Int64.max_int
5959+let minus_one = Conv.wrap_exn (-1L)
6060+let zero = Conv.wrap_exn 0L
6161+let one = Conv.wrap_exn 1L
6262+6363+let succ x = add x one
6464+let pred x = sub x one
6565+6666+let mul x y = Int64.mul x (Conv.unwrap y)
6767+let div x y =
6868+ let r = Int64.div x y in
6969+ if Int64.equal r 0x4000_0000_0000_0000L then
7070+ (* This case happens when we overflow via [ min_int / 1 ], in which case we
7171+ should wrap back to [ min_int ]. *)
7272+ min_int
7373+ else
7474+ Conv.wrap_modulo r
7575+7676+let lognot x = unset_bottom_bit (Int64.lognot x)
7777+let logxor x y = unset_bottom_bit (Int64.logxor x y)
7878+let shift_right x i = unset_bottom_bit (Int64.shift_right x i)
7979+let shift_right_logical x i = unset_bottom_bit (Int64.shift_right_logical x i)
8080+8181+let to_int x = Int64.to_int (Conv.unwrap x)
8282+let of_int x = Conv.wrap_exn (Int64.of_int x)
8383+let to_int32 x = Int64.to_int32 (Conv.unwrap x)
8484+let of_int32 x = Conv.wrap_exn (Int64.of_int32 x)
8585+let to_int64 x = Conv.unwrap x
8686+let of_int64 x = Conv.wrap_exn x
8787+let to_float x = Int64.to_float (Conv.unwrap x)
8888+let of_float x = Conv.wrap_exn (Int64.of_float x)
8989+9090+let to_string x = Int64.to_string (Conv.unwrap x)
9191+let of_string x = Conv.wrap_exn (Int64.of_string x)
9292+let of_string_opt x = try Some (of_string x) with _ -> None
9393+9494+let pp ppf x = Format.fprintf ppf "%Ld" (Conv.unwrap x)
9595+9696+let to_unsigned_int x =
9797+ let max_int = of_int Stdlib.max_int in
9898+ if compare zero x <= 0 && compare x max_int <= 0
9999+ then to_int x
100100+ else invalid_arg "Int63.to_unsigned_int: %Lx can not fit into a 31 bits unsigned integer" x
101101+102102+let without_bit_sign (x:int) = if x >= 0 then x else x land (lnot 0x40000000)
103103+104104+let of_unsigned_int x =
105105+ if x < 0
106106+ then logor 0x40000000L (of_int (without_bit_sign x))
107107+ else of_int x
108108+109109+let to_unsigned_int32 x =
110110+ let max_int = of_int32 Int32.max_int in
111111+ if compare zero x <= 0 && compare x max_int <= 0
112112+ then to_int32 x
113113+ else invalid_arg "Int63.to_unsigned_int32: %Lx can not fit into a 32 bits unsigned integer" x
114114+115115+let of_unsigned_int32 x =
116116+ if x < 0l
117117+ then logor 0x80000000L (of_int32 (Int32.logand x (Int32.lognot 0x80000000l)))
118118+ else of_int32 x
119119+120120+let encoded_size = 8
121121+122122+external set_64 : bytes -> int -> int64 -> unit = "%caml_bytes_set64u"
123123+external get_64 : string -> int -> int64 = "%caml_string_get64"
124124+external swap64 : int64 -> int64 = "%bswap_int64"
125125+126126+let encode buf ~off t =
127127+ let t = to_int64 t in
128128+ let t = if not Sys.big_endian then swap64 t else t in
129129+ set_64 buf off t
130130+131131+let decode buf ~off =
132132+ let t = get_64 buf off in
133133+ let t = if not Sys.big_endian then swap64 t else t in
134134+ of_int64 t
135135+136136+module Infix = struct
137137+ let ( + ) a b = add a b
138138+ let ( - ) a b = sub a b
139139+ let ( * ) a b = mul a b
140140+ let ( % ) a b = rem a b
141141+ let ( / ) a b = div a b
142142+ let ( land ) a b = logand a b
143143+ let ( lor ) a b = logor a b
144144+ let ( lsr ) a b = shift_right a b
145145+ let ( lsl ) a b = shift_left a b
146146+147147+ let ( && ) = ( land )
148148+ let ( || ) = ( lor )
149149+ let ( >> ) = ( lsr )
150150+ let ( << ) = ( lsl )
151151+152152+end
···11+type t = int
22+33+let zero = 0
44+let one = 1
55+let minus_one = -1
66+let neg x = -x
77+let add a b = a + b
88+let sub a b = a - b
99+let mul a b = a * b
1010+let div a b = a / b
1111+let rem a b = a mod b
1212+let succ x = succ x
1313+let pred x = pred x
1414+let logand a b = a land b
1515+let logor a b = a lor b
1616+let logxor a b = a lxor b
1717+let lognot x = lnot x
1818+let shift_left a n = a lsl n
1919+let shift_right a n = a asr n
2020+let shift_right_logical a n = a lsr n
2121+let abs x = abs x
2222+let max_int = max_int
2323+let min_int = min_int
2424+2525+external of_int : t -> t = "%identity"
2626+external to_int : t -> t = "%identity"
2727+2828+let to_int32 = Stdlib.Int32.of_int
2929+let of_int32 = Stdlib.Int32.to_int
3030+let to_int64 = Stdlib.Int64.of_int
3131+let of_int64 = Stdlib.Int64.to_int
3232+let of_float x = int_of_float x
3333+let to_float x = float_of_int x
3434+let of_string x = int_of_string x
3535+let of_string_opt x = try Some (of_string x) with Failure _ -> None
3636+let to_string x = string_of_int x
3737+let equal : int -> int -> bool = fun a b -> a = b
3838+let compare : int -> int -> int = fun a b -> compare a b
3939+let pp = Format.pp_print_int
4040+4141+external to_unsigned_int : t -> int = "%identity"
4242+external of_unsigned_int : int -> t = "%identity"
4343+4444+let invalid_arg fmt = Format.kasprintf invalid_arg fmt
4545+4646+let to_unsigned_int32 =
4747+ let uint32_mask = (0xffff lsl 16) lor 0xffff in
4848+ fun x ->
4949+ let truncated = x land uint32_mask in
5050+ if x <> truncated
5151+ then invalid_arg "Int63.to_unsigned_int32: %d can not fit into a 32 bits integer" x
5252+ else Int32.of_int truncated
5353+5454+let of_unsigned_int32 =
5555+ let int32_sign_mask = 1 lsl 31 in
5656+ let int32_sign_maskl = 0x80000000l in
5757+ fun x ->
5858+ if x < 0l then
5959+ let x = Int32.logand x (Int32.lognot int32_sign_maskl) in
6060+ Int32.to_int x lor int32_sign_mask
6161+ else Int32.to_int x
6262+6363+let encoded_size = 8
6464+6565+external set_64 : bytes -> int -> int64 -> unit = "%caml_bytes_set64u"
6666+external get_64 : string -> int -> int64 = "%caml_string_get64"
6767+external swap64 : int64 -> int64 = "%bswap_int64"
6868+6969+let encode buf ~off t =
7070+ let t = to_int64 t in
7171+ let t = if not Sys.big_endian then swap64 t else t in
7272+ set_64 buf off t
7373+7474+let decode buf ~off =
7575+ let t = get_64 buf off in
7676+ let t = if not Sys.big_endian then swap64 t else t in
7777+ of_int64 t
7878+7979+module Infix = struct
8080+ let ( + ) a b = add a b
8181+ let ( - ) a b = sub a b
8282+ let ( * ) a b = mul a b
8383+ let ( % ) a b = rem a b
8484+ let ( / ) a b = div a b
8585+ let ( land ) a b = logand a b
8686+ let ( lor ) a b = logor a b
8787+ let ( lsr ) a b = shift_right a b
8888+ let ( lsl ) a b = shift_left a b
8989+9090+ let ( && ) = ( land )
9191+ let ( || ) = ( lor )
9292+ let ( >> ) = ( lsr )
9393+ let ( << ) = ( lsl )
9494+9595+end
+3
vendor/opam/optint/src/int63_native.mli
···11+type t = int [@@immediate]
22+33+include Integer_interface.S with type t := t
+175
vendor/opam/optint/src/integer_interface.ml
···11+module type S = sig
22+ type t
33+44+ val zero : t
55+ (** Integer 0. *)
66+77+ val one : t
88+ (** Integer 1. *)
99+1010+ val minus_one : t
1111+ (** Integer (-1). *)
1212+1313+ val neg : t -> t
1414+ (** Unary negation. *)
1515+1616+ val add : t -> t -> t
1717+ (** Addition. *)
1818+1919+ val sub : t -> t -> t
2020+ (** Subtraction. *)
2121+2222+ val mul : t -> t -> t
2323+ (** Mulitplication. *)
2424+2525+ val div : t -> t -> t
2626+ (** Integer division. Raise [Division_by_zero] if the second argument is zero.
2727+ This division rounds the real quotient of its arguments towrds zero. *)
2828+2929+ val rem : t -> t -> t
3030+ (** Integer remainder. If [y] is not zero, the result of [rem x y] satisfies
3131+ the following property: [x = add (mul (div x y) y) (rem x y)]. if [y = 0],
3232+ [rem x y] raises [Division_by_zero]. *)
3333+3434+ val succ : t -> t
3535+ (** Successor. [succ x] is [add x one]. *)
3636+3737+ val pred : t -> t
3838+ (** Predecessor. [pred x] is [sub x one]. *)
3939+4040+ val abs : t -> t
4141+ (** Return the absolute value its argument. *)
4242+4343+ val max_int : t
4444+ (** The greatest representable integer. *)
4545+4646+ val min_int : t
4747+ (** The smallest representable integer. *)
4848+4949+ val logand : t -> t -> t
5050+ (** Bitwise logical and. *)
5151+5252+ val logor : t -> t -> t
5353+ (** Bitwise logical or. *)
5454+5555+ val logxor : t -> t -> t
5656+ (** Bitwise logical exclusive or. *)
5757+5858+ val lognot : t -> t
5959+ (** Bitwise logical negation. *)
6060+6161+ val shift_left : t -> int -> t
6262+ (** [shift_left x y] shifts [x] to the left by [y] bits. The result is
6363+ unspecified if [y < 0] or [y >= (32 || 63)]. *)
6464+6565+ val shift_right : t -> int -> t
6666+ (** [shift_right x y] shifts [x] to the right by [y] bits. This is an
6767+ arithmetic shift: the sign bit of [x] is replicated and inserted in the
6868+ vacated bits. The result is unspecified if [y < 0] or [y >= (32 || 63)]. *)
6969+7070+ val shift_right_logical : t -> int -> t
7171+ (** [shift_right_logical x y] shifts [x] to the right by [y] bits. This is a
7272+ logical shift: zeroes are inserted in the vacated bits regardless of the
7373+ sign of [x] / The result is unspecified if [y < 0] or [y >= (32 || 63)]. *)
7474+7575+ val of_int : int -> t
7676+ (** Convert the given integer (type [int] ) to {!t}. It's an unsafe function
7777+ whose semantic is different from architecture. *)
7878+7979+ val to_int : t -> int
8080+ (** Convert the given {!t} integer to an integer (type [int] ). On 64-bit
8181+ platforms, the conversion is exact. On 32-bit platforms, the 32-bit
8282+ integer is taken modulo 2 {^ 31}, i.e. the high-order bit is lost during
8383+ the conversion. *)
8484+8585+ val of_int32 : int32 -> t
8686+ (** Convert the given 32-bit integer (type [int32]) to {!t} integer. It's an
8787+ unsafe function whose semantic is different from architecture. *)
8888+8989+ val to_int32 : t -> int32
9090+ (** Convert the given {!t} integer to a 32-bit integer. *)
9191+9292+ val of_int64 : int64 -> t
9393+ (** Convert the given 64-bit integer (type [int64]) to {!t} integer. *)
9494+9595+ val to_int64 : t -> int64
9696+ (** Covert the given {!t} integer to a 64-bit integer. *)
9797+9898+ val of_float : float -> t
9999+ (** Convert the given floating-point number to a {!t} integer, discarding the
100100+ fractional part (truncate towards 0). The result of the conversion is
101101+ undefined if, after truncation, the number is outside the range
102102+ {!min_int}, {!max_int}. *)
103103+104104+ val to_float : t -> float
105105+ (** Convert the given {!t} integer to a floating-point number. *)
106106+107107+ val of_string : string -> t
108108+ (** Convert the given string to a {!t} integer. The string is read in decimal
109109+ (by default, or if the string begins with [0u]) or in hexadecimal, octal
110110+ or binary if the string begins with [0x], [0o] or [0b] respectively.
111111+112112+ The [0u] prefix reads the input as an unsigned integer in the range
113113+ [\[0, 2 * max_int + 1\]]. If the input exceeds {!max_int} it is converted
114114+ to the signed integer [min_int + input - max_int - 1].
115115+116116+ The [_] (underscore) character can appear anywhere in the string is
117117+ ignored. Raise [Failure _] if the given string is not a valid
118118+ representation of an integer, or if the integer represented exceeds the
119119+ range of integer, or if the integer represented exceeds the range of
120120+ integers representable in type {!t}. *)
121121+122122+ val of_string_opt : string -> t option
123123+ (** Same as [of_string], but return [None] instead of raising. *)
124124+125125+ val to_string : t -> string
126126+ (** Return the string representation of its argument, in decimal. *)
127127+128128+ val compare : t -> t -> int
129129+ (** The comparison function for {!t} integers, with the same specification as
130130+ {!Stdlib.compare}. Along with the type [t], this function [compare] allows
131131+ the module [Optint] to be passed as argument to the functors {!Set.Make}
132132+ and {!Map.Make}. *)
133133+134134+ val equal : t -> t -> bool
135135+ (** The equal function for {!t}. *)
136136+137137+ val pp : Format.formatter -> t -> unit
138138+ (** The pretty-printer for {!t}. *)
139139+140140+ (** {2 Encoding functions}
141141+142142+ Efficient fixed-length big-endian encoding functions for {!t} integers: *)
143143+144144+ val encode : bytes -> off:int -> t -> unit
145145+ val decode : string -> off:int -> t
146146+147147+ val encoded_size : int
148148+ (** The number of bytes in the {{!encode} encoded} form of {!t}. *)
149149+150150+ val to_unsigned_int32 : t -> int32
151151+ val of_unsigned_int32 : int32 -> t
152152+ val to_unsigned_int : t -> int
153153+ val of_unsigned_int : int -> t
154154+155155+ module Infix : sig
156156+ val ( + ) : t -> t -> t
157157+ val ( - ) : t -> t -> t
158158+ val ( * ) : t -> t -> t
159159+ val ( % ) : t -> t -> t
160160+ val ( / ) : t -> t -> t
161161+ val ( land ) : t -> t -> t
162162+ val ( lor ) : t -> t -> t
163163+ val ( lsr ) : t -> int -> t
164164+ val ( lsl ) : t -> int -> t
165165+166166+ val ( && ) : t -> t -> t
167167+ [@@ocaml.deprecated "Please use ( land )."]
168168+ val ( || ) : t -> t -> t
169169+ [@@ocaml.deprecated "Please use ( lor )."]
170170+ val ( >> ) : t -> int -> t
171171+ [@@ocaml.deprecated "Please use ( lsr )."]
172172+ val ( << ) : t -> int -> t
173173+ [@@ocaml.deprecated "Please use ( lsl )."]
174174+ end
175175+end
+77
vendor/opam/optint/src/optint.ml
···11+(** Extraction of [Stdlib.Sys.Immediate64] for pre-4.10 compatibility.
22+ [Immediate64] was originally authored by Jeremie Dimino <jeremie@dimino.org>,
33+ and is licensed along with the OCaml compiler system under LGPLv2. See the
44+ {{:https://github.com/ocaml/ocaml/blob/trunk/LICENSE} compiler license} for
55+ details.
66+77+ For soundness of the [@@immediate64] annotation, we ensure to use the boxed
88+ representation only when not on 64-bit platforms, but we need to use The
99+ Force to convince the type system of this fact. *)
1010+module Immediate64 = struct
1111+ module type Non_immediate = sig
1212+ type t
1313+ end
1414+1515+ module type Immediate = sig
1616+ type t [@@immediate]
1717+ end
1818+1919+ module Make (Immediate : Immediate) (Non_immediate : Non_immediate) = struct
2020+ type t [@@immediate64]
2121+2222+ type 'a repr =
2323+ | Immediate : Immediate.t repr
2424+ | Non_immediate : Non_immediate.t repr
2525+2626+ external magic : _ repr -> t repr = "%identity"
2727+2828+ let repr =
2929+ if Sys.word_size = 64 then magic Immediate else magic Non_immediate
3030+ end
3131+end
3232+3333+module Conditional = struct
3434+ type ('t, 'u, 'v) t =
3535+ | True : ('t, 't, _) t (** therefore ['t] = ['u] *)
3636+ | False : ('t, _, 't) t (** therefore ['t] = ['v] *)
3737+end
3838+3939+module Optint = struct
4040+ include Immediate64.Make (Optint_native) (Optint_emul)
4141+4242+ module type S = Integer_interface.S with type t := t
4343+4444+ let impl : (module S) =
4545+ match repr with
4646+ | Immediate -> (module Optint_native : S)
4747+ | Non_immediate -> (module Optint_emul : S)
4848+4949+ include (val impl : S)
5050+5151+ let is_immediate : (t, int, int32) Conditional.t =
5252+ match repr with
5353+ | Immediate -> True
5454+ | Non_immediate -> False
5555+end
5656+5757+module Int63 = struct
5858+ include Immediate64.Make (Int63_native) (Int63_emul)
5959+6060+ module type S = Integer_interface.S with type t := t
6161+6262+ let impl : (module S) =
6363+ match repr with
6464+ | Immediate -> (module Int63_native : S)
6565+ | Non_immediate -> (module Int63_emul : S)
6666+6767+ include (val impl : S)
6868+6969+ module Boxed = Int63_emul
7070+7171+ let is_immediate : (t, int, Boxed.t) Conditional.t =
7272+ match repr with
7373+ | Immediate -> True
7474+ | Non_immediate -> False
7575+end
7676+7777+include Optint
+36
vendor/opam/optint/src/optint.mli
···11+type t [@@immediate64]
22+(** The type of integers with {i at least} 32 bits.
33+ For 63-bit integers, see {!Int63}. *)
44+55+include Integer_interface.S with type t := t
66+(** @inline *)
77+88+(** {1 Other modules} *)
99+1010+(** A conditional type equality, used for revealing that a type [t] has one of
1111+ two possible implementation types [u] and [v]. *)
1212+module Conditional : sig
1313+ type ('t, 'u, 'v) t =
1414+ | True : ('t, 't, _) t (** therefore ['t] = ['u] *)
1515+ | False : ('t, _, 't) t (** therefore ['t] = ['v] *)
1616+end
1717+1818+val is_immediate : (t, int, int32) Conditional.t
1919+2020+(** 63-bit integers. *)
2121+module Int63 : sig
2222+ type t [@@immediate64]
2323+ (** The type of integers with exactly 63-bits. *)
2424+2525+ include Integer_interface.S with type t := t
2626+ (** @inline *)
2727+2828+ module Boxed : Integer_interface.S
2929+ (** An implementation of 63-bit integers that always uses a boxed
3030+ representation regardless of word size. *)
3131+3232+ (** [is_immediate] reveals the implementation of {!t} on the current
3333+ platform, and can be used to build [Int63] operations that behave
3434+ differently depending on the underlying representation, such as FFIs. *)
3535+ val is_immediate : (t, int, Boxed.t) Conditional.t
3636+end
+89
vendor/opam/optint/src/optint_emul.ml
···11+include Int32
22+33+external of_int32 : int32 -> t = "%identity"
44+external of_unsigned_int32 : int32 -> t = "%identity"
55+external to_int32 : t -> int32 = "%identity"
66+external to_unsigned_int32 : t -> int32 = "%identity"
77+88+let to_int64 = Int64.of_int32
99+let of_int64 = Int64.to_int32
1010+1111+let pp ppf (x:t) = Format.fprintf ppf "%ld" x
1212+1313+let without_bit_sign (x:int) = if x >= 0 then x else x land (lnot 0x40000000)
1414+1515+let invalid_arg fmt = Format.kasprintf invalid_arg fmt
1616+1717+(* XXX(dinosaure): the diff between [to_int] and [to_unsigned_int]
1818+ * is about the sign-bit [0x40000000][int]/[0x80000000][int32].
1919+ *
2020+ * For [to_int], we ensure for a negative number that we use only
2121+ * [0x3fffffff][int32] bits two most significant bits are set to [1].
2222+ * In that case, it safes to cast the [int32] to and [int] (31 bits).
2323+ *
2424+ * For [to_unsigned_int], we don't want to interpret if the value is
2525+ * negative or positive. However, if the number can be interpreted as a
2626+ * negative nnumber, due to the two's complement layout, we are sure
2727+ * to lost, at least, the most significant bit which is a part of unsigned
2828+ * [int32]. So we are able to only accept "positive" numbers.
2929+ *
3030+ * NOTE: we trust on the two's complement! *)
3131+3232+let to_int x =
3333+ let max_int = of_int Stdlib.max_int in
3434+ if compare zero x <= 0 && compare x max_int <= 0
3535+ then to_int x (* XXX(dinosaure): positive and can fit into a 31-bit integer. *)
3636+ else if compare zero x > 0 && Int32.logand 0xC0000000l x = 0xC0000000l
3737+ then let x = Int32.logand x 0x7fffffffl in to_int x
3838+ else invalid_arg "Optint.to_int: %lx can not fit into a 31 bits integer" x
3939+4040+let to_unsigned_int x =
4141+ let max_int = of_int Stdlib.max_int in
4242+ if compare zero x <= 0 && compare x max_int <= 0
4343+ then to_int x
4444+ else invalid_arg "Optint.to_unsigned_int: %lx can not fit into a 31 bits unsigned integer" x
4545+4646+let of_int x =
4747+ if x < 0
4848+ then logor 0xC0000000l (of_int (without_bit_sign x))
4949+ else of_int x
5050+5151+let of_unsigned_int x =
5252+ if x < 0
5353+ then logor 0x40000000l (of_int (without_bit_sign x))
5454+ else of_int x
5555+5656+let encoded_size = 4
5757+5858+external set_32 : bytes -> int -> int32 -> unit = "%caml_bytes_set32u"
5959+external get_32 : string -> int -> int32 = "%caml_string_get32"
6060+external swap32 : int32 -> int32 = "%bswap_int32"
6161+6262+let encode buf ~off t =
6363+ let t = to_int32 t in
6464+ let t = if not Sys.big_endian then swap32 t else t in
6565+ set_32 buf off t
6666+6767+let decode buf ~off =
6868+ let t = get_32 buf off in
6969+ let t = if not Sys.big_endian then swap32 t else t in
7070+ of_int32 t
7171+7272+module Infix = struct
7373+ let ( + ) a b = add a b
7474+ let ( - ) a b = sub a b
7575+ let ( * ) a b = mul a b
7676+ let ( % ) a b = rem a b
7777+ let ( / ) a b = div a b
7878+7979+ let ( land ) a b = logand a b
8080+ let ( lor ) a b = logor a b
8181+ let ( lsr ) a b = shift_right a b
8282+ let ( lsl ) a b = shift_left a b
8383+8484+ let ( && ) = ( land )
8585+ let ( || ) = ( lor )
8686+ let ( >> ) = ( lsr )
8787+ let ( << ) = ( lsl )
8888+8989+end
+1
vendor/opam/optint/src/optint_emul.mli
···11+include Integer_interface.S with type t = int32
+126
vendor/opam/optint/src/optint_native.ml
···11+type t = int
22+33+let zero = 0
44+let one = 1
55+let minus_one = (-1)
66+let neg x = (-x)
77+let add a b = a + b
88+let sub a b = a - b
99+let mul a b = a * b
1010+1111+let _unsigned_compare n m =
1212+ let open Nativeint in
1313+ compare (sub n min_int) (sub m min_int)
1414+1515+let _unsigned_div n d =
1616+ let open Nativeint in
1717+ if d < zero then
1818+ if _unsigned_compare n d < 0 then zero else one
1919+ else
2020+ let q = shift_left (div (shift_right_logical n 1) d) 1 in
2121+ let r = sub n (mul q d) in
2222+ if _unsigned_compare r d >= 0 then succ q else q
2323+2424+let div a b = Nativeint.to_int (_unsigned_div (Nativeint.of_int a) (Nativeint.of_int b))
2525+let rem a b = a mod b
2626+let succ x = x + 1
2727+let pred x = x - 1
2828+let abs x =
2929+ let mask = x asr Sys.int_size in (* extract sign: -1 if signed, 0 if not signed *)
3030+ (x + mask) lxor mask
3131+let max_int = Int32.(to_int max_int)
3232+let min_int = Int32.(to_int min_int)
3333+let logand a b = a land b
3434+let logor a b = a lor b
3535+let logxor a b = a lxor b
3636+let lognot x = lnot x
3737+let shift_left a n = a lsl n
3838+let shift_right a n = a asr n
3939+let shift_right_logical a n = a lsr n
4040+external of_int : int -> t = "%identity"
4141+external of_unsigned_int : int -> t = "%identity"
4242+external to_int : t -> int = "%identity"
4343+external to_unsigned_int : t -> int = "%identity"
4444+let to_int64 = Stdlib.Int64.of_int
4545+let of_int64 = Stdlib.Int64.to_int
4646+let of_float x = int_of_float x
4747+let to_float x = (* allocation *) float_of_int x
4848+let of_string x = int_of_string x
4949+let of_string_opt x = try (* allocation *) Some (of_string x) with Failure _ -> None
5050+let to_string x = string_of_int x
5151+let compare : int -> int -> int = fun a b -> a - b
5252+let equal : int -> int -> bool = fun a b -> a = b
5353+5454+let invalid_arg fmt = Format.kasprintf invalid_arg fmt
5555+5656+let uint32_max = (0xffff lsl 16) lor 0xffff
5757+let int32_sign_maskl = 0x80000000l
5858+let int32_sign_mask = 1 lsl 31
5959+let int32_maxl = 0x7fffffffl
6060+let int32_max = 0x7fffffff
6161+6262+let to_int32 x =
6363+ let truncated = x land uint32_max in
6464+ if x = truncated then Int32.of_int truncated
6565+ else if compare 0 x > 0 && (x lsr 31) = uint32_max
6666+ then Int32.(logor int32_sign_maskl (of_int (x land int32_max)))
6767+ else invalid_arg "Optint.to_int32: %d can not fit into a 32 bits integer" x
6868+6969+let to_unsigned_int32 x =
7070+ let truncated = x land uint32_max in
7171+ if x <> truncated
7272+ then invalid_arg "Optint.to_unsigned_int32: %d can not fit into a 32 bits integer" x
7373+ else Int32.of_int truncated
7474+7575+let of_int32 =
7676+ let negative_int32_mask = (int32_max lsl 32) lor int32_sign_mask in
7777+ fun x ->
7878+ if x < 0l
7979+ then
8080+ let x = Int32.logand x int32_maxl in
8181+ negative_int32_mask lor (Int32.to_int x)
8282+ else Int32.to_int x
8383+8484+let of_unsigned_int32 x =
8585+ if x < 0l
8686+ then
8787+ let x = Int32.logand x (Int32.lognot int32_sign_maskl) in
8888+ (Int32.to_int x) lor int32_sign_mask
8989+ else Int32.to_int x
9090+9191+let pp ppf (x:t) = Format.fprintf ppf "%d" x
9292+9393+let encoded_size = 4
9494+9595+external set_32 : bytes -> int -> int32 -> unit = "%caml_bytes_set32u"
9696+external get_32 : string -> int -> int32 = "%caml_string_get32"
9797+external swap32 : int32 -> int32 = "%bswap_int32"
9898+9999+let encode buf ~off t =
100100+ let t = to_int32 t in
101101+ let t = if not Sys.big_endian then swap32 t else t in
102102+ set_32 buf off t
103103+104104+let decode buf ~off =
105105+ let t = get_32 buf off in
106106+ let t = if not Sys.big_endian then swap32 t else t in
107107+ of_int32 t
108108+109109+module Infix = struct
110110+ let ( + ) a b = add a b
111111+ let ( - ) a b = sub a b
112112+ let ( * ) a b = mul a b
113113+ let ( % ) a b = rem a b
114114+ let ( / ) a b = div a b
115115+116116+ let ( land ) a b = logand a b
117117+ let ( lor ) a b = logor a b
118118+ let ( lsr ) a b = shift_right a b
119119+ let ( lsl ) a b = shift_left a b
120120+121121+ let ( && ) = ( land )
122122+ let ( || ) = ( lor )
123123+ let ( >> ) = ( lsr )
124124+ let ( << ) = ( lsl )
125125+126126+end
+3
vendor/opam/optint/src/optint_native.mli
···11+type t = int [@@immediate]
22+33+include Integer_interface.S with type t := t