BitwisePopcount constructor
Creates shared bitwise-comparison population-count hardware.
Implementation
BitwisePopcount(
Logic a,
Logic b, {
required bool countEqual,
required String definitionPrefix,
int radix = 2,
super.name = 'bitwise_popcount',
super.reserveName,
super.reserveDefinitionName,
String? definitionName,
}) : super(
definitionName:
definitionName ?? '${definitionPrefix}_W${a.width}_R$radix',
) {
if (a.width != b.width) {
throw RohdHclException(
'Bitwise population-count inputs must have equal widths, got '
'${a.width} and ${b.width}.',
);
}
a = addInput('a', a, width: a.width);
b = addInput('b', b, width: b.width);
final compared = (countEqual ? ~(a ^ b) : a ^ b).named('compared');
final populationCount = Count(compared, radix: radix);
treeDepth = populationCount.treeDepth;
addOutput('count', width: populationCount.count.width) <=
populationCount.count;
}