CaseAssociativeMemory constructor
- Logic clk,
- Logic reset,
- List<
AssociativeUpdatePortInterface> updates, - List<
AssociativeLookupPortInterface> lookups, { - int entryCount = 8,
- bool enableValidTracking = false,
- MemoryConfiguration? memoryConfiguration,
- String name = 'case_associative_memory',
- bool reserveName = false,
- bool reserveDefinitionName = false,
- String? definitionName,
Creates a legacy-compatible CAM with associative role-specific ports.
Implementation
CaseAssociativeMemory(
Logic clk,
Logic reset,
List<AssociativeUpdatePortInterface> updates,
List<AssociativeLookupPortInterface> lookups, {
this.entryCount = 8,
this.enableValidTracking = false,
MemoryConfiguration? memoryConfiguration,
super.name = 'case_associative_memory',
super.reserveName,
super.reserveDefinitionName,
String? definitionName,
}) : backing = resolveMemoryConfiguration(memoryConfiguration).backing,
super(
definitionName: definitionName ??
schemaQualifiedDefinitionName(
'CaseAssociative_U${updates.length}_'
'L${lookups.length}_E${entryCount}_',
[if (lookups.isNotEmpty) lookups.first.key],
suffix: '_I${[
...updates.map((p) => p.indexWidth),
...lookups.map((p) => p.indexWidth),
].join('_')}'
'_T${enableValidTracking ? 1 : 0}'
'_${_backingName(memoryConfiguration)}',
),
) {
if (entryCount < 1 || lookups.isEmpty) {
throw ArgumentError(
'Positive entry count and a lookup port are required.');
}
final config = resolveMemoryConfiguration(memoryConfiguration);
if (backing == MemoryBacking.sram ||
(backing == MemoryBacking.automatic && config.sramFunctor != null)) {
throw UnsupportedError('Synchronous SRAM cannot provide CAM lookups.');
}
final keySchema = lookups.first.key;
for (final port in <AssociativePortInterface>[...updates, ...lookups]) {
if (!sameRohdPayloadShape(keySchema, port.key) ||
port.indexWidth < (entryCount - 1).bitLength) {
throw ArgumentError('CAM keys must have matching shapes and indices '
'must address every entry.');
}
}
if (lookups.any((port) => port.matchVector != null)) {
throw ArgumentError('Exact-case CAM does not provide a match vector.');
}
description = CaseAssociativeMemoryModelDescription(
entryCount: entryCount,
keyWidth: keySchema.width,
updateIndexWidths: [for (final port in updates) port.indexWidth],
lookupIndexWidths: [for (final port in lookups) port.indexWidth],
trackValidity: enableValidTracking,
);
final localClk = addInput('clk', clk);
final localReset = addInput('reset', reset);
final localUpdates = [
for (var i = 0; i < updates.length; i++)
addInterfacePorts(updates[i],
inputTags: {DataPortGroup.control, DataPortGroup.data},
uniquify: (s) => 'update_${s}_$i'),
];
final localLookups = [
for (var i = 0; i < lookups.length; i++)
addInterfacePorts(lookups[i],
inputTags: {DataPortGroup.control},
outputTags: {DataPortGroup.data},
uniquify: (s) => 'lookup_${s}_$i'),
];
if (enableValidTracking) {
addOutput('valid_count', width: (entryCount + 1).log2Ceil);
addOutput('full');
addOutput('empty');
}
if (backing == MemoryBacking.model) {
_buildModel(
localClk, localReset, localUpdates, localLookups, keySchema.width);
} else {
_buildRtl(
localClk, localReset, localUpdates, localLookups, keySchema.width);
}
}