buildLogic method
Builds the internal logic of the queue.
Implementation
@protected
@visibleForOverriding
void buildLogic() {
if (isModel) {
_buildModel();
return;
}
final availableIndicesFifo = Fifo(
clk,
reset,
readEnable: push,
writeEnable: popFromDataQueue,
writeData: popIndex,
depth: entryCount,
initialValues: List.generate(entryCount, (i) => i),
memoryConfiguration: memoryConfiguration,
name: 'available_indices_fifo',
);
if (Test.instance != null) {
FifoChecker(
availableIndicesFifo,
name: '${name}_availableIndicesFifoChecker',
enableEndOfTestEmptyCheck: false, // since it should be FULL at the end
// TODO(mkorbel1): add a check that this is FULL at the end of a test
);
}
_availableIndicesFifoEmpty <= availableIndicesFifo.empty;
channelTrackers = [
for (var i = 0; i < numChannels; i++)
buildChannelTracking(
i,
push: push & pushChannel.eq(i),
pop: popFromDataQueue & popChannel.eq(i),
),
];
final pointerWritePort = DataPortInterface(indexWidth, indexWidth);
final pointerReadPort = DataPortInterface(indexWidth, indexWidth);
// whenever a push comes, update the last pointer for that channel
// - the channel tracking needs to update lastIndex
// - the old lastIndex needs to be updated with nextIndex
Combinational([
If(
push,
then: [
Case(pushChannel, conditionalType: ConditionalType.unique, [
for (final channelTracker in channelTrackers)
CaseItem(
Const(channelTracker.channelId, width: pushChannel.width),
[
pointerWritePort.en < push & ~channelTracker.empty,
pointerWritePort.addr < channelTracker.lastIndex,
pointerWritePort.data < pushIndex,
],
),
]),
],
orElse: [
pointerWritePort.en < 0,
pointerWritePort.addr < 0,
pointerWritePort.data < 0,
],
),
]);
pointerReadPort.en <= popFromDataQueue;
pointerReadPort.addr <= popIndex;
configuredRegisterFile(
clk,
reset,
[pointerWritePort],
[pointerReadPort],
entryCount: entryCount,
memoryConfiguration: memoryConfiguration,
name: 'pointer_storage',
);
occupiedChannels <= channelTrackers.map((e) => ~e.empty).toList().rconcat();
final popSelectArbiter = RoundRobinArbiter(
arbitable.elements,
clk: clk,
reset: reset,
name: 'popSelectArbiter',
);
popValid <= popSelectArbiter.grants.concat().or();
// An explicit unknown default keeps popIndex unknown without a grant in
// generated SystemVerilog too, rather than an unmatched unique case.
popIndex <=
cases(
Const(1),
conditionalType: ConditionalType.unique,
{
for (final (i, grant) in popSelectArbiter.grants.indexed)
grant: channelTrackers[i].firstIndex,
},
defaultValue: Const(LogicValue.filled(indexWidth, LogicValue.x)),
);
popChannel <=
OneHotToBinary(
popSelectArbiter.grants.rconcat(),
).binary.zeroExtend(popChannel.width);
pushIndex <= availableIndicesFifo.readData;
final pushWritePort = DataPortInterface(pushData.width, indexWidth);
pushWritePort.data <= pushData;
pushWritePort.addr <= pushIndex;
pushWritePort.en <= push;
final popReadPort = DataPortInterface(pushData.width, indexWidth);
popReadPort.addr <= popIndex;
popReadPort.en <= popFromDataQueue;
popReplacementIndex <= pointerReadPort.data;
popData <= popReadPort.data;
configuredRegisterFile(
clk,
reset,
[pushWritePort],
[popReadPort, ...?additionalReadDataPorts],
entryCount: entryCount,
name: 'main_storage',
);
}