DotProductBase constructor
Creates a new DotProductBase instance given a List<Logic> of
multiplicands and a List<Logic> of multipliers.
Every multiplicand must have one common width and every multiplier must have one common width. The multiplicand and multiplier widths may differ.
The optional signedMultiplicand parameter configures the multiplicands
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 multipliers
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.
The output product will be log2Ceil(multiplicands.length) wider than the sum of one multiplicand width and one multiplier width to accommodate the increasing accumulation value.
Implementation
DotProductBase(List<Logic> multiplicands, List<Logic> multipliers,
{dynamic signedMultiplicand,
dynamic signedMultiplier,
super.name = 'dotproduct',
super.reserveName = false,
super.reserveDefinitionName = false,
String? definitionName})
: super(
definitionName: definitionName ??
'DotProduct_L${multipliers.length}_'
'A${multiplicands[0].width}_B${multipliers[0].width}_'
'${Multiplier.signedMD(signedMultiplicand)}_'
'${Multiplier.signedML(signedMultiplier)}') {
if (multipliers.length != multiplicands.length) {
throw RohdHclException(
'Number of multipliers and multiplicands must be equal.');
}
final candWidthMiss = multiplicands
.mapIndexed((i, m) => m.width == multiplicands[i > 0 ? i - 1 : 0].width)
.where((w) => w)
.length;
if (candWidthMiss < multiplicands.length) {
throw RohdHclException('Multiplicands must all have the same width: '
'${multiplicands.length - candWidthMiss} '
"don't match preceding width.");
}
final multiplierWidthMatches = multipliers
.mapIndexed((i, m) => m.width == multipliers[i > 0 ? i - 1 : 0].width)
.where((w) => w)
.length;
if (multiplierWidthMatches < multipliers.length) {
throw RohdHclException('Multipliers must all have the same width: '
'${multipliers.length - multiplierWidthMatches} '
"don't match preceding width.");
}
signedMultiplicandParameter =
StaticOrRuntimeParameter.ofDynamic(signedMultiplicand);
signedMultiplierParameter =
StaticOrRuntimeParameter.ofDynamic(signedMultiplier);
this.multiplicands = multiplicands
.mapIndexed((i, multiplicand) => addInput(
'multiplicand_$i', multiplicand,
width: multiplicand.width))
.toList();
this.multipliers = multipliers
.mapIndexed((i, multiplier) =>
addInput('multiplier_$i', multiplier, width: multiplier.width))
.toList();
}