swap<FpType extends FloatingPoint> static method

(FpType, FpType) swap<FpType extends FloatingPoint>(
  1. Logic swap,
  2. (FpType, FpType) toSwap
)

Swap two FloatingPoint structures based on a conditional swap.

Implementation

static (FpType, FpType) swap<FpType extends FloatingPoint>(
    Logic swap, (FpType, FpType) toSwap) {
  final in1 = toSwap.$1.named('swapIn1_${toSwap.$1.name}');
  final in2 = toSwap.$2.named('swapIn2_${toSwap.$2.name}');

  FpType clone({String? name}) => toSwap.$1.clone(name: name) as FpType;

  final out1 = mux(swap, in2, in1).named('swapOut1');
  final out2 = mux(swap, in1, in2).named('swapOut2');
  final first = clone(name: 'swapOut1')..gets(out1);
  final second = clone(name: 'swapOut2')..gets(out2);
  return (first, second);
}