instantiate method
- required Logic clk,
- required Logic reset,
- required List<
AssociativeUpdatePortInterface> updatePorts, - required List<
AssociativeLookupPortInterface> lookupPorts, - required String name,
- AssociativeIndexedSideReadRequest? sideReadRequest,
- List<
AssociativeIndexedSideReadRequest> ? sideReadRequests,
Instantiates this binding on ports matching the resolved request.
Implementation
AssociativeMemory instantiate({
required Logic clk,
required Logic reset,
required List<AssociativeUpdatePortInterface> updatePorts,
required List<AssociativeLookupPortInterface> lookupPorts,
required String name,
AssociativeIndexedSideReadRequest? sideReadRequest,
List<AssociativeIndexedSideReadRequest>? sideReadRequests,
}) {
if (memory != null) {
throw StateError(
'An associative-memory binding may be instantiated once.');
}
if (sideReadRequest != null && sideReadRequests != null) {
throw ArgumentError('Use either sideReadRequest or sideReadRequests.');
}
final sides = sideReadRequests ??
(sideReadRequest == null
? <AssociativeIndexedSideReadRequest>[]
: [sideReadRequest]);
final legacyUnboundSideRead =
request._legacySideReadRequirement && sides.isEmpty;
if ((!legacyUnboundSideRead &&
request.indexedSideReadCount != sides.length) ||
sides.any((side) => side.index.width != request.indexWidth)) {
throw ArgumentError(
'Indexed side-read port does not match the resolved request.');
}
final actualRequest = AssociativeMemoryRequest.fromPorts(
updatePorts: updatePorts,
lookupPorts: lookupPorts,
entryCount: request.entryCount,
lookupLatency: request.lookupLatency,
updateLatency: request.updateLatency,
duplicateKeyPolicy: request.duplicateKeyPolicy,
matchSelection: request.matchSelection,
resultShape: request.resultShape,
lookupUpdatePolicy: request.lookupUpdatePolicy,
updateCollisionPolicy: request.updateCollisionPolicy,
requiredResetBehavior: request.requiredResetBehavior,
requiredResetTiming: request.requiredResetTiming,
requiresIndexedSideRead: request.requiresIndexedSideRead,
indexedSideReadCount: request.indexedSideReadCount,
requiresValidityMask: request.requiresValidityMask,
);
if (!request._hasSameShape(actualRequest)) {
throw ArgumentError(
'Bound associative ports do not match the resolved request shape.');
}
if (sides.isNotEmpty && implementation._buildMultiple == null) {
throw ArgumentError('Associative-memory implementation '
'${implementation.identity} has no indexed-side-read builder.');
}
final built = sides.isNotEmpty
? implementation._buildMultiple!(
clk: clk,
reset: reset,
updatePorts: updatePorts,
lookupPorts: lookupPorts,
sideReadRequests: sides,
request: request,
contract: contract,
name: name,
)
: implementation._build(
clk: clk,
reset: reset,
updatePorts: updatePorts,
lookupPorts: lookupPorts,
request: request,
contract: contract,
name: name,
);
if (built.entryCount != request.entryCount ||
built.keyWidth != request.keyWidth ||
built.indexWidth != request.indexWidth ||
built.numUpdates != request.updatePortCount ||
built.numLookups != request.lookupPortCount ||
built.lookupLatency != contract.lookupLatency ||
built.updateLatency != contract.updateLatency) {
throw StateError('Associative-memory implementation '
'${implementation.identity} built a module that does not match its '
'resolved binding.');
}
if (request.requiresValidityMask) {
if (built is! AssociativeValidityMaskProvider) {
throw StateError('Associative-memory implementation '
'${implementation.identity} did not provide a validity mask.');
}
final mask = (built as AssociativeValidityMaskProvider).validMask;
if (mask == null || mask.width != request.entryCount) {
throw StateError('Associative-memory implementation '
'${implementation.identity} provided an invalid validity mask.');
}
}
if (sides.length == 1) {
if (built is! AssociativeIndexedSideReadProvider) {
throw StateError('Associative-memory implementation '
'${implementation.identity} did not provide its indexed '
'side read.');
}
final response =
(built as AssociativeIndexedSideReadProvider).sideReadResponse;
if (response == null || response.key.width != request.keyWidth) {
throw StateError('Associative-memory implementation '
'${implementation.identity} provided an invalid side-read '
'response.');
}
}
if (sides.length > 1) {
if (built is! AssociativeMultiIndexedSideReadProvider) {
throw StateError('Associative-memory implementation '
'${implementation.identity} did not provide indexed side reads.');
}
final responses =
(built as AssociativeMultiIndexedSideReadProvider).sideReadResponses;
if (responses.length != sides.length ||
responses.any((response) => response.key.width != request.keyWidth)) {
throw StateError('Associative-memory implementation '
'${implementation.identity} provided invalid side-read responses.');
}
}
memory = built;
return built;
}