Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file int64.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319open!Importopen!Caml.Int64moduleT=structtypet=int64[@@deriving_inlinehash,sexp,sexp_grammar]let(hash_fold_t:Ppx_hash_lib.Std.Hash.state->t->Ppx_hash_lib.Std.Hash.state)=hash_fold_int64and(hash:t->Ppx_hash_lib.Std.Hash.hash_value)=letfunc=hash_int64infunx->funcx;;lett_of_sexp=(int64_of_sexp:Ppx_sexp_conv_lib.Sexp.t->t)letsexp_of_t=(sexp_of_int64:t->Ppx_sexp_conv_lib.Sexp.t)let(t_sexp_grammar:Ppx_sexp_conv_lib.Sexp.Private.Raw_grammar.t)=let(_the_generic_group:Ppx_sexp_conv_lib.Sexp.Private.Raw_grammar.generic_group)={implicit_vars=["int64"];ggid="\146e\023\249\235eE\139c\132W\195\137\129\235\025";types=["t",Implicit_var0]}inlet(_the_group:Ppx_sexp_conv_lib.Sexp.Private.Raw_grammar.group)={gid=Ppx_sexp_conv_lib.Lazy_group_id.create();apply_implicit=[int64_sexp_grammar];generic_group=_the_generic_group;origin="int64.ml.T"}inlet(t_sexp_grammar:Ppx_sexp_conv_lib.Sexp.Private.Raw_grammar.t)=Ref("t",_the_group)int_sexp_grammar;;[@@@end]letcompare=Int64_replace_polymorphic_compare.compareletto_string=to_stringletof_string=of_stringendincludeTincludeComparator.Make(T)letnum_bits=64letfloat_lower_bound=Float0.lower_bound_for_intnum_bitsletfloat_upper_bound=Float0.upper_bound_for_intnum_bitsletfloat_of_bits=float_of_bitsletbits_of_float=bits_of_floatletshift_right_logical=shift_right_logicalletshift_right=shift_rightletshift_left=shift_leftletbit_not=lognotletbit_xor=logxorletbit_or=logorletbit_and=logandletmin_value=min_intletmax_value=max_intletabs=absletpred=predletsucc=succletpow=Int_math.Private.int64_powletrem=remletneg=negletminus_one=minus_oneletone=oneletzero=zeroletto_float=to_floatletof_float_unchecked=Caml.Int64.of_floatletof_floatf=ifFloat_replace_polymorphic_compare.(>=)ffloat_lower_bound&&Float_replace_polymorphic_compare.(<=)ffloat_upper_boundthenCaml.Int64.of_floatfelsePrintf.invalid_argf"Int64.of_float: argument (%f) is out of range or NaN"(Float0.boxf)();;let(**)be=powbeexternalbswap64:t->t="%bswap_int64"let[@inlinealways]bswap16x=Caml.Int64.shift_right_logical(bswap64x)48let[@inlinealways]bswap32x=(* This is strictly better than coercing to an int32 to perform byteswap. Coercing
from an int32 will add unnecessary shift operations to sign extend the number
appropriately.
*)Caml.Int64.shift_right_logical(bswap64x)32;;let[@inlinealways]bswap48x=Caml.Int64.shift_right_logical(bswap64x)16includeComparable.Validate_with_zero(structincludeTletzero=zeroend)(* Open replace_polymorphic_compare after including functor instantiations so they do not
shadow its definitions. This is here so that efficient versions of the comparison
functions are available within this module. *)openInt64_replace_polymorphic_compareletinvariant(_:t)=()letbetweent~low~high=low<=t&&t<=highletclamp_uncheckedt~min~max=ift<minthenminelseift<=maxthentelsemaxletclamp_exnt~min~max=assert(min<=max);clamp_uncheckedt~min~max;;letclampt~min~max=ifmin>maxthenOr_error.error_s(Sexp.message"clamp requires [min <= max]"["min",T.sexp_of_tmin;"max",T.sexp_of_tmax])elseOk(clamp_uncheckedt~min~max);;let(/)=divlet(*)=mullet(-)=sublet(+)=addlet(~-)=negletincrr=r:=!r+oneletdecrr=r:=!r-oneletof_int64t=tletof_int64_exn=of_int64letto_int64t=tletpopcount=Popcount.int64_popcountmoduleConv=Int_conversionsletof_int=Conv.int_to_int64letof_int_exn=of_intletto_int=Conv.int64_to_intletto_int_exn=Conv.int64_to_int_exnletto_int_trunc=Conv.int64_to_int_truncletof_int32=Conv.int32_to_int64letof_int32_exn=of_int32letto_int32=Conv.int64_to_int32letto_int32_exn=Conv.int64_to_int32_exnletto_int32_trunc=Conv.int64_to_int32_truncletof_nativeint=Conv.nativeint_to_int64letof_nativeint_exn=of_nativeintletto_nativeint=Conv.int64_to_nativeintletto_nativeint_exn=Conv.int64_to_nativeint_exnletto_nativeint_trunc=Conv.int64_to_nativeint_truncmodulePow2=structopen!ImportopenInt64_replace_polymorphic_comparemoduleSys=Sys0letraise_s=Error.raise_sletnon_positive_argument()=Printf.invalid_argf"argument must be strictly positive"();;let(lor)=Caml.Int64.logorlet(lsr)=Caml.Int64.shift_right_logicallet(land)=Caml.Int64.logand(** "ceiling power of 2" - Least power of 2 greater than or equal to x. *)letceil_pow2x=ifx<=Caml.Int64.zerothennon_positive_argument();letx=Caml.Int64.predxinletx=xlor(xlsr1)inletx=xlor(xlsr2)inletx=xlor(xlsr4)inletx=xlor(xlsr8)inletx=xlor(xlsr16)inletx=xlor(xlsr32)inCaml.Int64.succx;;(** "floor power of 2" - Largest power of 2 less than or equal to x. *)letfloor_pow2x=ifx<=Caml.Int64.zerothennon_positive_argument();letx=xlor(xlsr1)inletx=xlor(xlsr2)inletx=xlor(xlsr4)inletx=xlor(xlsr8)inletx=xlor(xlsr16)inletx=xlor(xlsr32)inCaml.Int64.subx(xlsr1);;letis_pow2x=ifx<=Caml.Int64.zerothennon_positive_argument();xlandCaml.Int64.predx=Caml.Int64.zero;;(* C stubs for int clz and ctz to use the CLZ/BSR/CTZ/BSF instruction where possible *)externalclz:(int64[@unboxed])->(int[@untagged])="Base_int_math_int64_clz""Base_int_math_int64_clz_unboxed"[@@noalloc]externalctz:(int64[@unboxed])->(int[@untagged])="Base_int_math_int64_ctz""Base_int_math_int64_ctz_unboxed"[@@noalloc](** Hacker's Delight Second Edition p106 *)letfloor_log2i=ifi<=Caml.Int64.zerothenraise_s(Sexp.message"[Int64.floor_log2] got invalid input"["",sexp_of_int64i]);num_bits-1-clzi;;(** Hacker's Delight Second Edition p106 *)letceil_log2i=ifPoly.(<=)iCaml.Int64.zerothenraise_s(Sexp.message"[Int64.ceil_log2] got invalid input"["",sexp_of_int64i]);ifCaml.Int64.equaliCaml.Int64.onethen0elsenum_bits-clz(Caml.Int64.predi);;endincludePow2includeConv.Make(T)includeConv.Make_hex(structtypet=int64[@@deriving_inlinecompare,hash]letcompare=(compare_int64:t->t->int)let(hash_fold_t:Ppx_hash_lib.Std.Hash.state->t->Ppx_hash_lib.Std.Hash.state)=hash_fold_int64and(hash:t->Ppx_hash_lib.Std.Hash.hash_value)=letfunc=hash_int64infunx->funcx;;[@@@end]letzero=zeroletneg=(~-)let(<)=(<)letto_stringi=Printf.sprintf"%Lx"iletof_strings=Caml.Scanf.sscanfs"%Lx"Fn.idletmodule_name="Base.Int64.Hex"end)includePretty_printer.Register(structtypenonrect=tletto_string=to_stringletmodule_name="Base.Int64"end)modulePre_O=structlet(+)=(+)let(-)=(-)let(*)=(*)let(/)=(/)let(~-)=(~-)let(**)=(**)include(Int64_replace_polymorphic_compare:Comparisons.Infixwithtypet:=t)letabs=absletneg=negletzero=zeroletof_int_exn=of_int_exnendmoduleO=structincludePre_OincludeInt_math.Make(structtypenonrect=tincludePre_Oletrem=remletto_float=to_floatletof_float=of_floatletof_string=T.of_stringletto_string=T.to_stringend)let(land)=bit_andlet(lor)=bit_orlet(lxor)=bit_xorletlnot=bit_notlet(lsl)=shift_leftlet(asr)=shift_rightlet(lsr)=shift_right_logicalendincludeO(* [Int64] and [Int64.O] agree value-wise *)(* Include type-specific [Replace_polymorphic_compare] at the end, after
including functor application that could shadow its definitions. This is
here so that efficient versions of the comparison functions are exported by
this module. *)includeInt64_replace_polymorphic_compare