SignMagnitudeAdder constructor

SignMagnitudeAdder(
  1. Logic aSign,
  2. Logic a,
  3. Logic bSign,
  4. Logic b,
  5. Adder adderGen(
    1. Logic,
    2. Logic
    ), {
  6. bool largestMagnitudeFirst = false,
  7. String name = 'sign_magnitude_adder',
})

SignMagnitudeAdder constructor with an adder functor adderGen Inputs are (sign, magnitude) pairs: (aSign, a) and (bSign, b). If the caller can guarantee that the larger magnitude value is provided first in a, then they can set largestMagnitudeFirst too 'true' to avoid a comparator.

Implementation

// TODO(desmonddak): this adder may need a carry-in for rounding
SignMagnitudeAdder(this.aSign, super.a, this.bSign, super.b,
    Adder Function(Logic, Logic) adderGen,
    {this.largestMagnitudeFirst = false,
    super.name = 'sign_magnitude_adder'}) {
  aSign = addInput('aSign', aSign);
  bSign = addInput('bSign', bSign);
  _sign = addOutput('sign');

  final bLarger = a.lt(b) | (a.eq(b) & bSign.gt(aSign));

  _sign <= (largestMagnitudeFirst ? aSign : mux(bLarger, bSign, aSign));
  final adder = OnesComplementAdder(a, b,
      subtractIn: aSign ^ bSign, adderGen: adderGen);
  sum <= adder.sum;
}