CompressionTreeDotProduct constructor
- List<
Logic> multiplicands, - List<
Logic> multipliers, { - dynamic signedMultiplicand,
- dynamic signedMultiplier,
- int productRadix = 4,
- Adder adderGen(}) = NativeAdder.new,
- String adderIdentity = 'native',
- String name = 'compression_tree_dotproduct',
- bool reserveName = false,
- bool reserveDefinitionName = false,
- String? definitionName,
The productRadix parameter specifies the radix for use in
partial-product generation of the multiplies. While a ColumnCompressor
is used on the tall array of partial products, the final addition is
accomplished using the specified adderGen (default is
NativeAdder.new).
adderIdentity must stably identify the generated adder configuration so
automatic definition names remain unique when a custom adderGen is
used.
Implementation
CompressionTreeDotProduct(super.multiplicands, super.multipliers,
{super.signedMultiplicand,
super.signedMultiplier,
int productRadix = 4,
Adder Function(Logic a, Logic b, {Logic? carryIn}) adderGen =
NativeAdder.new,
String adderIdentity = 'native',
super.name = 'compression_tree_dotproduct',
super.reserveName = false,
super.reserveDefinitionName = false,
String? definitionName})
: super(
definitionName: definitionName ??
'CompressionTreeDotProduct_L${multipliers.length}_'
'A${multiplicands[0].width}_B${multipliers[0].width}_'
'R${productRadix}_Add${adderIdentity}_'
'${Multiplier.signedMD(signedMultiplicand)}_'
'${Multiplier.signedML(signedMultiplier)}') {
if (multiplicands.first.width != multipliers.first.width) {
throw RohdHclException(
'CompressionTreeDotProduct requires equal multiplicand and '
'multiplier widths.',
);
}
final ppGenerators = [
for (var i = 0; i < multipliers.length; i++)
PartialProductGenerator(
multiplicands[i], multipliers[i], RadixEncoder(productRadix),
signedMultiplicand: signedMultiplicandParameter.staticConfig,
signedMultiplier: signedMultiplierParameter.staticConfig,
selectSignedMultiplicand:
signedMultiplicandParameter.getRuntimeInput(this),
selectSignedMultiplier:
signedMultiplierParameter.getRuntimeInput(this))
];
for (final ppG in ppGenerators) {
StopBitsSignExtension(ppG).signExtend();
}
final ppg = ppGenerators.reduce((ppg, ppgNext) {
ppg.partialProducts.addAll(ppgNext.partialProducts);
ppg.rowShift.addAll(ppgNext.rowShift);
return ppg;
});
final vec = [
for (var row = 0; row < ppg.rows; row++)
ppg.partialProducts[row].rswizzle()
];
final columnCompressor = ColumnCompressor(vec, ppg.rowShift);
final adder = adderGen(columnCompressor.add0, columnCompressor.add1);
// An artifact of sign extension creates 2 extra bits in the sum.
final sum = adder.sum.slice(adder.sum.width - 3, 0);
addOutput('product', width: sum.width) <= sum;
}