HeadMetadataCache<T extends Logic> constructor
Creates a single-write, combinational-read metadata cache.
Implementation
HeadMetadataCache({
required Logic clk,
required Logic reset,
required Logic lookupIndex,
required Logic writeEnable,
required Logic writeIndex,
required T writeEntry,
required this.entryCount,
MemoryConfiguration? memoryConfiguration,
super.name = 'head_metadata_cache',
}) : indexWidth = max(1, entryCount.log2Ceil),
super(
definitionName: schemaQualifiedDefinitionName(
'HeadMetadataCache_E$entryCount'
'${_storageSuffix(memoryConfiguration)}_',
[writeEntry]),
) {
if (entryCount < 1) {
throw ArgumentError.value(entryCount, 'entryCount', 'Must be positive.');
}
if (lookupIndex.width != indexWidth || writeIndex.width != indexWidth) {
throw ArgumentError(
'Lookup and write indices must both be $indexWidth bits wide.',
);
}
final localClk = addInput('clk', clk);
final localReset = addInput('reset', reset);
final localLookupIndex =
addInput('lookupIndex', lookupIndex, width: indexWidth);
final localWriteEnable = addInput('writeEnable', writeEnable);
final localWriteIndex =
addInput('writeIndex', writeIndex, width: indexWidth);
final localWriteEntry = addTypedInput('writeEntry', writeEntry);
final write = DataPortInterface<T>.typed(localWriteEntry, indexWidth);
final read = DataPortInterface<T>.typed(localWriteEntry, indexWidth);
write.en <= localWriteEnable;
write.addr <= localWriteIndex;
write.data <= localWriteEntry;
read.en <= Const(1);
read.addr <= localLookupIndex;
final storage = resolveRegisterFileImplementation(
memoryConfiguration: memoryConfiguration);
if (storage == null) {
RegisterFile<T>(
localClk,
localReset,
[write],
[read],
entryCount: entryCount,
name: '${name}_entries',
);
} else {
storage(
clk: localClk,
reset: localReset,
writePorts: [write],
readPorts: [read],
entryCount: entryCount,
readUnderWrite: RegisterFileReadUnderWrite.readFirst,
name: '${name}_entries',
);
}
addTypedPayloadOutput(this, 'lookupEntry', localWriteEntry) <= read.data;
}