123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100(**************************************************************************)(* *)(* 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. *)(* *)(**************************************************************************)(* Module [Nativeint]: processor-native integers *)externalneg:nativeint->nativeint="%nativeint_neg"externaladd:nativeint->nativeint->nativeint="%nativeint_add"externalsub:nativeint->nativeint->nativeint="%nativeint_sub"externalmul:nativeint->nativeint->nativeint="%nativeint_mul"externaldiv:nativeint->nativeint->nativeint="%nativeint_div"externalrem:nativeint->nativeint->nativeint="%nativeint_mod"externallogand:nativeint->nativeint->nativeint="%nativeint_and"externallogor:nativeint->nativeint->nativeint="%nativeint_or"externallogxor:nativeint->nativeint->nativeint="%nativeint_xor"externalshift_left:nativeint->int->nativeint="%nativeint_lsl"externalshift_right:nativeint->int->nativeint="%nativeint_asr"externalshift_right_logical:nativeint->int->nativeint="%nativeint_lsr"externalof_int:int->nativeint="%nativeint_of_int"externalto_int:nativeint->int="%nativeint_to_int"externalof_float:float->nativeint="caml_nativeint_of_float""caml_nativeint_of_float_unboxed"[@@unboxed][@@noalloc]externalto_float:nativeint->float="caml_nativeint_to_float""caml_nativeint_to_float_unboxed"[@@unboxed][@@noalloc]externalof_int32:int32->nativeint="%nativeint_of_int32"externalto_int32:nativeint->int32="%nativeint_to_int32"letzero=0nletone=1nletminus_one=-1nletsuccn=addn1nletpredn=subn1nletabsn=ifn>=0nthennelsenegnletsize=Sys.word_sizeletmin_int=shift_left1n(size-1)letmax_int=submin_int1nletlognotn=logxorn(-1n)letunsigned_to_int=letmax_int=of_intStdlib.max_intinfunn->ifn>=0n&&n<=max_intthenSome(to_intn)elseNoneexternalformat:string->nativeint->string="caml_nativeint_format"letto_stringn=format"%d"nexternalof_string:string->nativeint="caml_nativeint_of_string"letof_string_opts=trySome(of_strings)withFailure_->Nonetypet=nativeintletcompare(x:t)(y:t)=Stdlib.comparexyletequal(x:t)(y:t)=comparexy=0letunsigned_comparenm=compare(subnmin_int)(submmin_int)letunsigned_ltnm=subnmin_int<submmin_intletminxy:t=ifx<=ythenxelseyletmaxxy: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.
*)letunsigned_divnd=ifd<zerothenifunsigned_ltndthenzeroelseoneelseletq=shift_left(div(shift_right_logicaln1)d)1inletr=subn(mulqd)inifunsigned_ltrdthenqelsesuccqletunsigned_remnd=subn(mul(unsigned_divnd)d)externalseeded_hash_param:int->int->int->'a->int="caml_hash"[@@noalloc]letseeded_hashseedx=seeded_hash_param10100seedxlethashx=seeded_hash_param101000x