ReductionTree constructor
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 operation to be performed at each node. Note thatoperation
can widen the output. The logic function must support the operation for (2 toradix
) inputs.radix
is the width of reduction at each node in the tree (e.g., binary: radix=2).signExtend
iftrue
, use sign-extension to widen Logic values as needed in the tree, otherwise use zero-extension (default).control
is an optional 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
ReductionTree(List<Logic> sequence, this.operation,
{this.radix = 2,
dynamic signExtend,
this.depthBetweenFlops,
Logic? control,
Logic? clk,
Logic? enable,
Logic? reset,
super.name = 'reduction_tree',
super.reserveName,
super.reserveDefinitionName,
String? definitionName})
: super(
definitionName: definitionName ??
'ReductionTreeNode_R${radix}_L${sequence.length}') {
if (sequence.isEmpty) {
throw RohdHclException("Don't use ReductionTree "
'with an empty sequence');
}
if (radix < 2) {
throw RohdHclException('Radix must be at least 2, got $radix');
}
signExtensionParameter = StaticOrRuntimeParameter.ofDynamic(signExtend);
_sequence = [
for (var i = 0; i < sequence.length; i++)
addInput('seq$i', sequence[i], width: sequence[i].width)
];
_control = (control != null
? addInput('control', control, width: control.width)
: null);
_clk = (clk != null) ? addInput('clk', clk) : null;
_enable = (enable != null) ? addInput('enable', enable) : null;
_reset = (reset != null) ? addInput('reset', reset) : null;
_controlOut = (control != null
? addOutput('controlOut', width: control.width)
: null);
_buildLogic();
}