CompressionTreeDotProduct constructor

CompressionTreeDotProduct(
  1. List<Logic> multiplicands,
  2. List<Logic> multipliers, {
  3. dynamic signedMultiplicand,
  4. dynamic signedMultiplier,
  5. int productRadix = 4,
  6. Adder adderGen(
    1. Logic a,
    2. Logic b, {
    3. Logic? carryIn,
    }) = NativeAdder.new,
  7. String name = 'compression_tree_dotproduct',
  8. bool reserveName = false,
  9. bool reserveDefinitionName = false,
  10. 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).

Implementation

CompressionTreeDotProduct(super.multiplicands, super.multipliers,
    {super.signedMultiplicand,
    super.signedMultiplier,
    int productRadix = 4,
    Adder Function(Logic a, Logic b, {Logic? carryIn}) adderGen =
        NativeAdder.new,
    super.name = 'compression_tree_dotproduct',
    super.reserveName = false,
    super.reserveDefinitionName = false,
    String? definitionName})
    : super(
          definitionName: definitionName ??
              'CompTreeDotProduct_W${multipliers[0].width}_') {
  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;
}