ReductionTreeGenerator constructor

ReductionTreeGenerator(
  1. List<Logic> sequence,
  2. Logic operation(
    1. List<Logic> inputs, {
    2. Logic? control,
    3. int depth,
    4. String name,
    }), {
  3. int radix = 2,
  4. dynamic signExtend,
  5. int? depthBetweenFlops,
  6. Logic? control,
  7. Logic? clk,
  8. Logic? enable,
  9. Logic? reset,
})

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.
  • operation is the Function 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).
  • control is an optional Logic input that is passed along with the data being reduced and passed into the operation. Optional parameters to be used for creating a pipelined computation tree:
  • clk, reset, enable are optionally provided to allow for flopping.
  • depthBetweenFlops specifies how many nodes deep separate flops.

Implementation

ReductionTreeGenerator(
  this.sequence,
  this.operation, {
  this.radix = 2,
  dynamic signExtend,
  this.depthBetweenFlops,
  this.control,
  this.clk,
  this.enable,
  this.reset,
}) {
  if (sequence.isEmpty) {
    throw RohdHclException("Don't use ReductionTreeGenerator "
        'with an empty sequence');
  }
  if (radix < 2) {
    throw RohdHclException('Radix must be at least 2, got $radix');
  }
  signExtensionParameter = StaticOrRuntimeParameter.ofDynamic(signExtend);

  controlOut = control != null ? Logic(width: control!.width) : null;
  _computed = _reductionTreeRecurse(sequence);
  out = Logic(width: _computed.value.width);
  out <= _computed.value;
  if (controlOut != null) {
    controlOut! <= _computed.controlOut!;
  }
}