UnsignedAddWithOverflow constructor
Constructs an UnsignedAddWithOverflow of a and b.
Implementation
UnsignedAddWithOverflow(Logic a, Logic b,
{int? sumWidth,
super.name = 'unsigned_add_with_overflow',
super.reserveName,
super.reserveDefinitionName,
String? definitionName})
: sumWidth = sumWidth ?? max(a.width, b.width),
super(
definitionName: definitionName ??
'UnsignedAddWithOverflow_A${a.width}_B${b.width}'
'_S${sumWidth ?? max(a.width, b.width)}') {
a = addInput('a', a, width: a.width);
b = addInput('b', b, width: b.width);
final sum = addOutput('sum', width: this.sumWidth);
final overflow = addOutput('overflow');
// One extra bit above the widest operand and sum keeps the true sum.
final w = max(max(a.width, b.width), this.sumWidth) + 1;
final full = a.zeroExtend(w) + b.zeroExtend(w);
sum <= full.slice(this.sumWidth - 1, 0);
overflow <= full.slice(w - 1, this.sumWidth).or();
}