UnsignedMulWithOverflow constructor
Constructs an UnsignedMulWithOverflow of a and b.
Implementation
UnsignedMulWithOverflow(Logic a, Logic b,
{int? productWidth,
super.name = 'unsigned_mul_with_overflow',
super.reserveName,
super.reserveDefinitionName,
String? definitionName})
: productWidth = productWidth ?? a.width + b.width,
super(
definitionName: definitionName ??
'UnsignedMulWithOverflow_A${a.width}_B${b.width}'
'_P${productWidth ?? a.width + b.width}') {
a = addInput('a', a, width: a.width);
b = addInput('b', b, width: b.width);
final product = addOutput('product', width: this.productWidth);
final overflow = addOutput('overflow');
final fullWidth = a.width + b.width;
final wideProduct = a.zeroExtend(fullWidth) * b.zeroExtend(fullWidth);
final full = wideProduct.slice(fullWidth - 1, 0);
if (this.productWidth >= fullWidth) {
product <= full.zeroExtend(this.productWidth);
overflow <= Const(0);
} else {
product <= full.slice(this.productWidth - 1, 0);
overflow <= full.slice(fullWidth - 1, this.productWidth).or();
}
}