GeneralDotProduct constructor

GeneralDotProduct(
  1. List<Logic> multiplicands,
  2. List<Logic> multipliers, {
  3. dynamic signedMultiplicand,
  4. dynamic signedMultiplier,
  5. int treeRadix = 2,
  6. String multiplierIdentity = 'native',
  7. String adderIdentity = 'native',
  8. Adder adderGen(
    1. Logic a,
    2. Logic b, {
    3. Logic? carryIn,
    4. String name,
    }) = NativeAdder.new,
  9. Multiplier multiplierGen(
    1. Logic a,
    2. Logic b, {
    3. Logic? clk,
    4. Logic? enable,
    5. Logic? reset,
    6. dynamic signedMultiplicand,
    7. dynamic signedMultiplier,
    }) = NativeMultiplier.new,
  10. String name = 'dotproduct',
  11. bool reserveName = false,
  12. bool reserveDefinitionName = false,
  13. String? definitionName,
})

Construct a GeneralDotProduct with a List of multiplicands and multipliers, a multiplierGen for constructing products, and an adderGen function to generate Adders for use in a ReductionTree for the final addition of the products.

multiplierIdentity and adderIdentity must stably identify the generated multiplier and adder configurations so automatic definition names remain unique when custom generators are used.

Implementation

GeneralDotProduct(super.multiplicands, super.multipliers,
    {super.signedMultiplicand,
    super.signedMultiplier,
    int treeRadix = 2,
    String multiplierIdentity = 'native',
    String adderIdentity = 'native',
    this.adderGen = NativeAdder.new,
    Multiplier Function(Logic a, Logic b,
            {Logic? clk,
            Logic? reset,
            Logic? enable,
            dynamic signedMultiplicand,
            dynamic signedMultiplier})
        multiplierGen = NativeMultiplier.new,
    super.name = 'dotproduct',
    super.reserveName = false,
    super.reserveDefinitionName = false,
    String? definitionName})
    : super(
          definitionName: definitionName ??
              'GeneralDotProduct_L${multipliers.length}_'
                  'A${multiplicands[0].width}_B${multipliers[0].width}_'
                  'R${treeRadix}_${multiplierIdentity}_'
                  'Add${adderIdentity}_'
                  '${Multiplier.signedMD(signedMultiplicand)}_'
                  '${Multiplier.signedML(signedMultiplier)}') {
  final hasRuntimeSign = signedMultiplicandParameter.runtimeConfig != null ||
      signedMultiplierParameter.runtimeConfig != null;
  _signedProduct = !hasRuntimeSign &&
      (signedMultiplicandParameter.staticConfig ||
          signedMultiplierParameter.staticConfig);
  _selectSignedProduct = hasRuntimeSign
      ? signedMultiplicandParameter.getLogic(this) |
          signedMultiplierParameter.getLogic(this)
      : null;

  final dotResults = [
    for (var i = 0; i < multipliers.length; i++)
      multiplierGen(multiplicands[i], multipliers[i],
              signedMultiplicand: signedMultiplicandParameter.isRuntime
                  ? signedMultiplicandParameter.getRuntimeInput(this)
                  : signedMultiplicandParameter.staticConfig,
              signedMultiplier: signedMultiplierParameter.isRuntime
                  ? signedMultiplierParameter.getRuntimeInput(this)
                  : signedMultiplierParameter.staticConfig)
          .product
  ];

  final prefixAdd = ReductionTreeGenerator(
    dotResults,
    addReduceAdders,
    signExtend: _selectSignedProduct ?? _signedProduct,
    control: _selectSignedProduct,
    radix: treeRadix,
  );
  addOutput('product', width: prefixAdd.out.width) <= prefixAdd.out;
}