fitAccumulateWidth method

  1. @protected
Logic fitAccumulateWidth(
  1. Logic naturalResult, {
  2. Logic? signed,
})

Reshapes naturalResult (the full-precision, natural-width multiply-accumulate result) to fit this module's accumulate output width.

If accumulate is the same width as naturalResult, it is returned unchanged. If accumulate is narrower, naturalResult is truncated to the low accumulate.width bits. If accumulate is wider, naturalResult is sign- or zero-extended based on signed (which defaults to the runtime isAccumulateSigned signal).

Implementation

@protected
Logic fitAccumulateWidth(Logic naturalResult, {Logic? signed}) {
  if (accumulate.width == naturalResult.width) {
    return naturalResult;
  }
  if (accumulate.width < naturalResult.width) {
    return naturalResult.slice(accumulate.width - 1, 0);
  }
  return mux(
      signed ?? isAccumulateSigned,
      naturalResult.signExtend(accumulate.width),
      naturalResult.zeroExtend(accumulate.width));
}