saturatingLdpcSignedSum function
Adds signed LDPC messages and saturates to width.
Implementation
Logic saturatingLdpcSignedSum(
List<Logic> values, {
required int width,
required String name,
}) {
if (values.isEmpty) {
throw ArgumentError.value(values, 'values', 'Must not be empty.');
}
final calculationWidth = width + _maximum(1, values.length.log2Ceil);
final extended = [
for (final value in values) value.signExtend(calculationWidth),
];
final sum = extended.length == 1
? extended.single
: ReductionTreeGenerator(
extended,
(inputs, {depth = 0, control, name = 'sum'}) => inputs.reduce(
(left, right) => (left + right).getRange(0, calculationWidth),
),
).out;
return NumericNarrowing(
sum,
outputWidth: width,
signed: true,
overflowMode: NumericOverflowMode.saturate,
name: '${name}_saturate',
).result.named(name);
}