ReadyValidMultiMetadataTable<LogicType extends Logic> constructor

ReadyValidMultiMetadataTable<LogicType extends Logic>({
  1. required Logic clk,
  2. required Logic reset,
  3. required List<ReadyValidInterface<Tagged<LogicType>>> writes,
  4. required List<Logic> lookupTags,
  5. required int capacity,
  6. List<LogicValue>? writeMasks,
  7. LogicValue? resetValue,
  8. RegisterFileFunctor? storageImplementation,
  9. String name = 'ready_valid_multi_metadata_table',
})

Creates typed, ordered, direct-indexed metadata storage.

Implementation

ReadyValidMultiMetadataTable({
  required Logic clk,
  required Logic reset,
  required List<ReadyValidInterface<Tagged<LogicType>>> writes,
  required List<Logic> lookupTags,
  required this.capacity,
  List<LogicValue>? writeMasks,
  LogicValue? resetValue,
  RegisterFileFunctor? storageImplementation,
  super.name = 'ready_valid_multi_metadata_table',
})  : tagWidth = writes.isEmpty ? 0 : writes.first.data.tag.width,
      writeLaneCount = writes.length,
      lookupCount = lookupTags.length,
      writeMasks = writeMasks ??
          List<LogicValue>.filled(
            writes.length,
            LogicValue.filled(
              writes.isEmpty ? 0 : writes.first.data.data.width,
              LogicValue.one,
            ),
          ),
      resetValue = resetValue ??
          LogicValue.filled(
            writes.isEmpty ? 0 : writes.first.data.data.width,
            LogicValue.zero,
          ),
      super(
        definitionName: _multiMetadataDefinitionName(
          capacity,
          writes,
          lookupTags.length,
          writeMasks,
          resetValue,
          storageImplementation,
        ),
      ) {
  for (final write in writes) {
    write.requireProviderComposableWith(ReadyValidContract.readyAndValid,
        consumerName: name);
  }

  final localClk = addInput('clk', clk);
  final localReset = addInput('reset', reset);
  final localLookupTags = [
    for (var port = 0; port < lookupCount; port++)
      addInput('lookupTag$port', lookupTags[port],
          width: lookupTags[port].width),
  ];
  this.writes = [
    for (var lane = 0; lane < writeLaneCount; lane++)
      addPairInterface(writes[lane], PairRole.consumer,
          uniquify: (original) => 'write_${lane}_$original'),
  ];

  final writeActions = [
    for (var lane = 0; lane < writeLaneCount; lane++)
      Logic(name: '${name}_write_$lane'),
  ];
  final writeData = [
    for (final write in this.writes) cloneTypedPayload(write.data),
  ];
  final core = MultiMetadataTable<LogicType>(
    clk: localClk,
    reset: localReset,
    writes: writeActions,
    writeData: writeData,
    lookupTags: localLookupTags,
    capacity: capacity,
    writeMasks: this.writeMasks,
    resetValue: this.resetValue,
    storageImplementation: storageImplementation,
    name: '${name}_core',
  );
  // The core takes every write, so each lane is always ready.
  for (var lane = 0; lane < writeLaneCount; lane++) {
    ReadyValidIngressAttachmentPolicy<Tagged<LogicType>>(
      supportsSameCycleReplacement: true,
      coreGatesAccept: true,
    ).attach(
      upstream: this.writes[lane],
      canAccept: Const(1),
      accept: writeActions[lane],
      payload: writeData[lane],
    );
  }

  final schema = this.writes.first.data.data;
  entryData = [
    for (var index = 0; index < capacity; index++)
      addTypedPayloadOutput(this, 'entryData$index', schema)
        ..gets(core.entryData[index]),
  ];
  registeredEntryData = [
    for (var index = 0; index < capacity; index++)
      addTypedPayloadOutput(this, 'registeredEntryData$index', schema)
        ..gets(core.registeredEntryData[index]),
  ];
  lookupData = [
    for (var port = 0; port < lookupCount; port++)
      addTypedPayloadOutput(this, 'lookupData$port', schema)
        ..gets(core.lookupData[port]),
  ];
  registeredLookupData = [
    for (var port = 0; port < lookupCount; port++)
      addTypedPayloadOutput(this, 'registeredLookupData$port', schema)
        ..gets(core.registeredLookupData[port]),
  ];
  addOutput('invalidWrites', width: writeLaneCount) <= core.invalidWrites;
  addOutput('invalidLookups', width: lookupCount) <= core.invalidLookups;
}