123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687(**************************************************************************)(* *)(* OCaml *)(* *)(* The OCaml programmers *)(* Jacob Van Buren, Jane Street, New York *)(* *)(* Copyright 2018 Institut National de Recherche en Informatique et *)(* en Automatique. *)(* Copyright 2025 Jane Street Group LLC *)(* *)(* 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. *)(* *)(**************************************************************************)[@@@ocaml.flambda_o3]open!Stdlibtypet=intletsize=Sys.int_sizeexternal(<):int->int->bool@@portable="%int_lessthan"letzero=0letone=1letminus_one=-1externalto_int:int->int@@portable="%identity"externalof_int:int->int@@portable="%identity"externalneg:int->int@@portable="%int_neg"externaladd:int->int->int@@portable="%int_add"externalsub:int->int->int@@portable="%int_sub"externalmul:int->int->int@@portable="%int_mul"externaldiv:int->int->int@@portable="%int_div"externalrem:int->int->int@@portable="%int_mod"externalsucc:int->int@@portable="%int_succ"externalpred:int->int@@portable="%int_pred"externallogand:int->int->int@@portable="%int_and"externallogor:int->int->int@@portable="%int_or"externallogxor:int->int->int@@portable="%int_xor"let[@inline]lognotx=logxorxminus_oneexternalshift_left:int->int->int@@portable="%int_lsl"externalshift_right:int->int->int@@portable="%int_asr"externalshift_right_logical:int->int->int@@portable="%int_lsr"let[@inline]absx=ifx<zerothennegxelsexexternalequal:int->int->bool@@portable="%int_equal"externalcompare:int->int->int@@portable="%int_compare"let[@inline]minxy=ifx<ythenxelseylet[@inline]maxxy=ifx<ythenyelsexexternalof_float:float->int@@portable="%int_of_float"externalto_float:int->float@@portable="%float_of_int"externalformat_int:string->int->string@@portable="caml_format_int"let[@inline]to_stringt=format_int"%d"texternalof_string:string->int@@portable="caml_int_of_string"letmax_int=shift_right_logicalminus_one1letmin_int=succmax_intlet[@inline]unsigned_to_intt=ift<0thenNoneelseSometexternalunsigned_compare:int->int->int@@portable="%int_unsigned_compare"externalunsigned_lt:int->int->bool@@portable="%int_unsigned_lessthan"(* Unsigned division from signed division of the same bitness. See Warren Jr.,
Henry S. (2013). Hacker's Delight (2 ed.), Sec 9-3. *)let[@inline]unsigned_divnd=ifd<zerothenifunsigned_ltndthenzeroelseoneelseletq=shift_left(div(shift_right_logicaln1)d)1inletr=subn(mulqd)inifunsigned_ltrdthenqelsesuccqlet[@inline]unsigned_remnd=subn(mul(unsigned_divnd)d)letseeded_hashseedt=Stdlib.Hashtbl.seeded_hashseedtlethasht=Stdlib.Hashtbl.hasht