LeadingZeroAnticipateBase constructor

LeadingZeroAnticipateBase(
  1. Logic aSign,
  2. Logic a,
  3. Logic bSign,
  4. Logic b, {
  5. String name = 'leading_zero_anticipate',
  6. bool reserveName = false,
  7. bool reserveDefinitionName = false,
  8. String? definitionName,
})

Construct a leading-zero anticipate module that predicts the number of leading zeros in the sum of a and b. The output leadingOne holds the position of the leading '1' (or, equivalently, the number of leading zeros) that are predicted. This prediction can be exact or 1 position less than the leading zero of the sum or subtraction of a and b. validLeadOne indicates a leading one was found.

Implementation

LeadingZeroAnticipateBase(Logic aSign, Logic a, Logic bSign, Logic b,
    {super.name = 'leading_zero_anticipate',
    super.reserveName,
    super.reserveDefinitionName,
    String? definitionName})
    : super(definitionName: definitionName ?? 'LeadingZeroAnticipate') {
  aSign = addInput('aSign', aSign);
  a = addInput('a', a, width: a.width);
  bSign = addInput('bSign', bSign);
  b = addInput('b', b, width: b.width);

  final aX = a.zeroExtend(a.width + 1).named('aX');
  final bX = b.zeroExtend(b.width + 1).named('bX');
  final t = (aX ^ mux(aSign ^ bSign, ~bX, bX)).named('t');
  final zForward = (~aX & mux(aSign ^ bSign, bX, ~bX)).named('zerosForward');
  final zReverse = ~bX & mux(aSign ^ bSign, aX, ~aX).named('zerosReverse');
  final fForward = Logic(name: 'findForward', width: t.width);
  final fReverse = Logic(name: 'findReverse', width: t.width);
  fForward <= t ^ (~zForward << 1 | Const(1, width: t.width));
  fReverse <= t ^ (~zReverse << 1 | Const(1, width: t.width));

  leadOneEncoder = RecursiveModulePriorityEncoder(fForward.reversed,
      generateValid: true, name: 'leadone_detect');

  leadOneEncoderConverse = RecursiveModulePriorityEncoder(fReverse.reversed,
      generateValid: true, name: 'leadone_detect_converse');

  addOutput('leadingOne', width: log2Ceil(fForward.width + 1));
  addOutput('validLeadOne');
}