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,
super.name = 'count',
super.reserveName,
super.reserveDefinitionName,
String? definitionName})
: super(definitionName: definitionName ?? 'Count_W${bus.width}') {
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 = (count + (countOne ? bus[i] : ~bus[i]).zeroExtend(count.width))
.named('count_$i');
}
_output =
addOutput('count${countOne ? "One" : "Zero"}', width: count.width);
_output <= count;
}