BrentKung constructor
BrentKung constructor
Implementation
BrentKung(List<Logic> inps, Logic Function(Logic, Logic) op)
: super(inps, 'brent_kung') {
final iseq = <Logic>[];
inps.forEachIndexed((i, el) {
iseq.add(addInput('i$i', el, width: el.width));
_oseq.add(addOutput('o$i', width: el.width));
});
// Reduce phase
var skip = 2;
while (skip <= inps.length) {
for (var i = skip - 1; i < inps.length; i += skip) {
iseq[i] = op(iseq[i - skip ~/ 2], iseq[i]);
}
skip *= 2;
}
// Prefix Phase
skip = largestPow2LessThan(inps.length);
while (skip > 2) {
for (var i = 3 * (skip ~/ 2) - 1; i < inps.length; i += skip) {
iseq[i] = op(iseq[i - skip ~/ 2], iseq[i]);
}
skip ~/= 2;
}
// Final row
for (var i = 2; i < inps.length; i += 2) {
iseq[i] = op(iseq[i - 1], iseq[i]);
}
iseq.forEachIndexed((i, el) {
_oseq[i] <= el;
});
}