FloatingPointAdder<FpTypeIn extends FloatingPoint, FpTypeOut extends FloatingPoint> constructor
Add two floating point numbers a
and b
, returning result in sum. If
a different output type is needed, you can provide that in outSum
.
clk
,reset
,enable
are optional inputs to control a pipestage (only inserted ifclk
is provided).
If outSum
is provided, it will be used as the output type, otherwise the
output type will be the same as the input type a
expect: if a
and b
don't match on explicit j-bit type then the output is the type of the
input that does NOT have explicit j-bit set.
Implementation
FloatingPointAdder(FpTypeIn a, FpTypeIn b,
{Logic? clk,
Logic? reset,
Logic? enable,
FpTypeOut? outSum,
this.roundingMode = FloatingPointRoundingMode.roundNearestEven,
super.name = 'floating_point_adder',
super.reserveName,
super.reserveDefinitionName,
String? definitionName})
: super(
definitionName: definitionName ??
'FloatingPointAdder_E${a.exponent.width}'
'M${a.mantissa.width}') {
if (b.exponent.width != a.exponent.width ||
b.mantissa.width != a.mantissa.width) {
throw RohdHclException('FloatingPoint input widths must match');
}
this.clk = (clk != null) ? addInput('clk', clk) : null;
this.reset = (reset != null) ? addInput('reset', reset) : null;
this.enable = (enable != null) ? addInput('enable', enable) : null;
this.a = (a.clone(name: 'a') as FpTypeIn)
..gets(addInput('a', a, width: a.width));
this.b = (b.clone(name: 'b') as FpTypeIn)
..gets(addInput('b', b, width: b.width));
internalSum =
(outSum ?? (a.explicitJBit ? b : a)).clone(name: 'outSum') as FpTypeOut;
exponentWidth = (outSum == null) ? a.exponent.width : outSum.exponent.width;
mantissaWidth = (outSum == null) ? a.mantissa.width : outSum.mantissa.width;
addOutput('sum', width: internalSum.width);
if (outSum != null) {
outSum <= output('sum');
}
output('sum') <= internalSum;
}