ReadyValidMultiLifecycleTracker<LogicType extends Logic> constructor
- required Logic clk,
- required Logic reset,
- required Logic quiesce,
- required List<
ReadyValidInterface< allocations,Tagged< >LogicType> > - required ReadyValidInterface<
Logic> cancellationMask, - required ReadyValidInterface<
Logic> releaseMask, - required List<
Logic> lookupTags, - required int capacity,
- RegisterFileFunctor? metadataStorageImplementation,
- String name = 'ready_valid_multi_lifecycle_tracker',
Creates a multi-lane lifecycle tracker.
Implementation
ReadyValidMultiLifecycleTracker(
{required Logic clk,
required Logic reset,
required Logic quiesce,
required List<ReadyValidInterface<Tagged<LogicType>>> allocations,
required ReadyValidInterface<Logic> cancellationMask,
required ReadyValidInterface<Logic> releaseMask,
required List<Logic> lookupTags,
required this.capacity,
RegisterFileFunctor? metadataStorageImplementation,
super.name = 'ready_valid_multi_lifecycle_tracker'})
: tagWidth = allocations.isEmpty ? 0 : allocations.first.data.tag.width,
allocationLaneCount = allocations.length,
lookupCount = lookupTags.length,
super(
definitionName: _multiLifecycleDefinitionName(capacity, allocations,
lookupTags.length, metadataStorageImplementation)) {
if (capacity < 1 || allocationLaneCount < 1 || lookupCount < 1) {
throw ArgumentError(
'Capacity, allocation lanes, and lookup count must be positive.');
}
final minimumTagWidth = max(1, capacity.log2Ceil);
final ownerWidth = allocations.first.data.data.width;
if (tagWidth < minimumTagWidth ||
allocations.any((allocation) =>
allocation.data.tag.width != tagWidth ||
allocation.data.data.width != ownerWidth) ||
cancellationMask.data.width != capacity ||
releaseMask.data.width != capacity ||
lookupTags.any((tag) => tag.width != tagWidth)) {
throw ArgumentError(
'Allocation, mask, owner, and lookup shapes must match capacity.');
}
if (!rohdPayloadsCompatible(
allocations.map((allocation) => allocation.data.data),
ignoreConstantNames: true)) {
throw ArgumentError('Allocation owner payloads must be compatible.');
}
for (final allocation in allocations) {
allocation.requireProviderComposableWith(ReadyValidContract.readyAndValid,
consumerName: name);
}
cancellationMask.requireProviderComposableWith(
ReadyValidContract.readyAndValid,
consumerName: name);
releaseMask.requireProviderComposableWith(ReadyValidContract.readyAndValid,
consumerName: name);
final localClk = addInput('clk', clk);
final localReset = addInput('reset', reset);
final localQuiesce = addInput('quiesce', quiesce);
final localLookupTags = [
for (var port = 0; port < lookupCount; port++)
addInput('lookupTag$port', lookupTags[port], width: tagWidth)
];
this.allocations = [
for (var lane = 0; lane < allocationLaneCount; lane++)
addPairInterface(allocations[lane], PairRole.consumer,
uniquify: (original) => 'allocation_${lane}_$original')
];
this.cancellationMask = addPairInterface(
cancellationMask, PairRole.consumer,
uniquify: (original) => 'cancellation_mask_$original');
this.releaseMask = addPairInterface(releaseMask, PairRole.consumer,
uniquify: (original) => 'release_mask_$original');
for (final allocation in this.allocations) {
allocation.ready <= ~localQuiesce;
}
this.cancellationMask.ready <= Const(1);
this.releaseMask.ready <= Const(1);
final live = [
for (var index = 0; index < capacity; index++)
Logic(name: '${name}_live_$index')
];
final canceled = [
for (var index = 0; index < capacity; index++)
Logic(name: '${name}_canceled_$index')
];
final metadataWrites = [
for (var lane = 0; lane < allocationLaneCount; lane++)
ReadyAndValidInterface(this
.allocations[lane]
.data
.cloneTyped(name: '${name}_metadata_write_$lane')),
];
for (var lane = 0; lane < allocationLaneCount; lane++) {
metadataWrites[lane].valid <= this.allocations[lane].accepted;
metadataWrites[lane].data <= this.allocations[lane].data;
}
final metadata = ReadyValidMultiMetadataTable(
clk: localClk,
reset: localReset,
writes: metadataWrites,
lookupTags: localLookupTags,
capacity: capacity,
storageImplementation: metadataStorageImplementation,
name: '${name}_metadata',
);
entryData = [
for (var index = 0; index < capacity; index++)
addTypedPayloadOutput(
this, 'entryData$index', this.allocations.first.data.data)
];
lookupData = [
for (var port = 0; port < lookupCount; port++)
addTypedPayloadOutput(
this, 'lookupData$port', this.allocations.first.data.data)
];
addOutput('liveTags', width: capacity);
addOutput('canceledTags', width: capacity);
addOutput('liveTagsAfterUpdates', width: capacity);
addOutput('canceledTagsAfterUpdates', width: capacity);
addOutput('lookupLive', width: lookupCount);
addOutput('lookupCanceled', width: lookupCount);
final countWidth = max(1, (capacity + 1).log2Ceil);
addOutput('liveCount', width: countWidth);
addOutput('empty');
addOutput('full');
addOutput('invalidAllocations', width: allocationLaneCount);
addOutput('duplicateAllocations', width: allocationLaneCount);
addOutput('cancelUnallocatedMask', width: capacity);
addOutput('duplicateCancelMask', width: capacity);
addOutput('doubleReleaseMask', width: capacity);
addOutput('invalidLookups', width: lookupCount);
final acceptedReleaseMask = mux(this.releaseMask.accepted,
this.releaseMask.data, Const(0, width: capacity))
.named('${name}_accepted_release_mask');
var updatedLive = [
for (var index = 0; index < capacity; index++)
(live[index] & ~acceptedReleaseMask[index])
.named('${name}_live_${index}_after_release')
];
var updatedCanceled = [
for (var index = 0; index < capacity; index++)
(canceled[index] & ~acceptedReleaseMask[index])
.named('${name}_canceled_${index}_after_release')
];
final capacityFillsTagSpace = capacity == (1 << tagWidth);
Logic inRange(Logic tag, String operation) => capacityFillsTagSpace
? Const(1)
: tag
.lt(Const(capacity, width: tagWidth))
.named('${name}_${operation}_in_range');
final allocationInRange = [
for (var lane = 0; lane < allocationLaneCount; lane++)
inRange(this.allocations[lane].data.tag, 'allocation_$lane')
];
final acceptedAllocations = [
for (var lane = 0; lane < allocationLaneCount; lane++)
(this.allocations[lane].accepted & allocationInRange[lane])
.named('${name}_allocation_${lane}_accepted')
];
final invalidAllocationLanes = [
for (var lane = 0; lane < allocationLaneCount; lane++)
this.allocations[lane].accepted & ~allocationInRange[lane]
];
final duplicateAllocationLanes = <Logic>[];
for (var lane = 0; lane < allocationLaneCount; lane++) {
Logic wasLive = Const(0);
for (var index = capacity - 1; index >= 0; index--) {
wasLive = mux(this.allocations[lane].data.tag.eq(index),
updatedLive[index], wasLive);
}
duplicateAllocationLanes.add(acceptedAllocations[lane] & wasLive);
final laneEntries = [
for (var index = 0; index < capacity; index++)
acceptedAllocations[lane] & this.allocations[lane].data.tag.eq(index)
];
updatedLive = [
for (var index = 0; index < capacity; index++)
(updatedLive[index] | laneEntries[index])
.named('${name}_live_${index}_after_allocation_$lane')
];
updatedCanceled = [
for (var index = 0; index < capacity; index++)
(updatedCanceled[index] & ~laneEntries[index])
.named('${name}_canceled_${index}_after_allocation_$lane')
];
}
final acceptedCancellationMask = mux(this.cancellationMask.accepted,
this.cancellationMask.data, Const(0, width: capacity))
.named('${name}_accepted_cancellation_mask');
final cancelUnallocated = [
for (var index = 0; index < capacity; index++)
acceptedCancellationMask[index] & ~updatedLive[index]
];
final duplicateCancel = [
for (var index = 0; index < capacity; index++)
acceptedCancellationMask[index] & updatedCanceled[index]
];
final nextLive = updatedLive;
final nextCanceled = [
for (var index = 0; index < capacity; index++)
(updatedCanceled[index] |
(acceptedCancellationMask[index] & updatedLive[index]))
.named('${name}_next_canceled_$index')
];
liveTags <= live.rconcat();
canceledTags <= canceled.rconcat();
liveTagsAfterUpdates <= nextLive.rconcat();
canceledTagsAfterUpdates <= nextCanceled.rconcat();
for (var index = 0; index < capacity; index++) {
entryData[index] <= metadata.registeredEntryData[index];
}
final lookupLiveBits = <Logic>[];
final lookupCanceledBits = <Logic>[];
final invalidLookupBits = <Logic>[];
for (var port = 0; port < lookupCount; port++) {
final lookupInRange = inRange(localLookupTags[port], 'lookup_$port');
Logic selectedLive = Const(0);
Logic selectedCanceled = Const(0);
for (var index = capacity - 1; index >= 0; index--) {
selectedLive =
mux(localLookupTags[port].eq(index), live[index], selectedLive);
selectedCanceled = mux(
localLookupTags[port].eq(index), canceled[index], selectedCanceled);
}
lookupLiveBits.add(lookupInRange & selectedLive);
lookupCanceledBits.add(lookupInRange & selectedLive & selectedCanceled);
invalidLookupBits.add(~lookupInRange);
lookupData[port] <= metadata.registeredLookupData[port];
}
lookupLive <= lookupLiveBits.rconcat();
lookupCanceled <= lookupCanceledBits.rconcat();
invalidLookups <= invalidLookupBits.rconcat();
final liveSum = live
.map((entry) => entry.zeroExtend(countWidth))
.reduce((left, right) => left + right)
.named('${name}_live_sum');
liveCount <= liveSum;
empty <= liveSum.eq(0);
full <= liveSum.eq(capacity);
invalidAllocations <= invalidAllocationLanes.rconcat();
duplicateAllocations <= duplicateAllocationLanes.rconcat();
cancelUnallocatedMask <= cancelUnallocated.rconcat();
duplicateCancelMask <= duplicateCancel.rconcat();
doubleReleaseMask <= acceptedReleaseMask & ~live.rconcat();
Sequential(localClk, reset: localReset, resetValues: {
for (final entry in live) entry: 0,
for (final entry in canceled) entry: 0,
}, [
for (var index = 0; index < capacity; index++) ...[
live[index] < nextLive[index],
canceled[index] < nextCanceled[index],
]
]);
}