ReadyValidTagAllocator<LogicType extends Logic> constructor

ReadyValidTagAllocator<LogicType extends Logic>({
  1. required ReadyValidInterface<LogicType> upstream,
  2. required IrrevocableReadyValidInterface<Logic> allocation,
  3. required ReadyValidInterface<Tagged<LogicType>> downstream,
  4. String name = 'ready_valid_tag_allocator',
})

Creates an atomic allocation and dispatch join.

Implementation

ReadyValidTagAllocator({
  required ReadyValidInterface<LogicType> upstream,
  required IrrevocableReadyValidInterface<Logic> allocation,
  required ReadyValidInterface<Tagged<LogicType>> downstream,
  super.name = 'ready_valid_tag_allocator',
}) : super(
        definitionName: 'ReadyValidTagAllocator_'
            'W${upstream.data.width}_TW${allocation.data.width}_'
            '${payloadShapesIdentity([upstream.data, downstream.data])}',
      ) {
  if (downstream.data.tag.width != allocation.data.width ||
      !rohdPayloadsCompatible([upstream.data, downstream.data.data],
          ignoreConstantNames: true)) {
    throw ArgumentError('Downstream payload and tag widths must match the '
        'upstream payload and allocator index widths.');
  }
  upstream.requireProviderComposableWith(ReadyValidContract.validThenReady,
      consumerName: name);
  allocation.requireProviderComposableWith(ReadyValidContract.irrevocable,
      consumerName: '$name allocator');
  downstream.requireConsumerComposableWith(ReadyValidContract.readyAndValid,
      providerName: name);

  this.upstream = addPairInterface(upstream, PairRole.consumer,
      uniquify: (original) => 'upstream_$original');
  this.allocation = addPairInterfaceFrom(
    IrrevocableReadyValidInterface<Logic>(
        cloneInterfacePayload(allocation.data)),
    allocation,
    PairRole.consumer,
    uniquify: (original) => 'allocation_$original',
  );
  this.downstream = addPairInterfaceFrom(
    IrrevocableReadyValidInterface<Tagged<LogicType>>(
        downstream.data.cloneTyped()),
    downstream,
    PairRole.provider,
    uniquify: (original) => 'downstream_$original',
  );

  final joinedValid = (this.upstream.valid & this.allocation.valid)
      .named('${name}_joined_valid');
  final transferReady = this.downstream.ready;

  this.downstream.valid <= joinedValid;
  this.downstream.data.data <= this.upstream.data;
  this.downstream.data.tag <= this.allocation.data;
  this.upstream.ready <= this.allocation.valid & transferReady;
  this.allocation.ready <= this.upstream.valid & transferReady;
}