Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file fixed_intf.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163(** Fixed point arithmetic.
{[
(* select bits type *)
module F = Fixed.Make (Bits)
(* select Signed/Unsigned fixed type, and overflow and rounding mode. *)
module S = F.Signed.Make (struct
let round = F.Signed.Round.tie_to_nearest_even
let overflow = F.Signed.Overflow.saturate
end)
]} *)open!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:sigtypetendtypetvalmk:int->B.t->t(** create a fixed point value. [mk f x] will have [f] fractional bits. [width x -
f] will be the number of integer bits *)valint:t->B.t(** return the integer part of the value *)valfrac:t->B.t(** return the fractional part of the value *)valsignal:t->B.t(** return the underlying bits *)valwidth_int:t->int(** number of integer bits *)valwidth_frac:t->int(** number of fractional bits *)valto_float:t->float(** convert fixed point value to a float *)valselect_int:t->int->B.t(** [select_int f x] extracts the integer part, and resizes it to x bits. Bits are
dropped from the msb down, if required. *)valselect_frac: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:t->int->int->t(** resizes a fixed type using select_int and select_frac *)valnorm:tlist->tlist(** find largest integer and fractional parts in each fixed value, and resize all
elements to that size *)valnorm2:t->t->t*t(** same as norm, but for 2 values *)valconst:int->int->float->t(** create a fixed value with the given number of integer and fractional bits from the
floating point value *)val(+:):t->t->t(** adition *)val(-:):t->t->t(** subtraction *)val(*:):t->t->t(** multiplication *)val(==:):t->t->B.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 *)valmux:B.t->tlist->t(** multiplexor *)valresize:t->int->int->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 *)endmoduletypeFixed=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=unsignedround)moduleOverflow:(Overflowwithtypet=unsignedoverflow)moduletypeSpec=sigvalround:Round.tvaloverflow:Overflow.tendmoduleMake(S:Spec):FixedendmoduleSigned:sigmoduleRound:(Roundwithtypet=signedround)moduleOverflow:(Overflowwithtypet=signedoverflow)moduletypeSpec=sigvalround:Round.tvaloverflow:Overflow.tendmoduleMake(S:Spec):Fixedendendend