123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117# 2 "int64.ml"(**************************************************************************)(* *)(* OCaml *)(* *)(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)(* *)(* Copyright 1996 Institut National de Recherche en Informatique et *)(* en Automatique. *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)open!Stdlib[@@@ocaml.flambda_o3](* Module [Int64]: 64-bit integers *)externalneg:(int64[@local_opt])->(int64[@local_opt])@@portable="%int64_neg"externaladd:(int64[@local_opt])->(int64[@local_opt])->(int64[@local_opt])@@portable="%int64_add"externalsub:(int64[@local_opt])->(int64[@local_opt])->(int64[@local_opt])@@portable="%int64_sub"externalmul:(int64[@local_opt])->(int64[@local_opt])->(int64[@local_opt])@@portable="%int64_mul"externaldiv:(int64[@local_opt])->(int64[@local_opt])->(int64[@local_opt])@@portable="%int64_div"externalrem:(int64[@local_opt])->(int64[@local_opt])->(int64[@local_opt])@@portable="%int64_mod"externallogand:(int64[@local_opt])->(int64[@local_opt])->(int64[@local_opt])@@portable="%int64_and"externallogor:(int64[@local_opt])->(int64[@local_opt])->(int64[@local_opt])@@portable="%int64_or"externallogxor:(int64[@local_opt])->(int64[@local_opt])->(int64[@local_opt])@@portable="%int64_xor"externalshift_left:(int64[@local_opt])->int->(int64[@local_opt])@@portable="%int64_lsl"externalshift_right:(int64[@local_opt])->int->(int64[@local_opt])@@portable="%int64_asr"externalshift_right_logical:(int64[@local_opt])->int->(int64[@local_opt])@@portable="%int64_lsr"externalof_int:int->(int64[@local_opt])@@portable="%int64_of_int"externalto_int:(int64[@local_opt])->int@@portable="%int64_to_int"externalof_float:float->int64@@portable="caml_int64_of_float""caml_int64_of_float_unboxed"[@@unboxed][@@noalloc][@@builtin]externalto_float:int64->float@@portable="caml_int64_to_float""caml_int64_to_float_unboxed"[@@unboxed][@@noalloc][@@builtin]externalof_int32:int32->int64@@portable="%int64_of_int32"externalto_int32:int64->int32@@portable="%int64_to_int32"externalof_nativeint:nativeint->int64@@portable="%int64_of_nativeint"externalto_nativeint:int64->nativeint@@portable="%int64_to_nativeint"letzero=0Lletone=1Lletminus_one=-1Llet[@inlineavailable]succn=addn1Llet[@inlineavailable]predn=subn1Llet[@inlineavailable]absn=ifn>=0Lthennelsenegnletmin_int=0x8000000000000000Lletmax_int=0x7FFFFFFFFFFFFFFFLlet[@inlineavailable]lognotn=logxorn(-1L)letunsigned_to_int=letmax_int=of_intStdlib.max_intinfun[@inlineavailable]n->ifn>=0L&&n<=max_intthenSome(to_intn)elseNoneexternalformat:string->int64->string@@portable="caml_int64_format"let[@inlineavailable]to_stringn=format"%d"nexternalof_string:string->(int64[@unboxed])@@portable="caml_int64_of_string""caml_int64_of_string_unboxed"let[@inlineavailable]of_string_opts=trySome(of_strings)withFailure_->Noneexternalbits_of_float:float->int64@@portable="caml_int64_bits_of_float""caml_int64_bits_of_float_unboxed"[@@unboxed][@@noalloc]externalfloat_of_bits:int64->float@@portable="caml_int64_float_of_bits""caml_int64_float_of_bits_unboxed"[@@unboxed][@@noalloc]typet=int64let[@inlineavailable]compare(x:t)(y:t)=Stdlib.comparexylet[@inlineavailable]equal(x:t)(y:t)=x=ylet[@inlineavailable]unsigned_comparenm=compare(subnmin_int)(submmin_int)letunsigned_ltnm=subnmin_int<submmin_intlet[@inlineavailable]minxy:t=ifx<=ythenxelseylet[@inlineavailable]maxxy:t=ifx>=ythenxelsey(* Unsigned division from signed division of the same bitness.
See Warren Jr., Henry S. (2013). Hacker's Delight (2 ed.), Sec 9-3.
*)let[@inlineavailable]unsigned_divnd=ifd<zerothenifunsigned_ltndthenzeroelseoneelseletq=shift_left(div(shift_right_logicaln1)d)1inletr=subn(mulqd)inifunsigned_ltrdthenqelsesuccqlet[@inlineavailable]unsigned_remnd=subn(mul((unsigned_div[@inlined])nd)d)(* [caml_hash_exn] doesn't raise on int64s, so it's safe for
it to be marked as [@@noalloc].
*)externalseeded_hash_param:int->int->int->int64->int@@portable="caml_hash_exn"[@@noalloc]letseeded_hashseedx=seeded_hash_param10100seedxlethashx=seeded_hash_param101000x