ReadyValidGroupedCompletionTracker constructor

ReadyValidGroupedCompletionTracker({
  1. required Logic clk,
  2. required Logic reset,
  3. required List<ReadyValidInterface<Logic>> allocations,
  4. required List<ReadyValidInterface<GroupedCompletionUpdate>> updates,
  5. required ReadyValidInterface<Logic> releaseMask,
  6. required ReadyValidInterface<Logic> cancellationMask,
  7. required List<Logic> lookupTags,
  8. required int capacity,
  9. required int maxUops,
  10. String name = 'ready_valid_grouped_completion_tracker',
})

Creates a grouped completion tracker.

Implementation

ReadyValidGroupedCompletionTracker({
  required Logic clk,
  required Logic reset,
  required List<ReadyValidInterface<Logic>> allocations,
  required List<ReadyValidInterface<GroupedCompletionUpdate>> updates,
  required ReadyValidInterface<Logic> releaseMask,
  required ReadyValidInterface<Logic> cancellationMask,
  required List<Logic> lookupTags,
  required this.capacity,
  required this.maxUops,
  super.name = 'ready_valid_grouped_completion_tracker',
})  : tagWidth = max(1, capacity.log2Ceil),
      super(
        definitionName: 'ReadyValidGroupedCompletionTracker_'
            'C${capacity}_U${maxUops}_A${allocations.length}_'
            'W${updates.length}_Q${lookupTags.length}',
      ) {
  for (final interface in [
    ...allocations,
    ...updates,
    releaseMask,
    cancellationMask,
  ]) {
    interface.requireProviderComposableWith(ReadyValidContract.readyAndValid,
        consumerName: name);
  }

  final localClk = addInput('clk', clk);
  final localReset = addInput('reset', reset);
  this.allocations = [
    for (var lane = 0; lane < allocations.length; lane++)
      addPairInterface(allocations[lane], PairRole.consumer,
          uniquify: (original) => 'allocation_${lane}_$original')
  ];
  this.updates = [
    for (var lane = 0; lane < updates.length; lane++)
      addPairInterface(updates[lane], PairRole.consumer,
          uniquify: (original) => 'update_${lane}_$original')
  ];
  this.releaseMask = addPairInterface(releaseMask, PairRole.consumer,
      uniquify: (original) => 'release_$original');
  this.cancellationMask = addPairInterface(
      cancellationMask, PairRole.consumer,
      uniquify: (original) => 'cancellation_$original');
  // The core validates the geometry of every port, including these widths.
  final localLookupTags = [
    for (var port = 0; port < lookupTags.length; port++)
      addInput('lookupTag$port', lookupTags[port],
          width: lookupTags[port].width)
  ];

  final allocate = [
    for (var lane = 0; lane < allocations.length; lane++)
      Logic(name: '${name}_allocate_$lane')
  ];
  final allocationTags = [
    for (final stream in this.allocations) cloneInterfacePayload(stream.data)
  ];
  final update = [
    for (var lane = 0; lane < updates.length; lane++)
      Logic(name: '${name}_update_$lane')
  ];
  final updateData = [
    for (final stream in this.updates) cloneTypedPayload(stream.data)
  ];
  final release = Logic(name: '${name}_release');
  final releaseBits = cloneInterfacePayload(this.releaseMask.data);
  final cancel = Logic(name: '${name}_cancel');
  final cancellationBits = cloneInterfacePayload(this.cancellationMask.data);
  final core = GroupedCompletionTracker(
    clk: localClk,
    reset: localReset,
    allocate: allocate,
    allocationTags: allocationTags,
    update: update,
    updateData: updateData,
    releaseGroups: release,
    releaseMask: releaseBits,
    cancelGroups: cancel,
    cancellationMask: cancellationBits,
    lookupTags: localLookupTags,
    capacity: capacity,
    maxUops: maxUops,
    name: '${name}_core',
  );

  // The core takes every offered action, so each boundary is always ready.
  final maskIngress = ReadyValidIngressAttachmentPolicy<Logic>(
    supportsSameCycleReplacement: false,
    coreGatesAccept: true,
  );
  final allocationIngress = ReadyValidIngressAttachmentPolicy<Logic>(
    supportsSameCycleReplacement: true,
    coreGatesAccept: true,
  );
  final updateIngress =
      ReadyValidIngressAttachmentPolicy<GroupedCompletionUpdate>(
    supportsSameCycleReplacement: false,
    coreGatesAccept: true,
  );
  for (var lane = 0; lane < allocations.length; lane++) {
    allocationIngress.attach(
      upstream: this.allocations[lane],
      canAccept: Const(1),
      accept: allocate[lane],
      payload: allocationTags[lane],
    );
  }
  for (var lane = 0; lane < updates.length; lane++) {
    updateIngress.attach(
      upstream: this.updates[lane],
      canAccept: Const(1),
      accept: update[lane],
      payload: updateData[lane],
    );
  }
  maskIngress
    ..attach(
      upstream: this.releaseMask,
      canAccept: Const(1),
      accept: release,
      payload: releaseBits,
    )
    ..attach(
      upstream: this.cancellationMask,
      canAccept: Const(1),
      accept: cancel,
      payload: cancellationBits,
    );

  addOutput('occupiedTags', width: capacity) <= core.occupiedTags;
  addOutput('lookupValid', width: lookupTags.length) <= core.lookupValid;
  addOutput('invalidAllocations', width: allocations.length) <=
      core.invalidAllocations;
  addOutput('duplicateAllocations', width: allocations.length) <=
      core.duplicateAllocations;
  addOutput('invalidUpdateTags', width: updates.length) <=
      core.invalidUpdateTags;
  addOutput('invalidUpdateUops', width: updates.length) <=
      core.invalidUpdateUops;
  addOutput('updateUnallocated', width: updates.length) <=
      core.updateUnallocated;
  addOutput('releaseUnoccupiedMask', width: capacity) <=
      core.releaseUnoccupiedMask;
  addOutput('cancelUnoccupiedMask', width: capacity) <=
      core.cancelUnoccupiedMask;
  addOutput('invalidLookups', width: lookupTags.length) <=
      core.invalidLookups;
  entryStatus = [
    for (var tag = 0; tag < capacity; tag++)
      addTypedPayloadOutput(this, 'entryStatus$tag', core.entryStatus[tag])
        ..gets(core.entryStatus[tag])
  ];
  lookupStatus = [
    for (var port = 0; port < lookupTags.length; port++)
      addTypedPayloadOutput(
          this, 'lookupStatus$port', core.lookupStatus[port])
        ..gets(core.lookupStatus[port])
  ];
}