MultiplyAccumulate constructor

MultiplyAccumulate(
  1. Logic a,
  2. Logic b,
  3. Logic c, {
  4. Logic? clk,
  5. Logic? reset,
  6. Logic? enable,
  7. dynamic signedMultiplicand,
  8. dynamic signedMultiplier,
  9. dynamic signedAddend,
  10. int? outputWidth,
  11. String name = 'multiply_accumulate',
  12. bool reserveName = false,
  13. bool reserveDefinitionName = false,
  14. String? definitionName,
})

Take input a and input b, compute their product, add input c to produce the accumulate result.

The optional signedMultiplicand parameter configures the The optional signedMultiplicand parameter configures the multiplicand a statically using a bool as a signed multiplicand (default is false, or unsigned) or dynamically with a 1-bit Logic selectSignedMultiplicand input. You can pass either a bool (for static configuration) or a Logic (dynamically configuring the type handled) with a signal to this parameter, otherwise this constructor will throw.

The optional signedMultiplier parameter configures the multiplier b statically using a bool as a signed multiplier (default is false, or unsigned) or dynamically with a 1-bit Logic selectSignedMultiplier input. You can pass either a bool (for static configuration) or a Logic (dynamically configuring the type handled with a signal) to this parameter, otherwise this constructor will throw.

The optional signedAddend parameter configures the addend c as a signed addend (default is unsigned) or with a runtime configurable selectSignedAddend input.

The optional signedAddend parameter configures the multiplicand c statically using a bool as a signed multiplicand (default is false, or unsigned) or dynamically with a 1-bit Logic selectSignedAddend input. You can pass either a bool(for static configuration) or a Logic (dynamically configuring the type handled) with a signal to this parameter, otherwise this constructor will throw.

The optional outputWidth parameter configures the width of accumulate. If not provided, accumulate is the natural full-precision width a.width + b.width + 1. If outputWidth is narrower, the natural result is truncated to the low outputWidth bits. If outputWidth is wider, the natural result is sign- or zero-extended based on isAccumulateSigned.

Implementation

MultiplyAccumulate(Logic a, Logic b, Logic c,
    {Logic? clk,
    Logic? reset,
    Logic? enable,
    dynamic signedMultiplicand,
    dynamic signedMultiplier,
    dynamic signedAddend,
    int? outputWidth,
    super.name = 'multiply_accumulate',
    super.reserveName,
    super.reserveDefinitionName,
    String? definitionName})
    : super(
          definitionName: definitionName ??
              'MultiplyAccumulate_W${a.width}x${b.width}_'
                  'Acc${c.width}_Out'
                  '${outputWidth ?? (a.width + b.width + 1)}') {
  if (outputWidth != null && outputWidth <= 0) {
    throw RohdHclException(
        'outputWidth must be positive when provided, got $outputWidth.');
  }

  this.clk = (clk != null) ? addInput('clk', clk) : null;
  this.reset = (reset != null) ? addInput('reset', reset) : null;
  this.enable = (enable != null) ? addInput('enable', enable) : null;
  a = addInput('a', a, width: a.width);
  b = addInput('b', b, width: b.width);
  c = addInput('c', c, width: c.width);

  signedMultiplicandParameter =
      StaticOrRuntimeParameter.ofDynamic(signedMultiplicand);
  this.signedMultiplicand = signedMultiplicandParameter.staticConfig;
  signedMultiplierParameter =
      StaticOrRuntimeParameter.ofDynamic(signedMultiplier);
  this.signedMultiplier = signedMultiplierParameter.staticConfig;
  signedAddendParameter = StaticOrRuntimeParameter.ofDynamic(signedAddend);
  this.signedAddend = signedAddendParameter.staticConfig;

  addOutput('accumulate', width: outputWidth ?? (a.width + b.width + 1));

  addOutput('isAccumulateSigned') <=
      signedMultiplicandParameter.getLogic(this) |
          signedMultiplierParameter.getLogic(this) |
          signedAddendParameter.getLogic(this);
}