Hardcaml_verify_kernel.Comb_gatesHardcaml combinational logic API using lists of Basic_gate.ts.
include Hardcaml.Comb.S with type t = Basic_gates.t Base.listtype t = Basic_gates.t Base.listval sexp_of_t : t -> Sexplib0.Sexp.tinclude Base.Equal.S__local with type t := tval equal : t Base.Equal.equalval vdd : tlogic 1
val gnd : tlogic 0
val of_constant : Hardcaml.Constant.t -> tcreate signal from a constant
val of_bit_string : string -> tconvert binary string to constant
val of_int_trunc : width:int -> int -> tConvert integer to constant. Negative values are sign extended up to width. Input values which are larger or smaller than those representable in width bits are truncated.
val of_int32_trunc : width:int -> int32 -> tval of_int64_trunc : width:int -> int64 -> tval of_int : width:int -> int -> tSame as of_int_trunc
val of_int32 : width:int -> int32 -> tval of_int64 : width:int -> int64 -> tval of_unsigned_int : width:int -> int -> tConvert non-negative values to constant. Input values which are not representable in width bits will raise.
val of_unsigned_int32 : width:int -> int32 -> tval of_unsigned_int64 : width:int -> int64 -> tval of_signed_int : width:int -> int -> tConvert signed values to constant. Input values which are not representable in width bits will raise.
val of_signed_int32 : width:int -> int32 -> tval of_signed_int64 : width:int -> int64 -> tval of_hex : ?signedness:Hardcaml.Signedness.t -> width:int -> string -> tconvert hex string to a constant. If the target width is greater than the hex length and signedness is Signed then the result is sign extended. Otherwise the result is zero padded.
val of_octal : ?signedness:Hardcaml.Signedness.t -> width:int -> string -> tconvert octal string to a constant. If the target width is greater than the octal length and signedness is Signed then the result is sign extended. Otherwise the result is zero padded.
val of_string : string -> tconvert verilog style or binary string to constant
val of_bit_list : int list -> tconvert IntbitsList to constant
val of_decimal_string : width:int -> string -> tval of_char : char -> tconvert a char to an 8 bit constant
val of_bool : bool -> tconvert a bool to vdd or gnd
val of_ascii_string_lsb : string -> tconvert a string to a series of 8-bit characters and concatenate them into a signal, with the first character of the string being in the least-significant bits
val of_ascii_string_msb : string -> tconvert a string to a series of 8-bit characters and concatenate them into a signal, with the first character of the string being in the most-significant bits
val random : width:int -> tcreate random constant vector of given width
val zero : int -> tzero w makes a the zero valued constant of width w
val ones : int -> tones w makes a constant of all ones of width w
val one : int -> tone w makes a one valued constant of width w
val empty : tthe empty signal
val is_empty : t -> boolreturns true if the signal is empty
names a signal
let a = a -- "a" in ...
signals may have multiple names.
val width : t -> intreturns the width (number of bits) of a signal.
let w = width s in ...
addess_bits_for num_elements returns the address width required to index num_elements.
It is the same as Int.ceil_log2, except it wll return a minimum value of 1 (since you cannot have 0 width vectors). Raises if num_elements is < 0.
num_bits_to_represent x returns the number of bits required to represent the number x, which should be >= 0.
val to_constant : t -> Hardcaml.Constant.tconvert the signal to a constant
concat ts concatenates a list of signals - the msb of the head of the list will become the msb of the result.
let c = concat [ a; b; c ] in ...
concat raises if ts is empty or if any t in ts is empty.
Similar to concat_msb except the lsb of the head of the list will become the lsb of the result.
val is_vdd : t -> boolval is_gnd : t -> boolselect t ~high ~low selects from t bits in the range high...low, inclusive. select raises unless high and low fall within 0 .. width t - 1 and high >= lo.
x.:+[lo, width] == select x (lo + width - 1) lo. If width is None it selects all remaining msbs of the vector ie x.:+[lo,None] == drop_bottom x lo
x.:-[hi, width] == select x hi (hi - width + 1). If hi is None it defaults to the msb of the vector ie x.:-[None, width] == sel_top x width
insert ~into:t x ~at_offset insert x into t at given offet
multiplexer.
let m = mux sel inputs in ...
Given l = List.length inputs and w = width sel the following conditions must hold:
l <= Int.pow 2 w, l >= 1
If l < Int.pow 2 w, the last input is repeated.
All inputs provided must have the same width, which will in turn be equal to the width of m.
mux2 c t f 2 input multiplexer. Selects t if c is high otherwise f.
t and f must have same width and c must be 1 bit.
Equivalent to mux c [f; t]
cases ~default select [(match0, value0); (match0, value0)...] compares select with matchN and outputs valueN. If nothing matches default is output. This construct maps to a case statement.
The matchN values must be constants.
val to_string : t -> stringcreate string from signal
val to_int_trunc : t -> intto_int t treats t as unsigned and resizes it to fit exactly within an OCaml Int.t.
width t > Int.num_bits then the upper bits are truncated.width t >= Int.num_bits and bit t (Int.num_bits-1) = vdd (i.e. the msb of the resulting Int.t is set), then the result is negative.t is Signal.t and not a constant value, an exception is raised.val to_int32_trunc : t -> int32val to_int64_trunc : t -> int64val to_int : t -> intSame as to_int_trunc.
val to_int32 : t -> int32val to_int64 : t -> int64val to_signed_int : t -> intto_signed_int t treats t as signed and resizes it to fit exactly within an OCaml Int.t.
t is Signal.t and not a constant value, an exception is raised.val to_signed_int32 : t -> int32val to_signed_int64 : t -> int64val to_unsigned_int : t -> intto_unsigned_int t treats t as unsigned and resizes it to fit exactly within an OCaml Int.t.
int value must be unsigned (so the max width is Int.num_bits - 1).t is Signal.t and not a constant value, an exception is raised.val to_unsigned_int32 : t -> int32val to_unsigned_int64 : t -> int64val to_bool : t -> boolConvert signal to a bool. The signal must be 1 bit wide.
val to_char : t -> charConvert signal to a char. The signal must be 8 bits wide.
val to_ascii_string_lsb : t -> stringConvert into a string, with the first character being from the least-significant bits of the signal. The signal width must be a multiple of 8 bits.
val to_ascii_string_msb : t -> stringConvert into a string, with the first character being from the most-significant bits of the signal. The signal width must be a multiple of 8 bits.
val to_bstr : t -> stringcreate binary string from signal
val to_bigint : t -> signedness:Hardcaml.Signedness.t -> Bigint.tConvert bits to a Zarith.t
Split signal in half. The most significant bits will be in the left half of the returned tuple.
msbs is not provided, the signal will be split in half with the MSB part possibly containing one more bit.msbs is provided, msbs most significant bits will be split off.Same as split_in_half_msb, but
lsbs is not provided, the LSB part might have one more bit.lsbs is provided, lsbs least significant bits will be split off.The most significant bits will still be in the left half of the tuple.
Split signal into a list of signals with width equal to part_width. The least significant bits are at the head of the returned list. If exact is true the input signal width must be exactly divisable by part_width. When exact is false and the input signal width is not exactly divisible by part_width, the last element will contains residual bits.
eg:
split_lsb ~part_width:4 16b0001_0010_0011_0100 =
[ 4b0100; 4b0011; 4b0010; 4b0001 ]
split_lsb ~exact:false ~part_width:4 17b11_0001_0010_0011_0100 =
[ 4b0100; 4b0011; 4b0010; 4b0001; 2b11 ]Like split_lsb except the most significant bits are at the head of the returned list. Residual bits when exact is false goes to the last element of the list, so in the general case split_lsb is not necessarily equivalent to split_msb |> List.rev.
uresize t ~width:w returns the unsigned resize of t to width w. If w = width t, this is a no-op. If w < width t, this selects the w low bits of t. If w > width t, this extends t with zero (w - width t).
sresize t ~width:w returns the signed resize of t to width w. If w = width t, this is a no-op. If w < width t, this selects the w low bits of t. If w > width t, this extends t with w - width t copies of msb t.
uextend t ~width:w behaves similarly to uresize t ~width:w but asserts that w >= width to prevent inadvertently chopping the signal.
sextend t ~width:w behaves similarly to sresize t ~width:w but asserts that w >= width to prevent inadvertently chopping the signal.
resize_list ~resize l finds the maximum width in l and applies resize el max to each element.
resize_op2 ~resize f a b applies resize x w to a and b where w is the maximum of their widths. It then returns f a b
mod_counter max t is if t = max then 0 else (t + 1), and can be used to count from 0 to max then from zero again. If max == (1<<n - 1), then a comparator is not generated and overflow arithmetic is used instead.
compute_arity ~steps num_values computes the tree arity required to reduce num_values in steps. steps<=0 raises.
compute_tree_branches ~steps num_values returns a list of length steps of branching factors required to reduce num_values. This tends to produce a slightly more balanced sequence than just applying compute_arity at every step.
tree ~arity ~f input creates a tree of operations. The arity of the operator is configurable. tree raises if input = [].
val priority_select :
?branching_factor:int ->
(t, t) Hardcaml__.Comb_intf.with_valid2 list ->
(t, t) Hardcaml__.Comb_intf.with_valid2priority_select cases returns the value associated with the first case whose valid signal is high. valid will be set low in the returned with_valid if no case is selected.
val priority_select_with_default :
?branching_factor:int ->
(t, t) Hardcaml__.Comb_intf.with_valid2 list ->
default:t ->
tSame as priority_select except returns default if no case matches.
Select a case where one and only one valid signal is enabled. If more than one case is valid then the return value is undefined. If no cases are valid, 0 is returned by the current implementation, though this should not be relied upon.
is_pow2 t returns a bit to indicate if t is a power of 2.
leading_ones t returns the number of consecutive 1s from the most significant bit of t down.
trailing_ones t returns the number of consecutive 1s from the least significant bit of t up.
leading_zeros t returns the number of consecutive 0s from the most significant bit of t down.
trailing_zeros t returns the number of consecutive 0s from the least significant bit of t up.
floor_log2 x returns the floor of log-base-2 of x. x is treated as unsigned and an error is indicated by valid = gnd in the return value if x = 0.
ceil_log2 x returns the ceiling of log-base-2 of x. x is treated as unsigned and an error is indicated by valid = gnd in the return value if x = 0.
Increment a gray code value. The implementation converts to binary, increments the binary value, then converts back to gray code.
any_bit_set t returns vdd if at least one bit if set in t and gnd otherwise.
module With_zero_width : sig ... endConcatention, selection and resizing functions for signals encoded as an option where None means zero width.
module type Typed_math = sig ... endmodule Unsigned : Typed_mathUnsigned vector operations (ie may operate on Bits.t or Signal.t directly).
module Signed : Typed_mathSigned vector operations (ie may operate on Bits.t or Signal.t directly).
val input : Base.string -> Base.int -> tinput "name" width creates an input with "name" and given width in bits.
cofactor ~var p ~f computes the cofactor of each bit of f wrt to each bit of var. p must be a constant and represents the value of var which which to perform the cofactor.