NativeAdder constructor

NativeAdder(
  1. Logic a,
  2. Logic b, {
  3. Logic? carryIn,
  4. String name = 'native_adder',
})

The width of input a and b must be the same.

Implementation

NativeAdder(super.a, super.b, {super.carryIn, super.name = 'native_adder'})
    : super(definitionName: 'NativeAdder_W${a.width}') {
  if (a.width != b.width) {
    throw RohdHclException('inputs of a and b should have same width.');
  }
  final aExtended =
      a.zeroExtend(a.width + 1).named('aExtended', naming: Naming.mergeable);
  final bExtended =
      b.zeroExtend(a.width + 1).named('bExtended', naming: Naming.mergeable);
  final aPlusb = (aExtended + bExtended)
      .named('aExtended_plus_bExtended', naming: Naming.mergeable);
  if (carryIn == null) {
    sum <= aPlusb;
  } else {
    final cinExtendend = carryIn!
        .zeroExtend(a.width + 1)
        .named('carryInExtended', naming: Naming.mergeable);
    sum <=
        (aPlusb + cinExtendend)
            .named('sumWithCarryIn', naming: Naming.mergeable);
  }
}