ParallelPrefixAdder constructor

ParallelPrefixAdder(
  1. Logic a,
  2. Logic b, {
  3. ParallelPrefix ppGen(
    1. List<Logic>,
    2. Logic (
      1. Logic,
      2. Logic
      )
    ) = KoggeStone.new,
  4. String name = 'parallel_prefix_adder',
})

Adder constructor

Implementation

ParallelPrefixAdder(super.a, super.b,
    {ParallelPrefix Function(List<Logic>, Logic Function(Logic, Logic))
        ppGen = KoggeStone.new,
    super.name = 'parallel_prefix_adder'}) {
  final u = ppGen(
      List<Logic>.generate(
          a.width, (i) => [a[i] & b[i], a[i] | b[i]].swizzle()),
      (lhs, rhs) => [rhs[1] | rhs[0] & lhs[1], rhs[0] & lhs[0]].swizzle());
  sum <=
      [
        u.val[a.width - 1][1],
        List<Logic>.generate(a.width,
                (i) => (i == 0) ? a[i] ^ b[i] : a[i] ^ b[i] ^ u.val[i - 1][1])
            .rswizzle()
      ].swizzle();
}