saturatingLdpcSignedDifference function

Logic saturatingLdpcSignedDifference(
  1. Logic minuend,
  2. Logic subtrahend, {
  3. required int width,
  4. required String name,
})

Subtracts signed subtrahend from minuend and saturates to width.

Implementation

Logic saturatingLdpcSignedDifference(
  Logic minuend,
  Logic subtrahend, {
  required int width,
  required String name,
}) {
  final calculationWidth = width + 1;
  final difference = (minuend.signExtend(calculationWidth) -
          subtrahend.signExtend(calculationWidth))
      .getRange(0, calculationWidth);
  return NumericNarrowing(
    difference,
    outputWidth: width,
    signed: true,
    overflowMode: NumericOverflowMode.saturate,
    name: '${name}_saturate',
  ).result.named(name);
}