GeneralDotProduct constructor
- List<
Logic> multiplicands, - List<
Logic> multipliers, { - dynamic signedMultiplicand,
- dynamic signedMultiplier,
- int treeRadix = 2,
- String multiplierIdentity = 'native',
- String adderIdentity = 'native',
- Adder adderGen(}) = NativeAdder.new,
- Multiplier multiplierGen(
- Logic a,
- Logic b, {
- Logic? clk,
- Logic? enable,
- Logic? reset,
- dynamic signedMultiplicand,
- dynamic signedMultiplier,
- String name = 'dotproduct',
- bool reserveName = false,
- bool reserveDefinitionName = false,
- 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;
}