Hardcaml_kernel.Clocked_signalSourceClocked_signal.t is similar to a Signal.t, but with clock domain info attached to it.
Information tracked by the signal.
One or more string names applied to a signal. These will be used during RTL code generation and simulation to aid design inspection.
Returns the list of names and locations assigned to the signal.
Set the given names on the signal. Wipes any names currently set.
Reset any names for global signals.
Attributes are attached to signals and written during RTL generation. They can be used to control downstream synthesis and place and route tools. They do not otherwise affect the Hardcaml circuit.
Add an attribute to node.
Returns attributes associated to the signal.
Set the format used to display the signal
A comment can be associated with a signal, and this is sometimes useful to pass information to downstream tooling (specifically Verilator).
Set the comment associated with the signal. This is currently only supported in Verilog.
Remove the comment associated with the signal. This is currently only supported in Verilog.
Attach a waiver for mux coverage. Raises if the signal is not a mux.
Attach a waiver for cases coverage. Raises if the signal is not a cases signal.
Attach a waiver for register coverage. Raises if the signal is not a register or it is an always state register.
Attach a state waiver to an always state register. Raises if the signal is not an always state register.
val add_always_state_transition_waiver_exn :
t ->
string Coverage_prim.Transition.t Coverage_prim.Waiver.t ->
tAttach as transition wavier to an always state register. Raises if the signal is not an always state register.
Specification of the module level input and output ports. Ports are represented in Hardcaml as wires with a single name. Note that Hardcaml will generally rewrite and legalize names depending on context but will not do so for ports.
Wires are used in Hardcaml to conenct two signals together. They are first created then assigned to (internally they have a mutable reference to their driver). Wires are how we can create cycles which we require in order to build logic like, for example, a counter.
It is entirely possible to create combinational loops using wires. Often this is not the intent and Hardcaml has functions to detect this - for example, Cyclesim will fail if there is such a loop.
The main combinational logic API for creating things like adders, multiplexers etc. This API is the same as provided by Bits.t.
By default Hardcaml performs constant propogation over signals - operations with purely constant values (and some other simple cases such as a &: vdd) will be simplified. You can avoid this by using the operations from the Unoptimized module.
Combinational logic API with constant propogation optimizations.
include Comb.S with type t := tinclude Base.Equal.S__local with type t := tcreate signal from a constant
Convert 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.
Convert non-negative values to constant. Input values which are not representable in width bits will raise.
Convert signed values to constant. Input values which are not representable in width bits will raise.
convert 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.
convert 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.
Convert an arbitrarily wide integer value to a constant.
convert 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
convert 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
names a signal
let a = a -- "a" in ...
signals may have multiple names.
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.
convert the signal to a constant
concat_msb ts concatenates a list of signals - the msb of the head of the list will become the msb of the result.
let c = concat_msb [ a; b; c ] in ...
concat_msb 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.
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.
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.
concatenate two signals.
let c = a @: b in ...
equivalent to concat [ a; b ]
select 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
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.
to_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.to_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.to_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.Convert 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.
Convert 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.
Convert 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.
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
fold 'op' though list
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_kernel__.Comb_intf.with_valid2 list ->
(t, t) Hardcaml_kernel__.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_kernel__.Comb_intf.with_valid2 list ->
default:t ->
tSame as priority_select except returns default if no case matches.
val onehot_select :
?branching_factor:int ->
(t, t) Hardcaml_kernel__.Comb_intf.with_valid2 list ->
tSelect 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.
binary_to_byte_qualifier ~num_bytes t returns a byte qualifier encoding of a binary size for use when encoding contiguous byte enables or byte keep signals.
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.
all_bits_set t returns vdd if all bits in t are set and gnd otherwise.
Concatention, selection and resizing functions for signals encoded as an option where None means zero width.
Unsigned vector operations (ie may operate on Bits.t or Signal.t directly).
Signed vector operations (ie may operate on Bits.t or Signal.t directly).
Combinational logic API without constant propogation optimizations.
Registers are configured using a Reg_spec.t. This encodes the clock, synchronous clear, and asychronous reset used.
Like reg_fb but returns both the registered value and the next cycle's value (i.e. the output of f prev_value). The next value ignores clear or reset if applied, i.e. if clear is applied, next will still be f prev_value rather than clear_to.
Pipeline a signal n times with the given register specification. If set, a list of RTL attributes will also be applied to each register created.
val cut_through_reg :
?initialize_to:Bits.t ->
?reset_to:Bits.t ->
?clear:t ->
?clear_to:t ->
Reg_spec.t ->
enable:t ->
t ->
tA register which forwards its input value to the output during cycles in which it is enabled.
Implemented as a register with a mux on the output. Note that the cut through bevahiour will also occur if enable is high during a clear (or even reset) operation.
Staged.unstage (prev spec ?enable d) returns a function prev n which provides d registered n times (ie the value of d n cycles in the past). n=0 means the current (combinational value).
The internal registers are shared between calls. When called multiple times with a maximum value of n exactly n registers are created.
val counter :
?enable:t ->
?initialize_to:Bits.t ->
?reset_to:Bits.t ->
?clear:t ->
?clear_to:t ->
?by:int ->
Reg_spec.t ->
width:int ->
tBasic counter. Adds by on each enabled cycle. Wraps on over/underflow.
multiport_memory provides the low-level primitive from which Hardcaml memories are created. It provides a memory with an arbitrary number of read and write ports that is asychronously read.
By default synthesizers will infer either LUT ram or register banks from this primitive.
Limiting the number of read/write ports and placing a register on the read address or read output port will allow synthesizers to infer single or simple dual port RAM from RTL. ram_rbw and ram_wbr are examples of this.
val multiport_memory :
?enable_modelling_features:bool ->
?verbose:bool ->
?name:string ->
?attributes:Rtl_attribute.t list ->
?initialize_to:Bits.t array ->
int ->
write_ports:t Write_port.t array ->
read_addresses:t array ->
t arraySynchronous write / asynchronous read memory. Supports an arbitrary number of read_addresses and write_ports. Placement of registers on the address or data output will allow synthesizers to infer RAMs from generated RTL (see also Ram.create which builds on this primitive to implement inferred memories).
Any provided attributes are applied to the memory array itself.
The memory may be initialized by providing initialize_to.
enable_modelling_features allows multibit enable and port scaling features. In both cases they will generate valid synthesizable RTL but backend tool inference is unlikely to work leading to sub-optimal designs.
In both cases extra read/write ports are generated and the internal RAM may be narrowed to support the feature.
For multibit enables the number of write enables must evenly divide the write data width or an exception will be raised.
For port scaling the read/write port ratio must be a power of two. It is specified by making the read and write address widths different and scaling the write data width appropriately. The size and initialize_to parameters are specified relative to the write port with the widest data bus.
A multi-read port asynchronous ROM built from a memory primitive. This can be used to map ROMs into RAM resources by registering the output.
val memory :
?attributes:Rtl_attribute.t list ->
int ->
write_port:t Write_port.t ->
read_address:t ->
tval ram_wbr :
?name:string ->
?attributes:Rtl_attribute.t list ->
write_port:t Write_port.t ->
read_port:t Read_port.t ->
int ->
tval ram_rbw :
?name:string ->
?attributes:Rtl_attribute.t list ->
write_port:t Write_port.t ->
read_port:t Read_port.t ->
int ->
tOperate on the underlying representation of the signal type. This is useful if you need to operate on the underlying Signal.Type that represents the Signal.S that you are working with or to reflect on the extra information attached to the specific Signal.S (like clock domains for Clocked.t).
Return the underlying representation for the signal.
Construct a signal from the underlying representation and the information tracked by this signal.
Pretty printer.
val validate_signals_are_consistent :
op_name:string ->
(string * t) list ->
Clock_domain.Runtime.tCheck if the provided signals are consistent where the definition of consistency is defined by the underlying signal type.
For the unclocked Signal.t, this does nothing.
For the clocked signal, this asserts that all the provided signals have the same runtime domain and return the domain, raises if they're not compatible. ~op_name will be shown in the error message reporting a clock domain mismatch.
The rules of runtime clock domain consistencies are:
The elaboration-time runtime clock domain of the signal.
val ensure_domain :
loc:lexing_position ->
?name:string ->
t ->
required_domain:Clock_domain.Runtime.t ->
tValidates that when required_domain is expected, dom t is able to satisfy that requirement.
required_domain is a constant, dom t have to be a constantrequired_domain is Exact x, dom t can be either Exact x or Constantrequired_domain is Unknown, this check will always fail.Return the base signal if the clocked representation has the given domain.
Creates a signal with the associated domain. Raises if the signal already has a domain attached to it.
Map over the base implementation, keeping the same info.
Defines functions that shadow the standard Signal construct functions and ensure that a domain is provided.