CompressionTreeMultiplyAccumulate constructor
- Logic a,
- Logic b,
- Logic c,
- int radix, {
- Logic? clk,
- Logic? reset,
- Logic? enable,
- bool signedMultiplicand = false,
- bool signedMultiplier = false,
- bool signedAddend = false,
- Logic? selectSignedMultiplicand,
- Logic? selectSignedMultiplier,
- Logic? selectSignedAddend,
- Adder adderGen(}) = NativeAdder.new,
- PartialProductSignExtension seGen(
- PartialProductGeneratorBase pp, {
- String name,
- String name = 'compression_tree_mac',
Construct a compression tree integer multiply-add with a given radix
and an Adder generator functor adderGen
for the final adder.
a
and b
are the product terms, c
is the accumulate term which
must be the sum of the widths plus 1.
signedMultiplicand
parameter configures the multiplicand a
as
always signed (default is unsigned).
signedMultiplier
parameter configures the multiplier b
as
always signed (default is unsigned).
signedAddend
parameter configures the addend c
as
always signed (default is unsigned).
Sign extension methodology is defined by the partial product generator
supplied via seGen
.
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.
Optional selectSignedAddend
allows for runtime configuration of
signed or unsigned operation, overriding the signedAddend
static
configuration.
If clk
is not null then a set of flops are used to latch the output
after compression. reset
and enable
are optional
inputs to control these flops when clk
is provided. If clk
is null,
the ColumnCompressor is built as a combinational tree of compressors.
Implementation
CompressionTreeMultiplyAccumulate(super.a, super.b, super.c, int radix,
{Logic? clk,
Logic? reset,
Logic? enable,
super.signedMultiplicand = false,
super.signedMultiplier = false,
super.signedAddend = false,
super.selectSignedMultiplicand,
super.selectSignedMultiplier,
super.selectSignedAddend,
Adder Function(Logic a, Logic b, {Logic? carryIn}) adderGen =
NativeAdder.new,
PartialProductSignExtension Function(PartialProductGeneratorBase pp,
{String name})
seGen = CompactRectSignExtension.new,
super.name = 'compression_tree_mac'}) {
final accumulate = addOutput('accumulate', width: a.width + b.width + 1);
final pp = PartialProductGenerator(
a,
b,
RadixEncoder(radix),
selectSignedMultiplicand: selectSignedMultiplicand,
signedMultiplicand: signedMultiplicand,
selectSignedMultiplier: selectSignedMultiplier,
signedMultiplier: signedMultiplier,
);
seGen(pp).signExtend();
final lastLength =
pp.partialProducts[pp.rows - 1].length + pp.rowShift[pp.rows - 1];
final sign = mux(
(selectSignedAddend != null)
? selectSignedAddend!
: (signedAddend ? Const(1) : Const(0)),
c[c.width - 1],
Const(0));
final l = [for (var i = 0; i < c.width; i++) c[i]];
while (l.length < lastLength) {
l.add(sign);
}
l
..add(~sign)
..add(Const(1));
// For online evaluate in _ColumnCompressor to work, we need to
// insert the row rather than append it.
pp.partialProducts.insert(0, l);
pp.rowShift.insert(0, 0);
final compressor =
ColumnCompressor(clk: clk, reset: reset, enable: enable, pp)
..compress();
final adder = adderGen(compressor.extractRow(0), compressor.extractRow(1));
accumulate <= adder.sum.slice(a.width + b.width - 1 + 1, 0);
}