AtomicDispatchCoordinator<LogicType extends Logic> constructor

AtomicDispatchCoordinator<LogicType extends Logic>({
  1. required ReadyValidInterface<CompactedLanes<LogicType>> dispatch,
  2. required List<Logic> resourceReadyMasks,
  3. String name = 'atomic_dispatch_coordinator',
})

Creates an atomic dense-dispatch acceptance boundary.

Implementation

AtomicDispatchCoordinator({
  required ReadyValidInterface<CompactedLanes<LogicType>> dispatch,
  required List<Logic> resourceReadyMasks,
  super.name = 'atomic_dispatch_coordinator',
})  : laneCount = dispatch.data.laneCount,
      resourceCount = resourceReadyMasks.length,
      super(
        definitionName: _atomicDispatchDefinitionName(
            dispatch.data, resourceReadyMasks.length),
      ) {
  if (resourceReadyMasks.isEmpty || dispatch.data.laneCount < 1) {
    throw ArgumentError('Dispatch lanes and resources must be positive.');
  }
  if (resourceReadyMasks
      .any((mask) => mask.width != dispatch.data.laneCount)) {
    throw ArgumentError(
        'Every resource-ready mask must match the dispatch lane count.');
  }
  dispatch.requireProviderComposableWith(ReadyValidContract.irrevocable,
      consumerName: name);

  this.dispatch = addPairInterface(dispatch, PairRole.consumer,
      uniquify: (original) => 'dispatch_$original');
  this.resourceReadyMasks = [
    for (var index = 0; index < resourceReadyMasks.length; index++)
      addInput('resourceReady$index', resourceReadyMasks[index],
          width: laneCount)
  ];
  addOutput('acceptedLanes', width: laneCount);
  addOutput('blockedResources', width: resourceCount);
  addOutput('allResourcesReady');
  addOutput('invalidDispatchCount');

  final countValid = this.dispatch.data.validCount.neq(0) &
      this.dispatch.data.validCount.lte(laneCount);
  final requiredLanes = [
    for (var lane = 0; lane < laneCount; lane++)
      this.dispatch.data.validCount.gt(lane)
  ].rconcat();
  final resourceReady = [
    for (final mask in this.resourceReadyMasks)
      (mask & requiredLanes).eq(requiredLanes)
  ];
  final allReady = resourceReady.rconcat().and() & countValid;
  final blocked =
      [for (final ready in resourceReady) ~ready & countValid].rconcat();
  final accepted = this.dispatch.valid & allReady;

  this.dispatch.ready <= allReady;
  acceptedLanes <= mux(accepted, requiredLanes, Const(0, width: laneCount));
  blockedResources <= blocked;
  allResourcesReady <= allReady;
  invalidDispatchCount <= this.dispatch.valid & ~countValid;
}