GroupedCompletionTracker constructor
- required Logic clk,
- required Logic reset,
- required List<
Logic> allocate, - required List<
Logic> allocationTags, - required List<
Logic> update, - required List<
GroupedCompletionUpdate> updateData, - required Logic releaseGroups,
- required Logic releaseMask,
- required Logic cancelGroups,
- required Logic cancellationMask,
- required List<
Logic> lookupTags, - required int capacity,
- required int maxUops,
- String name = 'grouped_completion_tracker',
Creates grouped completion state driven by explicit actions.
Lane n of allocate creates the group named by lane n of
allocationTags, and lane n of update merges lane n of
updateData. releaseGroups and cancelGroups apply releaseMask and
cancellationMask, which hold one bit per group.
Implementation
GroupedCompletionTracker({
required Logic clk,
required Logic reset,
required List<Logic> allocate,
required List<Logic> allocationTags,
required List<Logic> update,
required List<GroupedCompletionUpdate> updateData,
required Logic releaseGroups,
required Logic releaseMask,
required Logic cancelGroups,
required Logic cancellationMask,
required List<Logic> lookupTags,
required this.capacity,
required this.maxUops,
super.name = 'grouped_completion_tracker',
}) : tagWidth = max(1, capacity.log2Ceil),
super(
definitionName: 'GroupedCompletionTracker_'
'C${capacity}_U${maxUops}_A${allocate.length}_'
'W${update.length}_Q${lookupTags.length}',
) {
if (capacity < 1 ||
maxUops < 1 ||
allocate.isEmpty ||
update.isEmpty ||
lookupTags.isEmpty ||
allocationTags.length != allocate.length ||
updateData.length != update.length ||
allocationTags.any((tag) => tag.width != tagWidth) ||
updateData.any((data) =>
data.groupTagWidth != tagWidth || data.maxUops != maxUops) ||
releaseMask.width != capacity ||
cancellationMask.width != capacity ||
lookupTags.any((tag) => tag.width != tagWidth)) {
throw ArgumentError(
'Grouped completion ports must match the configured geometry.');
}
final allocationLanes = allocate.length;
final updateLanes = update.length;
final localClk = addInput('clk', clk);
final localReset = addInput('reset', reset);
final localAllocate = [
for (var lane = 0; lane < allocationLanes; lane++)
addInput('allocate$lane', allocate[lane])
];
final localAllocationTags = [
for (var lane = 0; lane < allocationLanes; lane++)
addInput('allocationTag$lane', allocationTags[lane], width: tagWidth)
];
final localUpdate = [
for (var lane = 0; lane < updateLanes; lane++)
addInput('update$lane', update[lane])
];
final localUpdateData = [
for (var lane = 0; lane < updateLanes; lane++)
addTypedInput('updateData$lane', updateData[lane])
];
final localRelease = addInput('releaseGroups', releaseGroups);
final localReleaseMask =
addInput('releaseMask', releaseMask, width: capacity);
final localCancel = addInput('cancelGroups', cancelGroups);
final localCancellationMask =
addInput('cancellationMask', cancellationMask, width: capacity);
final localLookupTags = [
for (var port = 0; port < lookupTags.length; port++)
addInput('lookupTag$port', lookupTags[port], width: tagWidth)
];
addOutput('occupiedTags', width: capacity);
addOutput('lookupValid', width: lookupTags.length);
addOutput('invalidAllocations', width: allocationLanes);
addOutput('duplicateAllocations', width: allocationLanes);
addOutput('invalidUpdateTags', width: updateLanes);
addOutput('invalidUpdateUops', width: updateLanes);
addOutput('updateUnallocated', width: updateLanes);
addOutput('releaseUnoccupiedMask', width: capacity);
addOutput('cancelUnoccupiedMask', width: capacity);
addOutput('invalidLookups', width: lookupTags.length);
final occupied = [
for (var tag = 0; tag < capacity; tag++)
Logic(name: '${name}_occupied_$tag')
];
final completed = [
for (var tag = 0; tag < capacity; tag++)
Logic(name: '${name}_completed_$tag', width: maxUops)
];
final exceptions = [
for (var tag = 0; tag < capacity; tag++)
Logic(name: '${name}_exceptions_$tag', width: maxUops)
];
final flushes = [
for (var tag = 0; tag < capacity; tag++)
Logic(name: '${name}_flushes_$tag', width: maxUops)
];
entryStatus = [
for (var tag = 0; tag < capacity; tag++)
addTypedOutput(
'entryStatus$tag',
({name = ''}) =>
GroupedCompletionStatus(maxUops: maxUops, name: name))
];
lookupStatus = [
for (var port = 0; port < lookupTags.length; port++)
addTypedOutput(
'lookupStatus$port',
({name = ''}) =>
GroupedCompletionStatus(maxUops: maxUops, name: name))
];
final fullTagSpace = capacity == (1 << tagWidth);
Logic tagInRange(Logic tag) =>
fullTagSpace ? Const(1) : tag.lt(Const(capacity, width: tagWidth));
Logic uopInRange(Logic uop) => maxUops == (1 << uop.width)
? Const(1)
: uop.lt(Const(maxUops, width: uop.width));
final allocationInRange = [
for (final tag in localAllocationTags) tagInRange(tag)
];
final updateTagInRange = [
for (final data in localUpdateData) tagInRange(data.groupTag)
];
final updateUopInRange = [
for (final data in localUpdateData) uopInRange(data.uopIndex)
];
final lookupInRange = [for (final tag in localLookupTags) tagInRange(tag)];
invalidAllocations <=
[
for (var lane = allocationLanes - 1; lane >= 0; lane--)
localAllocate[lane] & ~allocationInRange[lane]
].concat();
invalidUpdateTags <=
[
for (var lane = updateLanes - 1; lane >= 0; lane--)
localUpdate[lane] & ~updateTagInRange[lane]
].concat();
invalidUpdateUops <=
[
for (var lane = updateLanes - 1; lane >= 0; lane--)
localUpdate[lane] & updateTagInRange[lane] & ~updateUopInRange[lane]
].concat();
invalidLookups <=
[
for (var port = lookupTags.length - 1; port >= 0; port--)
~lookupInRange[port]
].concat();
final duplicateAllocationBits = <Logic>[];
final updateUnallocatedBits = <Logic>[];
final occupiedBeforeCancel = <Logic>[];
final nextOccupied = <Logic>[];
final nextCompleted = <Logic>[];
final nextExceptions = <Logic>[];
final nextFlushes = <Logic>[];
for (var tag = 0; tag < capacity; tag++) {
var live = occupied[tag] & ~(localRelease & localReleaseMask[tag]);
var completedMask = mux(live, completed[tag], Const(0, width: maxUops));
var exceptionMask = mux(live, exceptions[tag], Const(0, width: maxUops));
var flushMask = mux(live, flushes[tag], Const(0, width: maxUops));
for (var lane = 0; lane < allocationLanes; lane++) {
final targets = localAllocate[lane] &
allocationInRange[lane] &
localAllocationTags[lane].eq(tag);
duplicateAllocationBits.add(targets & live);
live = mux(targets, Const(1), live);
completedMask = mux(targets, Const(0, width: maxUops), completedMask);
exceptionMask = mux(targets, Const(0, width: maxUops), exceptionMask);
flushMask = mux(targets, Const(0, width: maxUops), flushMask);
}
for (var lane = 0; lane < updateLanes; lane++) {
final data = localUpdateData[lane];
final targets = localUpdate[lane] &
updateTagInRange[lane] &
updateUopInRange[lane] &
data.groupTag.eq(tag);
updateUnallocatedBits.add(targets & ~live);
final merge = targets & live;
Logic selectedUop = Const(0, width: maxUops);
for (var uop = 0; uop < maxUops; uop++) {
selectedUop = mux(data.uopIndex.eq(uop),
Const(1 << uop, width: maxUops), selectedUop);
}
completedMask = completedMask |
mux(merge & data.completed, selectedUop, Const(0, width: maxUops));
exceptionMask = exceptionMask |
mux(merge & data.exception, selectedUop, Const(0, width: maxUops));
flushMask = flushMask |
mux(merge & data.flush, selectedUop, Const(0, width: maxUops));
}
final canceled = localCancel & localCancellationMask[tag];
occupiedBeforeCancel.add(live);
nextOccupied.add(live & ~canceled);
nextCompleted.add(mux(canceled, Const(0, width: maxUops), completedMask));
nextExceptions
.add(mux(canceled, Const(0, width: maxUops), exceptionMask));
nextFlushes.add(mux(canceled, Const(0, width: maxUops), flushMask));
}
duplicateAllocations <=
[
for (var lane = allocationLanes - 1; lane >= 0; lane--)
[
for (var tag = 0; tag < capacity; tag++)
duplicateAllocationBits[tag * allocationLanes + lane]
].rconcat().or()
].concat();
updateUnallocated <=
[
for (var lane = updateLanes - 1; lane >= 0; lane--)
[
for (var tag = 0; tag < capacity; tag++)
updateUnallocatedBits[tag * updateLanes + lane]
].rconcat().or()
].concat();
releaseUnoccupiedMask <=
mux(localRelease, localReleaseMask & ~occupiedTags,
Const(0, width: capacity));
cancelUnoccupiedMask <=
mux(
localCancel,
localCancellationMask & ~occupiedBeforeCancel.rconcat(),
Const(0, width: capacity));
occupiedTags <= occupied.rconcat();
for (var tag = 0; tag < capacity; tag++) {
entryStatus[tag].completedMask <= completed[tag];
entryStatus[tag].exceptionMask <= exceptions[tag];
entryStatus[tag].flushMask <= flushes[tag];
}
final lookupValidBits = <Logic>[];
for (var port = 0; port < lookupTags.length; port++) {
Logic valid = Const(0);
Logic selectedCompleted = Const(0, width: maxUops);
Logic selectedException = Const(0, width: maxUops);
Logic selectedFlush = Const(0, width: maxUops);
for (var tag = 0; tag < capacity; tag++) {
final matches = localLookupTags[port].eq(tag);
valid = mux(matches, occupied[tag], valid);
selectedCompleted = mux(matches, completed[tag], selectedCompleted);
selectedException = mux(matches, exceptions[tag], selectedException);
selectedFlush = mux(matches, flushes[tag], selectedFlush);
}
lookupValidBits.add(valid & lookupInRange[port]);
lookupStatus[port].completedMask <= selectedCompleted;
lookupStatus[port].exceptionMask <= selectedException;
lookupStatus[port].flushMask <= selectedFlush;
}
lookupValid <= lookupValidBits.rconcat();
Sequential(localClk, reset: localReset, resetValues: {
for (final bit in occupied) bit: 0,
for (final mask in completed) mask: 0,
for (final mask in exceptions) mask: 0,
for (final mask in flushes) mask: 0,
}, [
for (var tag = 0; tag < capacity; tag++) ...[
occupied[tag] < nextOccupied[tag],
completed[tag] < nextCompleted[tag],
exceptions[tag] < nextExceptions[tag],
flushes[tag] < nextFlushes[tag],
],
]);
}