AssociativeMemory<KeyType extends Logic> constructor
- required Logic clk,
- required Logic reset,
- required int entryCount,
- required AssociativeMemoryContract contract,
- List<
AssociativeUpdatePortInterface> ? updatePorts, - List<
AssociativeLookupPortInterface> ? lookupPorts, - @Deprecated('Use updatePorts instead.') List<
AssociativeUpdatePortInterface> ? updates, - @Deprecated('Use lookupPorts instead.') List<
AssociativeLookupPortInterface> ? lookups, - String name = 'associative_memory',
- bool reserveName = false,
- bool reserveDefinitionName = false,
- String? definitionName,
Creates the common associative-memory port boundary.
updatePorts and lookupPorts are required; updates and lookups
are their deprecated former names.
Implementation
AssociativeMemory({
required Logic clk,
required Logic reset,
required this.entryCount,
required this.contract,
List<AssociativeUpdatePortInterface>? updatePorts,
List<AssociativeLookupPortInterface>? lookupPorts,
@Deprecated('Use updatePorts instead.')
List<AssociativeUpdatePortInterface>? updates,
@Deprecated('Use lookupPorts instead.')
List<AssociativeLookupPortInterface>? lookups,
super.name = 'associative_memory',
super.reserveName,
super.reserveDefinitionName,
super.definitionName,
}) : keyWidth = _keyWidth(
resolveAssociativePortList(updatePorts, updates, 'updatePorts'),
resolveAssociativePortList(lookupPorts, lookups, 'lookupPorts')),
indexWidth = _indexWidth(
resolveAssociativePortList(updatePorts, updates, 'updatePorts'),
resolveAssociativePortList(lookupPorts, lookups, 'lookupPorts')) {
final updateList =
resolveAssociativePortList(updatePorts, updates, 'updatePorts');
final lookupList =
resolveAssociativePortList(lookupPorts, lookups, 'lookupPorts');
if (lookupList.isEmpty) {
throw ArgumentError('At least one associative lookup port is required.');
}
if (entryCount < 1 ||
(BigInt.one << indexWidth) < BigInt.from(entryCount)) {
throw ArgumentError('Entry count must be positive and representable.');
}
for (final port in <AssociativePortInterface>[
...updateList,
...lookupList
]) {
if (port.keyWidth != keyWidth || port.indexWidth != indexWidth) {
throw ArgumentError('All associative ports must have matching shapes.');
}
}
final ports = <AssociativePortInterface>[...updateList, ...lookupList];
if (!rohdPayloadsCompatible(ports.map((port) => port.key))) {
throw ArgumentError('All associative keys must have compatible '
'declared layouts.');
}
if (contract.resultShape ==
AssociativeResultShape.matchVectorAndSelectedIndex &&
lookupList.any((lookup) => lookup.matchEntryCount != entryCount)) {
throw ArgumentError('Every lookup port must carry one match bit per '
'entry when the contract requests match vectors.');
}
addInput('clk', clk);
addInput('reset', reset);
for (var index = 0; index < updateList.length; index++) {
localUpdates.add(addInterfacePorts(
updateList[index],
inputTags: {DataPortGroup.control, DataPortGroup.data},
outputTags: <DataPortGroup>{},
uniquify: (original) => 'update_${original}_$index',
));
}
for (var index = 0; index < lookupList.length; index++) {
localLookups.add(addInterfacePorts(
lookupList[index],
inputTags: {DataPortGroup.control},
outputTags: {DataPortGroup.data},
uniquify: (original) => 'lookup_${original}_$index',
));
}
final schema = <AssociativePortInterface>[...localUpdates, ...localLookups]
.map((port) => port.key)
.whereType<KeyType>()
.firstOrNull;
if (schema == null) {
throw ArgumentError('At least one associative port must declare a '
'$KeyType key.');
}
keySchema = schema;
}