StoreSetPredictor constructor
- required Logic clk,
- required Logic reset,
- required Logic lookupInstruction,
- required ReadyValidInterface<
StoreSetAssignment> assignment, - required ReadyValidInterface<
StoreSetLastStore> lastStoreUpdate, - required ReadyValidInterface<
StoreSetLastStore> lastStoreRelease, - required int instructionCount,
- required int setCount,
- String name = 'store_set_predictor',
Creates a Store Set dependency predictor.
Implementation
StoreSetPredictor({
required Logic clk,
required Logic reset,
required Logic lookupInstruction,
required ReadyValidInterface<StoreSetAssignment> assignment,
required ReadyValidInterface<StoreSetLastStore> lastStoreUpdate,
required ReadyValidInterface<StoreSetLastStore> lastStoreRelease,
required this.instructionCount,
required this.setCount,
super.name = 'store_set_predictor',
}) : super(
definitionName: 'StoreSetPredictor_I${instructionCount}_'
'S${setCount}_T${lastStoreUpdate.data.storeTagWidth}',
) {
if (instructionCount < 1 || setCount < 1) {
throw ArgumentError('Store Set table capacities must be positive.');
}
final instructionWidth = max(1, instructionCount.log2Ceil);
final setIdWidth = max(1, setCount.log2Ceil);
if (lookupInstruction.width < instructionWidth ||
assignment.data.instructionWidth != lookupInstruction.width ||
assignment.data.setIdWidth < setIdWidth ||
lastStoreUpdate.data.setIdWidth != assignment.data.setIdWidth ||
lastStoreRelease.data.setIdWidth != assignment.data.setIdWidth ||
lastStoreRelease.data.storeTagWidth !=
lastStoreUpdate.data.storeTagWidth) {
throw ArgumentError('Store Set lookup and update shapes must match.');
}
for (final interface in [assignment, lastStoreUpdate, lastStoreRelease]) {
interface.requireProviderComposableWith(ReadyValidContract.readyAndValid,
consumerName: name);
}
final localClk = addInput('clk', clk);
final localReset = addInput('reset', reset);
final localLookup = addInput('lookupInstruction', lookupInstruction,
width: lookupInstruction.width);
this.assignment = addPairInterface(assignment, PairRole.consumer,
uniquify: (original) => 'assignment_$original');
this.lastStoreUpdate = addPairInterface(lastStoreUpdate, PairRole.consumer,
uniquify: (original) => 'last_store_update_$original');
this.lastStoreRelease = addPairInterface(
lastStoreRelease, PairRole.consumer,
uniquify: (original) => 'last_store_release_$original');
for (final interface in [
this.assignment,
this.lastStoreUpdate,
this.lastStoreRelease
]) {
interface.ready <= Const(1);
}
addOutput('lookupSetValid');
addOutput('lookupSetId', width: assignment.data.setIdWidth);
addOutput('dependencyValid');
addOutput('dependencyStoreTag', width: lastStoreUpdate.data.storeTagWidth);
addOutput('invalidLookupInstruction');
addOutput('invalidAssignment');
addOutput('invalidLastStoreUpdate');
addOutput('invalidLastStoreRelease');
addOutput('lastStoreReleaseMismatch');
final mappingsValid = [
for (var index = 0; index < instructionCount; index++)
Logic(name: '${name}_mapping_valid_$index')
];
final mappingSetIds = [
for (var index = 0; index < instructionCount; index++)
Logic(
name: '${name}_mapping_set_$index',
width: assignment.data.setIdWidth)
];
final lastStoresValid = [
for (var set = 0; set < setCount; set++)
Logic(name: '${name}_last_store_valid_$set')
];
final lastStoreTags = [
for (var set = 0; set < setCount; set++)
Logic(
name: '${name}_last_store_tag_$set',
width: lastStoreUpdate.data.storeTagWidth)
];
Logic inRange(Logic value, int count, String operation) =>
count == (1 << value.width)
? Const(1)
: value
.lt(Const(count, width: value.width))
.named('${name}_${operation}_in_range');
final lookupInRange =
inRange(localLookup, instructionCount, 'lookup_instruction');
final assignmentInstructionInRange = inRange(
this.assignment.data.instruction, instructionCount, 'assignment');
final assignmentSetInRange =
inRange(this.assignment.data.setId, setCount, 'assignment_set');
final updateSetInRange =
inRange(this.lastStoreUpdate.data.setId, setCount, 'update_set');
final releaseSetInRange =
inRange(this.lastStoreRelease.data.setId, setCount, 'release_set');
Logic mappedValid = Const(0);
Logic mappedSet = Const(0, width: assignment.data.setIdWidth);
for (var index = 0; index < instructionCount; index++) {
final matches = localLookup.eq(index);
mappedValid = mux(matches, mappingsValid[index], mappedValid);
mappedSet = mux(matches, mappingSetIds[index], mappedSet);
}
final assignmentBypass = this.assignment.accepted &
assignmentInstructionInRange &
this.assignment.data.instruction.eq(localLookup);
mappedValid = mux(assignmentBypass,
~this.assignment.data.invalidate & assignmentSetInRange, mappedValid);
mappedSet = mux(assignmentBypass, this.assignment.data.setId, mappedSet);
Logic predictedValid = Const(0);
Logic predictedTag = Const(0, width: lastStoreUpdate.data.storeTagWidth);
for (var set = 0; set < setCount; set++) {
final matches = mappedSet.eq(set);
predictedValid = mux(matches, lastStoresValid[set], predictedValid);
predictedTag = mux(matches, lastStoreTags[set], predictedTag);
}
final matchingRelease = this.lastStoreRelease.accepted &
releaseSetInRange &
this.lastStoreRelease.data.setId.eq(mappedSet) &
this.lastStoreRelease.data.storeTag.eq(predictedTag);
predictedValid = mux(matchingRelease, Const(0), predictedValid);
final matchingUpdate = this.lastStoreUpdate.accepted &
updateSetInRange &
this.lastStoreUpdate.data.setId.eq(mappedSet);
predictedValid = mux(matchingUpdate, Const(1), predictedValid);
predictedTag =
mux(matchingUpdate, this.lastStoreUpdate.data.storeTag, predictedTag);
lookupSetValid <= lookupInRange & mappedValid;
lookupSetId <= mappedSet;
dependencyValid <= lookupInRange & mappedValid & predictedValid;
dependencyStoreTag <= predictedTag;
invalidLookupInstruction <= ~lookupInRange;
invalidAssignment <=
this.assignment.valid &
(~assignmentInstructionInRange |
(~this.assignment.data.invalidate & ~assignmentSetInRange));
invalidLastStoreUpdate <= this.lastStoreUpdate.valid & ~updateSetInRange;
invalidLastStoreRelease <= this.lastStoreRelease.valid & ~releaseSetInRange;
Logic currentReleaseValid = Const(0);
Logic currentReleaseTag =
Const(0, width: lastStoreRelease.data.storeTagWidth);
for (var set = 0; set < setCount; set++) {
final matches = this.lastStoreRelease.data.setId.eq(set);
currentReleaseValid =
mux(matches, lastStoresValid[set], currentReleaseValid);
currentReleaseTag = mux(matches, lastStoreTags[set], currentReleaseTag);
}
lastStoreReleaseMismatch <=
this.lastStoreRelease.accepted &
releaseSetInRange &
(~currentReleaseValid |
currentReleaseTag.neq(this.lastStoreRelease.data.storeTag));
Sequential(localClk, reset: localReset, resetValues: {
for (final valid in mappingsValid) valid: 0,
for (final setId in mappingSetIds) setId: 0,
for (final valid in lastStoresValid) valid: 0,
for (final tag in lastStoreTags) tag: 0,
}, [
for (var index = 0; index < instructionCount; index++)
If(
this.assignment.accepted &
assignmentInstructionInRange &
this.assignment.data.instruction.eq(index),
then: [
mappingsValid[index] <
~this.assignment.data.invalidate & assignmentSetInRange,
mappingSetIds[index] < this.assignment.data.setId,
]),
for (var set = 0; set < setCount; set++) ...[
If(
this.lastStoreRelease.accepted &
releaseSetInRange &
this.lastStoreRelease.data.setId.eq(set) &
lastStoresValid[set] &
lastStoreTags[set].eq(this.lastStoreRelease.data.storeTag),
then: [lastStoresValid[set] < 0]),
If(
this.lastStoreUpdate.accepted &
updateSetInRange &
this.lastStoreUpdate.data.setId.eq(set),
then: [
lastStoresValid[set] < 1,
lastStoreTags[set] < this.lastStoreUpdate.data.storeTag,
]),
],
]);
}