StaticPermutation constructor
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;
}