StaticPermutation constructor

StaticPermutation(
  1. Logic dataIn, {
  2. required PermutationDescriptor descriptor,
  3. int elementWidth = 1,
  4. dynamic applyPermutation = true,
  5. String name = 'static_permutation',
  6. bool reserveName = false,
  7. bool reserveDefinitionName = false,
  8. String? definitionName,
})

Creates static wiring for descriptor.

Implementation

StaticPermutation(
  Logic dataIn, {
  required this.descriptor,
  this.elementWidth = 1,
  dynamic applyPermutation = true,
  super.name = 'static_permutation',
  super.reserveName,
  super.reserveDefinitionName,
  String? definitionName,
}) : super(
        definitionName: definitionName ??
            'StaticPermutation_L${descriptor.length}_E${elementWidth}_'
                'P${descriptor.configurationSignature}_'
                '${_configurationName(applyPermutation)}',
      ) {
  if (elementWidth <= 0) {
    throw RohdHclException('Permutation element width must be positive.');
  }
  final expectedWidth = descriptor.length * elementWidth;
  if (dataIn.width != expectedWidth) {
    throw PortWidthMismatchException(dataIn, expectedWidth);
  }

  dataIn = addInput('data_in', dataIn, width: dataIn.width);
  applyPermutationParameter =
      StaticOrRuntimeParameter.ofDynamic(applyPermutation);
  late final Logic selected;
  if (applyPermutationParameter.runtimeConfig == null &&
      !applyPermutationParameter.staticConfig) {
    selected = dataIn;
  } else {
    final outputElements = [
      for (var outputIndex = 0;
          outputIndex < descriptor.length;
          outputIndex++)
        dataIn.getRange(
          descriptor.sourceIndex(outputIndex) * elementWidth,
          (descriptor.sourceIndex(outputIndex) + 1) * elementWidth,
        ),
    ];
    final permuted = outputElements.rconcat();
    selected = applyPermutationParameter.runtimeConfig != null
        ? mux(applyPermutationParameter.getLogic(this), permuted, dataIn)
        : permuted;
  }
  addOutput('result', width: dataIn.width) <= selected;
}