ReplacementPolicy constructor

ReplacementPolicy({
  1. required Logic clk,
  2. required Logic reset,
  3. required Logic validMask,
  4. required Logic eligibleMask,
  5. required List<ReplacementAccessInterface> accesses,
  6. required List<ReplacementAllocationInterface> allocations,
  7. required int entryCount,
  8. required String name,
  9. required String? definitionName,
  10. List<ReplacementCommitInterface> commits = const [],
})

Connects policy ports.

Implementation

ReplacementPolicy({
  required Logic clk,
  required Logic reset,
  required Logic validMask,
  required Logic eligibleMask,
  required List<ReplacementAccessInterface> accesses,
  required List<ReplacementAllocationInterface> allocations,
  required this.entryCount,
  required super.name,
  required super.definitionName,
  List<ReplacementCommitInterface> commits = const [],
}) : indexWidth = max(1, (entryCount - 1).bitLength) {
  if (entryCount < 1) {
    throw ArgumentError.value(entryCount, 'entryCount', 'Must be positive.');
  }
  if (validMask.width != entryCount || eligibleMask.width != entryCount) {
    throw ArgumentError(
        'Validity and eligibility must have one bit per entry.');
  }
  if (allocations.isEmpty ||
      accesses.any((port) => port.entryCount != entryCount) ||
      commits.any((port) => port.entryCount != entryCount) ||
      allocations.any((port) => port.entryCount != entryCount)) {
    throw ArgumentError('Allocation ports are required and all ports must '
        'match the policy entry count.');
  }
  addInput('clk', clk);
  addInput('reset', reset);
  addInput('validMask', validMask, width: entryCount);
  addInput('eligibleMask', eligibleMask, width: entryCount);
  addOutput('invalidAccess');
  addOutput('invalidCommit');

  for (final (index, port) in accesses.indexed) {
    localAccesses.add(addInterfacePorts(port,
        inputTags: {DataPortGroup.control},
        uniquify: (signal) => 'access_${index}_$signal'));
  }
  for (final (index, port) in commits.indexed) {
    localCommits.add(addInterfacePorts(port,
        inputTags: {DataPortGroup.control},
        uniquify: (signal) => 'commit_${index}_$signal'));
  }
  for (final (index, port) in allocations.indexed) {
    localAllocations.add(addInterfacePorts(port,
        inputTags: {DataPortGroup.control},
        outputTags: {DataPortGroup.data},
        uniquify: (signal) => 'allocation_${index}_$signal'));
  }
}