MultiScoreboard constructor
- required Logic clk,
- required Logic reset,
- required List<
Logic> markBusy, - required List<
Logic> busyTags, - required List<
Logic> markReady, - required List<
Logic> readyTags, - required List<
Logic> queryTags, - required int capacity,
- Logic? restore,
- Logic? restoreBusyResources,
- RegisterFileFunctor? storageImplementation,
- String name = 'multi_scoreboard',
Creates a multi-lane direct-indexed scoreboard driven by explicit actions.
Supply restore and restoreBusyResources together to generate the
atomic bitmap replacement. storageImplementation selects the busy
bitmap backing; the default is synthesizable flop state.
Implementation
MultiScoreboard(
{required Logic clk,
required Logic reset,
required List<Logic> markBusy,
required List<Logic> busyTags,
required List<Logic> markReady,
required List<Logic> readyTags,
required List<Logic> queryTags,
required this.capacity,
Logic? restore,
Logic? restoreBusyResources,
RegisterFileFunctor? storageImplementation,
super.name = 'multi_scoreboard'})
: tagWidth = busyTags.isEmpty ? 0 : busyTags.first.width,
busyLaneCount = markBusy.length,
readyLaneCount = markReady.length,
super(
definitionName: 'MultiScoreboard_C${capacity}_'
'B${markBusy.length}_R${markReady.length}_'
'Q${queryTags.length}_'
'T${busyTags.isEmpty ? 0 : busyTags.first.width}'
'${restore == null ? '' : '_Restore'}'
'${storageImplementation == null ? '' : '_'}'
'${storageImplementation?.identity ?? ''}') {
if (capacity < 1 ||
busyLaneCount < 1 ||
readyLaneCount < 1 ||
queryTags.isEmpty ||
(restoreBusyResources != null &&
restoreBusyResources.width != capacity)) {
throw ArgumentError(
'Capacity and busy, ready, and query lane counts must be positive.');
}
if (busyTags.length != busyLaneCount ||
readyTags.length != readyLaneCount ||
(restore == null) != (restoreBusyResources == null)) {
throw ArgumentError(
'Every busy, ready, and restore action requires its tag or bitmap.');
}
final minimumTagWidth = max(1, capacity.log2Ceil);
if (tagWidth < minimumTagWidth ||
busyTags.any((tag) => tag.width != tagWidth) ||
readyTags.any((tag) => tag.width != tagWidth) ||
queryTags.any((query) => query.width != tagWidth)) {
throw ArgumentError(
'Busy, ready, and query tags must match and represent capacity.');
}
final localClk = addInput('clk', clk);
final localReset = addInput('reset', reset);
final localQueries = [
for (var index = 0; index < queryTags.length; index++)
addInput('queryTag$index', queryTags[index], width: tagWidth)
];
final localMarkBusy = [
for (var lane = 0; lane < busyLaneCount; lane++)
addInput('markBusy$lane', markBusy[lane])
];
final localBusyTags = [
for (var lane = 0; lane < busyLaneCount; lane++)
addInput('busyTag$lane', busyTags[lane], width: tagWidth)
];
final localMarkReady = [
for (var lane = 0; lane < readyLaneCount; lane++)
addInput('markReady$lane', markReady[lane])
];
final localReadyTags = [
for (var lane = 0; lane < readyLaneCount; lane++)
addInput('readyTag$lane', readyTags[lane], width: tagWidth)
];
final localRestore = restore == null ? null : addInput('restore', restore);
final localRestoreBusyResources = restoreBusyResources == null
? null
: addInput('restoreBusyResources', restoreBusyResources,
width: capacity);
addOutput('busyResources', width: capacity);
addOutput('busyResourcesAfterUpdates', width: capacity);
addOutput('queryBusy', width: queryTags.length);
addOutput('invalidBusy', width: busyLaneCount);
addOutput('duplicateBusy', width: busyLaneCount);
addOutput('invalidReady', width: readyLaneCount);
addOutput('duplicateReady', width: readyLaneCount);
addOutput('invalidQueries', width: queryTags.length);
final busy = Logic(name: '${name}_busy_resources', width: capacity);
final fillsTagSpace = capacity == (1 << tagWidth);
Logic inRange(Logic tag, String operation) => fillsTagSpace
? Const(1)
: tag
.lt(Const(capacity, width: tagWidth))
.named('${name}_${operation}_in_range');
Logic selectedState(List<Logic> state, Logic tag, String operation) {
Logic selected = Const(0);
for (var index = capacity - 1; index >= 0; index--) {
selected = mux(tag.eq(index), state[index], selected)
.named('${name}_${operation}_through_$index');
}
return selected;
}
var updatedBusy = [
for (var index = 0; index < capacity; index++) busy[index]
];
final validReadyUpdates = <Logic>[];
final invalidReadyUpdates = <Logic>[];
final duplicateReadyUpdates = <Logic>[];
for (var lane = 0; lane < readyLaneCount; lane++) {
final range = inRange(localReadyTags[lane], 'ready_$lane');
final accepted = (localMarkReady[lane] & range)
.named('${name}_ready_${lane}_accepted');
final wasBusy = selectedState(
updatedBusy, localReadyTags[lane], 'ready_${lane}_selected');
validReadyUpdates.add(accepted);
invalidReadyUpdates.add(localMarkReady[lane] & ~range);
duplicateReadyUpdates.add(accepted & ~wasBusy);
updatedBusy = [
for (var index = 0; index < capacity; index++)
(updatedBusy[index] & ~(accepted & localReadyTags[lane].eq(index)))
.named('${name}_busy_${index}_after_ready_$lane')
];
}
final validBusyUpdates = <Logic>[];
final invalidBusyUpdates = <Logic>[];
final duplicateBusyUpdates = <Logic>[];
for (var lane = 0; lane < busyLaneCount; lane++) {
final range = inRange(localBusyTags[lane], 'busy_$lane');
final accepted =
(localMarkBusy[lane] & range).named('${name}_busy_${lane}_accepted');
final wasBusy = selectedState(
updatedBusy, localBusyTags[lane], 'busy_${lane}_selected');
validBusyUpdates.add(accepted);
invalidBusyUpdates.add(localMarkBusy[lane] & ~range);
duplicateBusyUpdates.add(accepted & wasBusy);
updatedBusy = [
for (var index = 0; index < capacity; index++)
(updatedBusy[index] | (accepted & localBusyTags[lane].eq(index)))
.named('${name}_busy_${index}_after_busy_$lane')
];
}
final nextBusy = updatedBusy.rconcat().named('${name}_next_busy');
final acceptedRestore = localRestore ?? Const(0);
final visibleBusy = mux(
acceptedRestore,
localRestoreBusyResources ?? Const(0, width: capacity),
nextBusy,
).named('${name}_visible_busy');
final visibleBusyBits = [
for (var index = 0; index < capacity; index++) visibleBusy[index],
];
busyResources <= busy;
busyResourcesAfterUpdates <= visibleBusy;
invalidBusy <= invalidBusyUpdates.rconcat();
duplicateBusy <= duplicateBusyUpdates.rconcat();
invalidReady <= invalidReadyUpdates.rconcat();
duplicateReady <= duplicateReadyUpdates.rconcat();
final queryResults = <Logic>[];
final invalidQueryBits = <Logic>[];
for (var port = 0; port < localQueries.length; port++) {
final range = inRange(localQueries[port], 'query_$port');
queryResults.add(range &
selectedState(
visibleBusyBits, localQueries[port], 'query_${port}_selected'));
invalidQueryBits.add(~range);
}
queryBusy <= queryResults.rconcat();
invalidQueries <= invalidQueryBits.rconcat();
final anyUpdate = (acceptedRestore |
[...validReadyUpdates, ...validBusyUpdates]
.reduce((left, right) => left | right))
.named('${name}_any_update');
if (storageImplementation == null) {
Sequential(localClk, reset: localReset, resetValues: {
busy: 0
}, [
If(anyUpdate, then: [busy < visibleBusy])
]);
} else {
final next = Logic(name: '${name}_stored_next', width: capacity);
Combinational([
next < busy,
If(anyUpdate, then: [next < visibleBusy]),
]);
connectRegisterFileBank(
clk: localClk,
reset: localReset,
current: [busy],
next: [next],
resetValues: [LogicValue.filled(capacity, LogicValue.zero)],
implementation: storageImplementation,
name: '${name}_storage',
);
}
}