MultiplierEncoder constructor

MultiplierEncoder(
  1. Logic multiplier,
  2. RadixEncoder radixEncoder, {
  3. Logic? selectSigned,
  4. bool signed = false,
})

Generate an encoding of the input multiplier

Implementation

MultiplierEncoder(this.multiplier, RadixEncoder radixEncoder,
    {Logic? selectSigned, bool signed = false})
    : _encoder = radixEncoder,
      _sliceWidth = log2Ceil(radixEncoder.radix) + 1 {
  if (signed && (selectSigned != null)) {
    throw RohdHclException('sign reconfiguration requires signed=false');
  }
  // Unsigned encoding wants to overlap past the multipler
  if (signed) {
    rows =
        ((multiplier.width + (signed ? 0 : 1)) / log2Ceil(radixEncoder.radix))
            .ceil();
  } else {
    rows = (((multiplier.width + 1) % (_sliceWidth - 1) == 0) ? 0 : 1) +
        ((multiplier.width + 1) ~/ log2Ceil(radixEncoder.radix));
  }
  // slices overlap by 1 and start at -1a
  if (selectSigned == null) {
    _extendedMultiplier = (signed
        ? multiplier.signExtend(rows * (_sliceWidth - 1))
        : multiplier.zeroExtend(rows * (_sliceWidth - 1)));
  } else {
    final len = multiplier.width;
    final sign = multiplier[len - 1];
    final extension = [
      for (var i = len - 1; i < (rows * (_sliceWidth - 1)); i++)
        mux(selectSigned, sign, Const(0))
    ];
    _extendedMultiplier = (multiplier.elements + extension).rswizzle();
  }
}