FloatingPointSwap<FpType extends FloatingPoint> constructor

FloatingPointSwap<FpType extends FloatingPoint>(
  1. FpType a,
  2. FpType b, {
  3. Logic? metaA,
  4. Logic? metaB,
  5. String name = 'floating_point_swap',
  6. bool reserveName = false,
  7. bool reserveDefinitionName = false,
  8. String definitionName = 'floating_point_swap',
})

Constructs a FloatingPointSwap module that swaps two floating point values.

Implementation

FloatingPointSwap(FpType a, FpType b,
    {Logic? metaA,
    Logic? metaB,
    super.name = 'floating_point_swap',
    super.reserveName,
    super.reserveDefinitionName,
    String definitionName = 'floating_point_swap'})
    : super(definitionName: definitionName) {
  if (a.width != b.width) {
    throw RohdHclException(
        'FloatingPointSwap requires inputs a and b to have the same width.');
  }
  if ((metaA == null) != (metaB == null)) {
    throw RohdHclException(
        'FloatingPointSwap requires both metaA and metaB to be either '
        'both null or both non-null.');
  }
  this.metaA =
      (metaA != null) ? addInput('inMetaA', metaA, width: metaA.width) : null;
  this.metaB =
      (metaB != null) ? addInput('inMetaB', metaB, width: metaB.width) : null;

  if (metaA != null && metaB != null) {
    // We have metadata to swap.
    if (metaA.width != metaB.width) {
      throw RohdHclException('FloatingPointSwap requires metaA and metaB to '
          'have the same width.');
    }
    addOutput('outMetaA', width: metaA.width);
    addOutput('outMetaB', width: metaB.width);
  }
  this.a = (a.clone(name: 'a') as FpType)
    ..gets(addInput('a', a, width: a.width));
  this.b = (b.clone(name: 'b') as FpType)
    ..gets(addInput('b', b, width: b.width));

  addOutput('outA', width: a.width);
  addOutput('outB', width: b.width);
}