RoundRobinReplacement constructor

RoundRobinReplacement({
  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. List<ReplacementCommitInterface> commits = const [],
  9. String name = 'round_robin_replacement',
})

Creates a round-robin policy.

Implementation

RoundRobinReplacement({
  required super.clk,
  required super.reset,
  required super.validMask,
  required super.eligibleMask,
  required super.accesses,
  required super.allocations,
  required super.entryCount,
  super.commits,
  super.name = 'round_robin_replacement',
}) : super(
          definitionName: 'RoundRobinReplacement_E${entryCount}_'
              'H${accesses.length}_A${allocations.length}'
              '${commits.isEmpty ? '' : '_C${commits.length}'}') {
  buildPolicy(
    stateWidth: indexWidth,
    onAccess: (state, index) => state,
    select: (state, candidates) {
      final width = entryCount.bitLength;
      final pointer = state.zeroExtend(width);
      // Keep the existing flattened module ports and generated definition.
      // ignore: deprecated_member_use_from_same_package
      final selector = AssociativeMatchSelector(
        matchVector: candidates,
        selectionValues: [
          for (var index = 0; index < entryCount; index++)
            mux(
              Const(index, width: width).gte(pointer),
              Const(index, width: width) - pointer,
              Const(entryCount, width: width) -
                  pointer +
                  Const(index, width: width),
            )
        ],
        selectionName: 'roundRobin',
      );
      return (valid: selector.valid, index: selector.selectedIndex);
    },
    onAllocation: (state, index) => mux(
        storedIndexMatches(index, entryCount - 1),
        Const(0, width: indexWidth),
        index + Const(1, width: indexWidth)),
  );
}