CompressorDelayTable.fromFullAdderStages constructor

CompressorDelayTable.fromFullAdderStages(
  1. CompressorDelayTable first,
  2. CompressorDelayTable second
)

Derives the 4:2 paths from the two full adders used by Compressor4.

Implementation

factory CompressorDelayTable.fromFullAdderStages(
    CompressorDelayTable first, CompressorDelayTable second) {
  if (first.sum.length != 3 || second.sum.length != 3) {
    throw ArgumentError('Both stages must be 3:2 compressor tables.');
  }
  return CompressorDelayTable(
    sum: [
      for (final delay in first.sum) delay + second.sum[2],
      second.sum[1],
      second.sum[0],
    ],
    carry: [
      for (final delay in first.sum) delay + second.carry[2],
      second.carry[1],
      second.carry[0],
    ],
    cout: [...first.carry, null, null],
  );
}