DotProductBase constructor
Creates a new DotProductBase instance given a List<Logic> of
multiplicands
and a List<Logic> of multipliers
. Currently widths of
all operands must match.
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 the widths of one pair of products to accomadate 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_W${multipliers[0].width}_') {
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.");
}
// Enforce square products.
final operandWidthMiss = multiplicands
.mapIndexed((i, m) => m.width == multipliers[i].width)
.where((w) => w)
.length;
if (operandWidthMiss < multiplicands.length) {
throw RohdHclException('Multiplier and multiplicand have '
'${multiplicands.length - operandWidthMiss} width mismatches.');
}
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();
}