ExternalAssociativeMemory constructor

ExternalAssociativeMemory({
  1. required Logic clk,
  2. required Logic reset,
  3. required List<AssociativeUpdatePortInterface> updatePorts,
  4. required List<AssociativeLookupPortInterface> lookupPorts,
  5. required int entryCount,
  6. required int keyWidth,
  7. required int indexWidth,
  8. required int lookupLatency,
  9. required String definitionName,
  10. String? matchSelection,
  11. String? updateCollisionPolicy,
  12. String? resetBehavior,
  13. Map<String, String>? parameters,
  14. String name = 'external_associative_memory',
})

Creates an external associative-memory macro adapter.

Implementation

ExternalAssociativeMemory({
  required Logic clk,
  required Logic reset,
  required List<AssociativeUpdatePortInterface> updatePorts,
  required List<AssociativeLookupPortInterface> lookupPorts,
  required this.entryCount,
  required this.keyWidth,
  required this.indexWidth,
  required this.lookupLatency,
  required super.definitionName,
  String? matchSelection,
  String? updateCollisionPolicy,
  String? resetBehavior,
  Map<String, String>? parameters,
  super.name = 'external_associative_memory',
}) : super(
        parameters: {
          'ENTRY_COUNT': '$entryCount',
          'KEY_WIDTH': '$keyWidth',
          'INDEX_WIDTH': '$indexWidth',
          'UPDATE_PORTS': '${updatePorts.length}',
          'LOOKUP_PORTS': '${lookupPorts.length}',
          'LOOKUP_LATENCY': '$lookupLatency',
          if (matchSelection != null) 'MATCH_SELECTION': '"$matchSelection"',
          if (updateCollisionPolicy != null)
            'UPDATE_COLLISION_POLICY': '"$updateCollisionPolicy"',
          if (resetBehavior != null) 'RESET_BEHAVIOR': '"$resetBehavior"',
          ...?parameters,
        },
      ) {
  if (entryCount < 1 || keyWidth < 1 || indexWidth < 1 || lookupLatency < 0) {
    throw ArgumentError('Associative macro geometry must be valid.');
  }
  if (updatePorts.any((port) =>
          port.keyWidth != keyWidth || port.indexWidth != indexWidth) ||
      lookupPorts.any((port) =>
          port.keyWidth != keyWidth || port.indexWidth != indexWidth)) {
    throw ArgumentError('All associative ports must match macro geometry.');
  }
  if (lookupPorts.isEmpty) {
    throw ArgumentError('At least one lookup port is required.');
  }

  addInput('clk', clk);
  addInput('reset', reset);
  for (var index = 0; index < updatePorts.length; index++) {
    addInterface<AssociativeUpdatePortInterface, DataPortGroup>(
      updatePorts[index],
      inputTags: {DataPortGroup.control, DataPortGroup.data},
      outputTags: const {},
      uniquify: (original) => 'update_${index}_$original',
    );
  }
  for (var index = 0; index < lookupPorts.length; index++) {
    addInterface<AssociativeLookupPortInterface, DataPortGroup>(
      lookupPorts[index],
      inputTags: {DataPortGroup.control},
      outputTags: {DataPortGroup.data},
      uniquify: (original) => 'lookup_${index}_$original',
    );
  }
}