Count constructor
Count 1
or 0
.
Takes in bus
of type Logic. by default performs countOne
(1
)
if countOne
is false
will count 0
Implementation
Count(Logic bus, {bool countOne = true}) {
bus = addInput('bus', bus, width: bus.width);
Logic count = Const(0, width: max(1, log2Ceil(bus.width) + 1));
for (var i = 0; i < bus.width; i++) {
count += (countOne ? bus[i] : ~bus[i]).zeroExtend(count.width);
}
_output =
addOutput('count${countOne ? "One" : "Zero"}', width: count.width);
_output <= count;
}