AgeMatrixTracker constructor

AgeMatrixTracker({
  1. required Logic clk,
  2. required Logic reset,
  3. required ReadyValidInterface<Logic> allocation,
  4. required ReadyValidInterface<TagRelease> release,
  5. required int entryCount,
  6. String name = 'age_matrix_tracker',
})

Creates a non-compacting age matrix.

Implementation

AgeMatrixTracker({
  required Logic clk,
  required Logic reset,
  required ReadyValidInterface<Logic> allocation,
  required ReadyValidInterface<TagRelease> release,
  required this.entryCount,
  super.name = 'age_matrix_tracker',
})  : indexWidth = allocation.data.width,
      super(
        definitionName:
            'AgeMatrixTracker_E${entryCount}_W${allocation.data.width}',
      ) {
  if (entryCount < 1) {
    throw ArgumentError.value(entryCount, 'entryCount', 'Must be positive.');
  }
  final minimumIndexWidth = max(1, entryCount.log2Ceil);
  if (indexWidth < minimumIndexWidth ||
      release.data.tag.width != indexWidth) {
    throw ArgumentError('Allocation and release indices must match and '
        'represent every entry.');
  }
  allocation.requireProviderComposableWith(ReadyValidContract.readyAndValid,
      consumerName: name);
  release.requireProviderComposableWith(ReadyValidContract.readyAndValid,
      consumerName: name);

  final localClk = addInput('clk', clk);
  final localReset = addInput('reset', reset);
  this.allocation = addPairInterface(allocation, PairRole.consumer,
      uniquify: (original) => 'allocation_$original');
  this.release = addPairInterface(release, PairRole.consumer,
      uniquify: (original) => 'release_$original');
  addOutput('validEntries', width: entryCount);
  addOutput('olderThan', width: entryCount * entryCount);
  addOutput('invalidAllocation');
  addOutput('duplicateAllocation');
  addOutput('invalidRelease');
  addOutput('doubleRelease');
  final capacityFillsIndexSpace = entryCount == (1 << indexWidth);
  final releaseInRange = capacityFillsIndexSpace
      ? Const(1)
      : this.release.data.tag.lt(Const(entryCount, width: indexWidth));
  final releaseMask = ReadyAndValidInterface(Logic(width: entryCount));
  releaseMask.valid <= this.release.valid;
  releaseMask.data <=
      [
        for (var index = 0; index < entryCount; index++)
          this.release.data.tag.eq(index),
      ].rconcat();
  this.release.ready <= releaseMask.ready;
  final tracker = MultiAgeMatrixTracker(
    clk: localClk,
    reset: localReset,
    allocations: [this.allocation],
    releaseMask: releaseMask,
    entryCount: entryCount,
    duplicateAllocationPolicy: DuplicateAgeAllocationPolicy.makeYoungest,
    name: '${name}_tracker',
  );
  validEntries <= tracker.validEntries;
  olderThan <= tracker.olderThan;
  invalidAllocation <= tracker.invalidAllocations;
  duplicateAllocation <= tracker.duplicateAllocations;
  invalidRelease <= this.release.accepted & ~releaseInRange;
  doubleRelease <= tracker.doubleReleaseMask.or();
}