Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file nativeint.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314open!Importopen!Caml.NativeintincludeNativeint_replace_polymorphic_comparemoduleT=structtypet=nativeint[@@deriving_inlinehash,sexp,sexp_grammar]let(hash_fold_t:Ppx_hash_lib.Std.Hash.state->t->Ppx_hash_lib.Std.Hash.state)=hash_fold_nativeintand(hash:t->Ppx_hash_lib.Std.Hash.hash_value)=letfunc=hash_nativeintinfunx->funcx;;lett_of_sexp=(nativeint_of_sexp:Ppx_sexp_conv_lib.Sexp.t->t)letsexp_of_t=(sexp_of_nativeint: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=["nativeint"];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=[nativeint_sexp_grammar];generic_group=_the_generic_group;origin="nativeint.ml.T"}inlet(t_sexp_grammar:Ppx_sexp_conv_lib.Sexp.Private.Raw_grammar.t)=Ref("t",_the_group)int_sexp_grammar;;[@@@end]letcompare=Nativeint_replace_polymorphic_compare.compareletto_string=to_stringletof_string=of_stringendincludeTincludeComparator.Make(T)includeComparable.Validate_with_zero(structincludeTletzero=zeroend)moduleConv=Int_conversionsincludeConv.Make(T)includeConv.Make_hex(structopenNativeint_replace_polymorphic_comparetypet=nativeint[@@deriving_inlinecompare,hash]letcompare=(compare_nativeint:t->t->int)let(hash_fold_t:Ppx_hash_lib.Std.Hash.state->t->Ppx_hash_lib.Std.Hash.state)=hash_fold_nativeintand(hash:t->Ppx_hash_lib.Std.Hash.hash_value)=letfunc=hash_nativeintinfunx->funcx;;[@@@end]letzero=zeroletneg=neglet(<)=(<)letto_stringi=Printf.sprintf"%nx"iletof_strings=Caml.Scanf.sscanfs"%nx"Fn.idletmodule_name="Base.Nativeint.Hex"end)includePretty_printer.Register(structtypenonrect=tletto_string=to_stringletmodule_name="Base.Nativeint"end)(* 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. *)open!Nativeint_replace_polymorphic_compareletinvariant(_:t)=()letnum_bits=Word_size.num_bitsWord_size.word_sizeletfloat_lower_bound=Float0.lower_bound_for_intnum_bitsletfloat_upper_bound=Float0.upper_bound_for_intnum_bitsletshift_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=succletrem=remletneg=negletminus_one=minus_oneletone=oneletzero=zeroletto_float=to_floatletof_float_unchecked=of_floatletof_floatf=ifFloat_replace_polymorphic_compare.(>=)ffloat_lower_bound&&Float_replace_polymorphic_compare.(<=)ffloat_upper_boundthenof_floatfelsePrintf.invalid_argf"Nativeint.of_float: argument (%f) is out of range or NaN"(Float0.boxf)();;modulePow2=structopen!ImportopenNativeint_replace_polymorphic_comparemoduleSys=Sys0letraise_s=Error.raise_sletnon_positive_argument()=Printf.invalid_argf"argument must be strictly positive"();;let(lor)=Caml.Nativeint.logorlet(lsr)=Caml.Nativeint.shift_right_logicallet(land)=Caml.Nativeint.logand(** "ceiling power of 2" - Least power of 2 greater than or equal to x. *)letceil_pow2(x:nativeint)=ifx<=0nthennon_positive_argument();letx=Caml.Nativeint.predxinletx=xlor(xlsr1)inletx=xlor(xlsr2)inletx=xlor(xlsr4)inletx=xlor(xlsr8)inletx=xlor(xlsr16)in(* The next line is superfluous on 32-bit architectures, but it's faster to do it
anyway than to branch *)letx=xlor(xlsr32)inCaml.Nativeint.succx;;(** "floor power of 2" - Largest power of 2 less than or equal to x. *)letfloor_pow2x=ifx<=0nthennon_positive_argument();letx=xlor(xlsr1)inletx=xlor(xlsr2)inletx=xlor(xlsr4)inletx=xlor(xlsr8)inletx=xlor(xlsr16)inletx=xlor(xlsr32)inCaml.Nativeint.subx(xlsr1);;letis_pow2x=ifx<=0nthennon_positive_argument();xlandCaml.Nativeint.predx=0n;;(* C stubs for nativeint clz and ctz to use the CLZ/BSR/CTZ/BSF instruction where possible *)externalclz:(nativeint[@unboxed])->(int[@untagged])="Base_int_math_nativeint_clz""Base_int_math_nativeint_clz_unboxed"[@@noalloc]externalctz:(nativeint[@unboxed])->(int[@untagged])="Base_int_math_nativeint_ctz""Base_int_math_nativeint_ctz_unboxed"[@@noalloc](** Hacker's Delight Second Edition p106 *)letfloor_log2i=ifPoly.(<=)iCaml.Nativeint.zerothenraise_s(Sexp.message"[Nativeint.floor_log2] got invalid input"["",sexp_of_nativeinti]);num_bits-1-clzi;;(** Hacker's Delight Second Edition p106 *)letceil_log2i=ifPoly.(<=)iCaml.Nativeint.zerothenraise_s(Sexp.message"[Nativeint.ceil_log2] got invalid input"["",sexp_of_nativeinti]);ifCaml.Nativeint.equaliCaml.Nativeint.onethen0elsenum_bits-clz(Caml.Nativeint.predi);;endincludePow2letbetweent~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_nativeintt=tletof_nativeint_exn=of_nativeintletto_nativeintt=tletto_nativeint_exn=to_nativeintletpopcount=Popcount.nativeint_popcountletof_int=Conv.int_to_nativeintletof_int_exn=of_intletto_int=Conv.nativeint_to_intletto_int_exn=Conv.nativeint_to_int_exnletto_int_trunc=Conv.nativeint_to_int_truncletof_int32=Conv.int32_to_nativeintletof_int32_exn=of_int32letto_int32=Conv.nativeint_to_int32letto_int32_exn=Conv.nativeint_to_int32_exnletto_int32_trunc=Conv.nativeint_to_int32_truncletof_int64=Conv.int64_to_nativeintletof_int64_exn=Conv.int64_to_nativeint_exnletof_int64_trunc=Conv.int64_to_nativeint_truncletto_int64=Conv.nativeint_to_int64letpowbe=of_int_exn(Int_math.Private.int_pow(to_int_exnb)(to_int_exne))let(**)be=powbemodulePre_O=structlet(+)=(+)let(-)=(-)let(*)=(*)let(/)=(/)let(~-)=(~-)let(**)=(**)include(Nativeint_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(* [Nativeint] and [Nativeint.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. *)includeNativeint_replace_polymorphic_compareexternalbswap:t->t="%bswap_native"