123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162open!ImportmoduletypeRound=sigmoduleB:sigtypetendtypetvalneg_infinity:tvalpos_infinity:tvalto_zero:tvalaway_from_zero:tvaltie_to_neg_infinity:tvaltie_to_pos_infinity:tvaltie_to_zero:tvaltie_away_from_zero:tvaltie_to_nearest_even:tvaltie_to_nearest_odd:tvalgeneric:B.t->tvaleval:t->int->B.t->B.tendmoduletypeOverflow=sigmoduleB:sigtypetendtypetvalwrap:tvalsaturate:tvaleval:t->int->int->B.t->B.tendmoduletypeFixed_point=sigmoduleB:sigtypetendtypet(** create a fixed point value. [mk f x] will have [f] fractional bits. [width x -
f] will be the number of integer bits *)valmk:int->B.t->t(** return the integer part of the value *)valint:t->B.t(** return the fractional part of the value *)valfrac:t->B.t(** return the underlying bits *)valsignal:t->B.t(** number of integer bits *)valwidth_int:t->int(** number of fractional bits *)valwidth_frac:t->int(** convert fixed point value to a float *)valto_float:t->float(** [select_int f x] extracts the integer part, and resizes it to x bits. Bits are
dropped from the msb down, if required. *)valselect_int:t->int->B.t(** [select_frac f x] extracts the fractional part, and resizes it to x bits. Bits
are dropped from the lsb up, if required. *)valselect_frac:t->int->B.t(** resizes a fixed type using select_int and select_frac *)valselect:t->int->int->t(** find largest integer and fractional parts in each fixed value, and resize all
elements to that size *)valnorm:tlist->tlist(** same as norm, but for 2 values *)valnorm2:t->t->t*t(** create a fixed value with the given number of integer and fractional bits from the
floating point value *)valconst:int->int->float->t(** adition *)val(+:):t->t->t(** subtraction *)val(-:):t->t->t(** multiplication *)val(*:):t->t->t(** equality *)val(==:):t->t->B.t(** inequality *)val(<>:):t->t->B.t(** less than *)val(<:):t->t->B.t(** less than or equal to *)val(<=:):t->t->B.t(** greater than *)val(>:):t->t->B.t(** greater than or equal to *)val(>=:):t->t->B.t(** multiplexor *)valmux:B.t->tlist->t(** [resize x i f] will resize the integer part to have [i] bits, and fractional part
to have [f] bits. Rounding and overflow control is applied *)valresize:t->int->int->tendmoduletypeFixed=sigmoduleMake(B:Comb.S):sigtypeunsignedtypesignedtype'aroundtype'aoverflow(** various different rounding modes *)moduletypeRound=RoundwithmoduleB:=B(** overflow control - wrap or saturate *)moduletypeOverflow=OverflowwithmoduleB:=B(** fixed point API *)moduletypeFixed=Fixed_pointwithmoduleB:=BmoduleUnsigned:sigmoduleRound:Roundwithtypet=unsignedroundmoduleOverflow:Overflowwithtypet=unsignedoverflowmoduletypeSpec=sigvalround:Round.tvaloverflow:Overflow.tendmoduleMake(S:Spec):FixedendmoduleSigned:sigmoduleRound:Roundwithtypet=signedroundmoduleOverflow:Overflowwithtypet=signedoverflowmoduletypeSpec=sigvalround:Round.tvaloverflow:Overflow.tendmoduleMake(S:Spec):Fixedendendend