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,enableare optional inputs to control a pipestage (only inserted ifclkis 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 = addTypedInput('a', a);
this.b = addTypedInput('b', b);
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;
// expose typed output and drive it from internalSum
sum = addTypedOutput(
'sum', internalSum.clone as FpTypeOut Function({String? name}));
sum <= internalSum;
if (outSum != null) {
outSum <= sum;
}
}