veryl icon indicating copy to clipboard operation
veryl copied to clipboard

Flag Wrapper Feature

Open nblei opened this issue 11 months ago • 0 comments

Consider the common use case where the value carried on a bus is only relevant if a flag is set.

For example, the value of wdata to a memory is only relevant if the write signal is set.

I propose a new built-in polymorphic type: enable with constructors set<T> and unset.

For example:

module bytereg (
  i_clk: input logic,
  i_wdata: input enable<logic<8>>,
  o_rdata: output logic<8>
) {
  var r: logic<8>;
  always_ff (i_clk) {
    if let set(x) = i_wdata {
      r = x;
    }
  }
}

This can be seen as a hardware analog of Option<T>. But, as hardware has both active-high and active-low flag values, we should also provide a two parameter type: enable<b: logic, T> where b gives the polarity of the enable flag. Thus, enable<T> is simply syntactic sugar for enable<1'b1, T>.

nblei avatar Mar 09 '24 19:03 nblei