ReadyValidMultiScoreboard constructor

ReadyValidMultiScoreboard({
  1. required Logic clk,
  2. required Logic reset,
  3. required List<ReadyValidInterface<Logic>> markBusy,
  4. required List<ReadyValidInterface<TagRelease>> markReady,
  5. required List<Logic> queryTags,
  6. required int capacity,
  7. ReadyValidInterface<Logic>? restore,
  8. RegisterFileFunctor? storageImplementation,
  9. String name = 'ready_valid_multi_scoreboard',
})

Creates a multi-lane direct-indexed scoreboard.

storageImplementation selects the busy bitmap backing; the default is synthesizable flop state.

Implementation

ReadyValidMultiScoreboard(
    {required Logic clk,
    required Logic reset,
    required List<ReadyValidInterface<Logic>> markBusy,
    required List<ReadyValidInterface<TagRelease>> markReady,
    required List<Logic> queryTags,
    required this.capacity,
    ReadyValidInterface<Logic>? restore,
    RegisterFileFunctor? storageImplementation,
    super.name = 'ready_valid_multi_scoreboard'})
    : tagWidth = markBusy.isEmpty ? 0 : markBusy.first.data.width,
      busyLaneCount = markBusy.length,
      readyLaneCount = markReady.length,
      super(
          definitionName: 'ReadyValidMultiScoreboard_C${capacity}_'
              'B${markBusy.length}_R${markReady.length}_'
              'Q${queryTags.length}_'
              'T${markBusy.isEmpty ? 0 : markBusy.first.data.width}'
              '${restore == null ? '' : '_Restore'}'
              '${storageImplementation == null ? '' : '_'}'
              '${storageImplementation?.identity ?? ''}') {
  for (final update in markBusy) {
    update.requireProviderComposableWith(ReadyValidContract.readyAndValid,
        consumerName: name);
  }
  for (final update in markReady) {
    update.requireProviderComposableWith(ReadyValidContract.readyAndValid,
        consumerName: name);
  }

  final localClk = addInput('clk', clk);
  final localReset = addInput('reset', reset);
  final localQueries = [
    for (var index = 0; index < queryTags.length; index++)
      addInput('queryTag$index', queryTags[index],
          width: queryTags[index].width)
  ];
  this.markBusy = [
    for (var lane = 0; lane < busyLaneCount; lane++)
      addPairInterface(markBusy[lane], PairRole.consumer,
          uniquify: (original) => 'mark_busy_${lane}_$original')
  ];
  this.markReady = [
    for (var lane = 0; lane < readyLaneCount; lane++)
      addPairInterface(markReady[lane], PairRole.consumer,
          uniquify: (original) => 'mark_ready_${lane}_$original')
  ];
  this.restore = restore == null
      ? null
      : addPairInterface(restore, PairRole.consumer,
          uniquify: (original) => 'restore_$original');

  final busyActions = [
    for (var lane = 0; lane < busyLaneCount; lane++)
      Logic(name: '${name}_mark_busy_$lane')
  ];
  final busyTags = [
    for (final update in this.markBusy) cloneInterfacePayload(update.data)
  ];
  final readyActions = [
    for (var lane = 0; lane < readyLaneCount; lane++)
      Logic(name: '${name}_mark_ready_$lane')
  ];
  final readyData = [
    for (final update in this.markReady) cloneTypedPayload(update.data)
  ];
  final localRestore = this.restore;
  final restoreAction =
      localRestore == null ? null : Logic(name: '${name}_restore');
  final restoreData =
      localRestore == null ? null : cloneInterfacePayload(localRestore.data);
  final core = MultiScoreboard(
    clk: localClk,
    reset: localReset,
    markBusy: busyActions,
    busyTags: busyTags,
    markReady: readyActions,
    readyTags: [for (final release in readyData) release.tag],
    queryTags: localQueries,
    capacity: capacity,
    restore: restoreAction,
    restoreBusyResources: restoreData,
    storageImplementation: storageImplementation,
    name: '${name}_core',
  );
  // The core takes every update, so each boundary is always ready.
  for (var lane = 0; lane < busyLaneCount; lane++) {
    ReadyValidIngressAttachmentPolicy<Logic>(
      supportsSameCycleReplacement: true,
      coreGatesAccept: true,
    ).attach(
      upstream: this.markBusy[lane],
      canAccept: Const(1),
      accept: busyActions[lane],
      payload: busyTags[lane],
    );
  }
  for (var lane = 0; lane < readyLaneCount; lane++) {
    ReadyValidIngressAttachmentPolicy<TagRelease>(
      supportsSameCycleReplacement: true,
      coreGatesAccept: true,
    ).attach(
      upstream: this.markReady[lane],
      canAccept: Const(1),
      accept: readyActions[lane],
      payload: readyData[lane],
    );
  }
  if (localRestore != null) {
    ReadyValidIngressAttachmentPolicy<Logic>(
      supportsSameCycleReplacement: false,
      coreGatesAccept: true,
    ).attach(
      upstream: localRestore,
      canAccept: Const(1),
      accept: restoreAction!,
      payload: restoreData!,
    );
  }

  addOutput('busyResources', width: capacity) <= core.busyResources;
  addOutput('busyResourcesAfterUpdates', width: capacity) <=
      core.busyResourcesAfterUpdates;
  addOutput('queryBusy', width: queryTags.length) <= core.queryBusy;
  addOutput('invalidBusy', width: busyLaneCount) <= core.invalidBusy;
  addOutput('duplicateBusy', width: busyLaneCount) <= core.duplicateBusy;
  addOutput('invalidReady', width: readyLaneCount) <= core.invalidReady;
  addOutput('duplicateReady', width: readyLaneCount) <= core.duplicateReady;
  addOutput('invalidQueries', width: queryTags.length) <= core.invalidQueries;
}