Float8ToFixed constructor

Float8ToFixed(
  1. Logic float,
  2. Logic mode, {
  3. String name = 'Float8ToFixed',
})

Constructor

Implementation

Float8ToFixed(Logic float, Logic mode, {super.name = 'Float8ToFixed'}) {
  float = addInput('float', float, width: float.width);
  mode = addInput('mode', mode);
  addOutput('fixed', width: 33);

  if (float.width != 8) {
    throw RohdHclException('Input width must be 8.');
  }

  final exponent = Logic(name: 'exponent', width: 5)
    ..gets(mux(
        mode, [Const(0), float.slice(6, 3)].swizzle(), float.slice(6, 2)));

  final jBit = Logic(name: 'jBit')..gets(exponent.or());

  final mantissa = Logic(name: 'mantissa', width: 4)
    ..gets(mux(mode, [jBit, float.slice(2, 0)].swizzle(),
        [Const(0), jBit, float.slice(1, 0)].swizzle()));

  final shift = Logic(name: 'shift', width: exponent.width)
    ..gets(mux(jBit, exponent - 1, Const(0, width: exponent.width)));

  final number = Logic(name: 'number', width: 33)
    ..gets([Const(0, width: 29), mantissa].swizzle() << shift);

  fixed <= mux(float[float.width - 1], ~number + 1, number);
}