FloatToFixed constructor
- FloatingPoint float, {
- String name = 'FloatToFixed',
Constructor
Implementation
FloatToFixed(FloatingPoint float, {super.name = 'FloatToFixed'}) {
float = float.clone()..gets(addInput('float', float, width: float.width));
final bias = FloatingPointValue.computeBias(float.exponent.width);
// E4M3 expands the max exponent by 1.
m = ((float.exponent.width == 4) & (float.mantissa.width == 3))
? bias + 1
: bias;
n = bias + float.mantissa.width - 1;
final outputWidth = m + n + 1;
final jBit = Logic(name: 'jBit')..gets(float.isNormal());
final shift = Logic(name: 'shift', width: float.exponent.width)
..gets(
mux(jBit, float.exponent - 1, Const(0, width: float.exponent.width)));
final number = Logic(name: 'number', width: outputWidth)
..gets([
Const(0, width: outputWidth - float.mantissa.width - 1),
jBit,
float.mantissa
].swizzle() <<
shift);
_fixed <= mux(float.sign, ~number + 1, number);
addOutput('fixed', width: outputWidth) <= _fixed;
}