Multiplier constructor

Multiplier(
  1. Logic a,
  2. Logic b, {
  3. bool signedMultiplicand = false,
  4. bool signedMultiplier = false,
  5. Logic? selectSignedMultiplicand,
  6. Logic? selectSignedMultiplier,
  7. String name = 'unnamed_module',
})

Take input a and input b and return the product of the multiplication result.

signedMultiplicand parameter configures the multiplicand a as a signed multiplier (default is unsigned).

signedMultiplier parameter configures the multiplier b as a signed multiplier (default is unsigned).

Optional selectSignedMultiplicand allows for runtime configuration of signed or unsigned operation, overriding the signedMultiplicand static configuration.

Optional selectSignedMultiplier allows for runtime configuration of signed or unsigned operation, overriding the signedMultiplier static configuration.

Implementation

Multiplier(Logic a, Logic b,
    {this.signedMultiplicand = false,
    this.signedMultiplier = false,
    Logic? selectSignedMultiplicand,
    Logic? selectSignedMultiplier,
    super.name}) {
  a = addInput('a', a, width: a.width);
  b = addInput('b', b, width: b.width);

  selectSignedMultiplicand = (selectSignedMultiplicand != null)
      ? addInput('selectSignedMultiplicand', selectSignedMultiplicand)
      : null;
  selectSignedMultiplier = (selectSignedMultiplier != null)
      ? addInput('selectSignedMultiplier', selectSignedMultiplier)
      : null;

  addOutput('isProductSigned') <=
      (signedMultiplicand | signedMultiplier ? Const(1) : Const(0)) |
          ((selectSignedMultiplicand != null)
              ? selectSignedMultiplicand
              : Const(0)) |
          ((selectSignedMultiplier != null)
              ? selectSignedMultiplier
              : Const(0));
}