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