Multiplier constructor
Take input a and input b and return the product of the
multiplication result.
The optional signedMultiplicand parameter configures the multiplicand
a statically using a bool to indicate a signed multiplicand (default
is false, or unsigned) or dynamically with a 1-bit Logic input.
Passing something other null, bool, or Logic will result in a throw.
The optional signedMultiplier parameter configures the multiplier b
statically using a bool to indicate a signed multiplier (default is
false, or unsigned) or dynamically with a 1-bit Logic input. Passing
something other null, bool, or Logic will result in a throw.
If clk is not null then a set of flops are used to make the multiply a
2-cycle latency operation. reset and enable are optional inputs to
control these flops when clk is provided.
Implementation
Multiplier(Logic a, Logic b,
{Logic? clk,
Logic? reset,
Logic? enable,
dynamic signedMultiplicand,
dynamic signedMultiplier,
super.name = 'multiplier',
super.reserveName,
super.reserveDefinitionName,
String? definitionName})
: super(
definitionName: definitionName ??
'${b.width}_$signedMD(signedMultiplicand)}_'
'$signedML(signedMultiplier)}') {
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);
signedMultiplicandParameter =
StaticOrRuntimeParameter.ofDynamic(signedMultiplicand);
this.signedMultiplicand = signedMultiplicandParameter.staticConfig;
signedMultiplierParameter =
StaticOrRuntimeParameter.ofDynamic(signedMultiplier);
this.signedMultiplier = signedMultiplierParameter.staticConfig;
addOutput('product', width: a.width + b.width);
addOutput('isProductSigned') <=
signedMultiplicandParameter.getLogic(this) |
signedMultiplierParameter.getLogic(this);
}