BitwisePopcount constructor

BitwisePopcount(
  1. Logic a,
  2. Logic b, {
  3. required bool countEqual,
  4. required String definitionPrefix,
  5. int radix = 2,
  6. String name = 'bitwise_popcount',
  7. bool reserveName = false,
  8. bool reserveDefinitionName = false,
  9. String? definitionName,
})

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;
}