ScheduledPermutationEngine<LogicType extends Logic> constructor
Creates a scheduled buffered permutation engine.
Implementation
ScheduledPermutationEngine({
required Logic clk,
required Logic reset,
required LogicType element,
required Logic write,
required Logic advance,
required Logic clear,
required this.descriptor,
required this.elementWidth,
String name = 'scheduled_permutation_engine',
}) : super(
definitionName: 'ScheduledPermutationEngine_N${descriptor.length}_'
'E${elementWidth}_P${descriptor.configurationSignature}_'
'${payloadShapeIdentity(element)}',
name: name,
) {
if (elementWidth < 1 || element.width != elementWidth) {
throw ArgumentError.value(
elementWidth, 'elementWidth', 'Must match a positive element width.');
}
this.clk = addInput('clk', clk);
this.reset = addInput('reset', reset);
this.element = addTypedInput('element', element);
write = addInput('write', write);
advance = addInput('advance', advance);
clear = addInput('clear', clear);
final indexWidth = widthFor(descriptor.length);
final localCollecting = Logic(name: '${name}_collecting');
final localEmitting = Logic(name: '${name}_emitting');
final writeIndex = Logic(name: '${name}_write_index', width: indexWidth);
final readIndex = Logic(name: '${name}_read_index', width: indexWidth);
// Replay selects packed slots; typed ports preserve the element schema.
final storage = List<Logic>.generate(
descriptor.length,
(index) => Logic(name: '${name}_storage_$index', width: elementWidth),
);
data = addTypedPayloadOutput(this, 'data', this.element);
final localLast = readIndex.eq(descriptor.length - 1);
addOutput('collecting') <= localCollecting;
addOutput('emitting') <= localEmitting;
addOutput('outputIndex', width: indexWidth) <= readIndex;
addOutput('first') <= localEmitting & readIndex.eq(0);
addOutput('last') <= localEmitting & localLast;
connectPackedPayload(
data,
[
for (var outputIndex = 0;
outputIndex < descriptor.length;
outputIndex++)
storage[descriptor.sourceIndex(outputIndex)],
].selectIndex(readIndex),
);
Sequential(this.clk, reset: this.reset, resetValues: {
localCollecting: 1,
localEmitting: 0,
writeIndex: 0,
readIndex: 0,
}, [
If(clear, then: [
localCollecting < 1,
localEmitting < 0,
writeIndex < 0,
readIndex < 0,
], orElse: [
If(write & localCollecting, then: [
for (var index = 0; index < descriptor.length; index++)
If(writeIndex.eq(index), then: [
storage[index] < this.element.packed,
]),
If(writeIndex.eq(descriptor.length - 1), then: [
localCollecting < 0,
localEmitting < 1,
writeIndex < 0,
readIndex < 0,
], orElse: [
writeIndex < writeIndex + 1,
]),
]),
If(advance & localEmitting, then: [
If(localLast, then: [
localCollecting < 1,
localEmitting < 0,
readIndex < 0,
], orElse: [
readIndex < readIndex + 1,
]),
]),
]),
]);
}