ReductionTree constructor

ReductionTree(
  1. List<Logic> sequence,
  2. Logic operation(
    1. List<Logic> inputs, {
    2. String name,
    }), {
  3. int radix = 2,
  4. bool signExtend = false,
  5. int? depthToFlop,
  6. Logic? clk,
  7. Logic? enable,
  8. Logic? reset,
  9. String name = 'reduction_tree',
})

Generate a tree based on dividing the input sequence of a node into segments, recursively constructing radix child nodes to operate on each segment.

  • sequence is the input sequence to be reduced using the tree of operations.
  • Logic Function(List inputs, {String name}) operation is the operation to be performed at each node. Note that operation can widen the output. The logic function must support the operation for 2 to radix inputs.
  • radix is the width of reduction at each node in the tree (e.g., binary: radix=2).
  • signExtend if true, use sign-extension to widen Logic values as needed in the tree, otherwise use zero-extension (default).

Optional parameters to be used for creating a pipelined computation tree:

  • clk, reset, enable are optionally provided to allow for flopping.
  • depthToFlop specifies how many nodes deep separate flops.

Implementation

ReductionTree(List<Logic> sequence, this.operation,
    {this.radix = 2,
    this.signExtend = false,
    this.depthToFlop,
    Logic? clk,
    Logic? enable,
    Logic? reset,
    super.name = 'reduction_tree'})
    : super(definitionName: 'ReductionTree_R${radix}_L${sequence.length}}') {
  if (sequence.isEmpty) {
    throw RohdHclException("Don't use ReductionTree "
        'with an empty sequence');
  }
  sequence = [
    for (var i = 0; i < sequence.length; i++)
      addInput('seq$i', sequence[i], width: sequence[i].width)
  ];
  this.clk = (clk != null) ? addInput('clk', clk) : null;
  this.enable = (enable != null) ? addInput('enable', enable) : null;
  this.reset = (reset != null) ? addInput('reset', reset) : null;

  _computed = reductionTreeRecurse(sequence);
  addOutput('out', width: _computed.value.width) <= _computed.value;
}