OnesComplementAdder constructor

OnesComplementAdder(
  1. Logic a,
  2. Logic b, {
  3. Adder adderGen(
    1. Logic,
    2. Logic, {
    3. Logic? carryIn,
    }) = NativeAdder.new,
  4. @Deprecated('Use subtract with a 1-bit Logic instead.') Logic? subtractIn,
  5. bool generateEndAroundCarry = false,
  6. Logic? carryIn,
  7. dynamic subtract,
  8. bool chainable = false,
  9. bool reserveName = false,
  10. bool reserveDefinitionName = false,
  11. String? definitionName,
  12. String name = 'ones_complement_adder',
})

OnesComplementAdder constructor with an adder functor adderGen.

  • subtract configures subtraction statically with a bool or at runtime with a 1-bit Logic. It defaults to addition.
  • subtractIn is a deprecated runtime subtraction control. It may be provided with an explicit subtract: false for compatibility.
  • If generateEndAroundCarry is true, then the end-around carry is not performed and is provided as output endAroundCarry. If generateEndAroundCarry is false, extra hardware takes care of adding the end-around carry to sum.
  • carryIn allows for another adder to chain into this one.
  • chainable tells this adder to not store the endAroundCarry in the sign bit as well, but to zero that to allow adders to be chained such as for use in the CarrySelectCompoundAdder.

Implementation

OnesComplementAdder(super.a, super.b,
    {Adder Function(Logic, Logic, {Logic? carryIn}) adderGen =
        NativeAdder.new,
    @Deprecated('Use subtract with a 1-bit Logic instead.') Logic? subtractIn,
    this.generateEndAroundCarry = false,
    super.carryIn,
    dynamic subtract,
    bool chainable = false,
    super.reserveName,
    super.reserveDefinitionName,
    String? definitionName,
    super.name = 'ones_complement_adder'})
    : super(
          definitionName:
              definitionName ?? 'OnesComplementAdder_W${a.width}') {
  if (generateEndAroundCarry) {
    addOutput('endAroundCarry');
  }
  final subtractIsActive =
      subtract != null && (subtract is! bool || subtract);
  if (subtractIn != null && subtractIsActive) {
    throw RohdHclException(
        "Provide either deprecated 'subtractIn' or 'subtract', "
        'but not both.');
  }
  subtractParameter = subtractIn != null
      ? StaticOrRuntimeParameter(
          name: 'subtractIn', runtimeConfig: subtractIn)
      : StaticOrRuntimeParameter.ofDynamic(subtract);
  _sign = addOutput('sign');

  final doSubtract = subtractParameter
      .getLogic(this)
      .named('dosubtract', naming: Naming.mergeable);

  final adderSum =
      adderGen(a, mux(doSubtract, ~b, b), carryIn: carryIn ?? Const(0))
          .sum
          .named('adderSum', naming: Naming.mergeable);

  if (generateEndAroundCarry) {
    endAroundCarry! <= adderSum[-1];
  }
  final endAround = adderSum[-1].named('endaround');
  final magnitude = adderSum.slice(a.width - 1, 0).named('magnitude');
  final Logic magnitudep1;
  if (!generateEndAroundCarry) {
    final incrementer = ParallelPrefixIncr(magnitude);
    magnitudep1 = incrementer.out.named('magnitude_plus1');
  } else {
    magnitudep1 = Const(0);
  }
  sum <=
      mux(
          doSubtract,
          [
            if (chainable) endAround else Const(0),
            mux(
                [if (chainable) Const(0) else endAround].first,
                [if (generateEndAroundCarry) magnitude else magnitudep1]
                    .first,
                ~magnitude)
          ].swizzle(),
          adderSum);
  _sign <= mux(doSubtract, ~endAround, Const(0));
}