addReduceAdders method

Logic addReduceAdders(
  1. List<Logic> inputs, {
  2. int? depth,
  3. Logic? control,
  4. String name = 'prefix',
})

Reduction tree adder generator for the final addition.

Implementation

Logic addReduceAdders(List<Logic> inputs,
    {int? depth, Logic? control, String name = 'prefix'}) {
  if (inputs.length < 4) {
    return inputs.reduce((v, e) => v + e);
  } else {
    final add0 = adderGen(inputs[0], inputs[1], name: '${name}_add0');
    final add1 = adderGen(inputs[2], inputs[3], name: '${name}_add1');
    final addf =
        adderGen(add0.sum, add1.sum, name: '${name}_addf_${depth ?? 0}');
    return addf.sum;
  }
}