MemoryViolationDetector constructor

MemoryViolationDetector({
  1. required Logic storeValid,
  2. required Logic storeAddress,
  3. required Logic storeByteEnable,
  4. required Logic storeSequence,
  5. required Logic loadValid,
  6. required Logic loadExecuted,
  7. required Logic loadAddressValid,
  8. required List<Logic> loadAddresses,
  9. required List<Logic> loadByteEnables,
  10. required List<Logic> loadSequences,
  11. required int maximumLiveEntries,
  12. String name = 'memory_violation_detector',
})

Creates an oldest-younger memory violation detector.

Implementation

MemoryViolationDetector({
  required Logic storeValid,
  required Logic storeAddress,
  required Logic storeByteEnable,
  required Logic storeSequence,
  required Logic loadValid,
  required Logic loadExecuted,
  required Logic loadAddressValid,
  required List<Logic> loadAddresses,
  required List<Logic> loadByteEnables,
  required List<Logic> loadSequences,
  required int maximumLiveEntries,
  super.name = 'memory_violation_detector',
})  : loadCount = loadValid.width,
      super(
        definitionName: 'MemoryViolationDetector_L${loadValid.width}_'
            'A${storeAddress.width}_B${storeByteEnable.width}_'
            'S${storeSequence.width}_M$maximumLiveEntries',
      ) {
  if (loadCount < 1 ||
      loadExecuted.width != loadCount ||
      loadAddressValid.width != loadCount ||
      loadAddresses.length != loadCount ||
      loadByteEnables.length != loadCount ||
      loadSequences.length != loadCount ||
      loadAddresses.any((address) => address.width != storeAddress.width) ||
      loadByteEnables
          .any((enable) => enable.width != storeByteEnable.width) ||
      loadSequences
          .any((sequence) => sequence.width != storeSequence.width)) {
    throw ArgumentError('Every load requires consistent state and widths.');
  }
  if (storeSequence.width < 2 ||
      maximumLiveEntries < 1 ||
      maximumLiveEntries >= (1 << (storeSequence.width - 1))) {
    throw ArgumentError.value(maximumLiveEntries, 'maximumLiveEntries',
        'Must fit in less than half the wrapping sequence space.');
  }
  final localStoreValid = addInput('storeValid', storeValid);
  final localStoreAddress =
      addInput('storeAddress', storeAddress, width: storeAddress.width);
  final localStoreByteEnable = addInput('storeByteEnable', storeByteEnable,
      width: storeByteEnable.width);
  final localStoreSequence =
      addInput('storeSequence', storeSequence, width: storeSequence.width);
  final localLoadValid = addInput('loadValid', loadValid, width: loadCount);
  final localLoadExecuted =
      addInput('loadExecuted', loadExecuted, width: loadCount);
  final localLoadAddressValid =
      addInput('loadAddressValid', loadAddressValid, width: loadCount);
  final localAddresses = [
    for (var index = 0; index < loadCount; index++)
      addInput('loadAddress$index', loadAddresses[index],
          width: storeAddress.width)
  ];
  final localByteEnables = [
    for (var index = 0; index < loadCount; index++)
      addInput('loadByteEnable$index', loadByteEnables[index],
          width: storeByteEnable.width)
  ];
  final localSequences = [
    for (var index = 0; index < loadCount; index++)
      addInput('loadSequence$index', loadSequences[index],
          width: storeSequence.width)
  ];

  final candidates = <Logic>[];
  for (var index = 0; index < loadCount; index++) {
    final younger = isOlderWrappingAge(
        candidateAge: localStoreSequence,
        selectedAge: localSequences[index],
        name: '${name}_load_${index}_younger');
    candidates.add((localStoreValid &
            localLoadValid[index] &
            localLoadExecuted[index] &
            localLoadAddressValid[index] &
            younger)
        .named('${name}_candidate_$index'));
  }
  final matcher = MemoryAddressMatcher(
    queryAddress: localStoreAddress,
    queryByteEnable: localStoreByteEnable,
    candidateValid: candidates.rconcat(),
    candidateAddresses: localAddresses,
    candidateByteEnables: localByteEnables,
    name: '${name}_address_matcher',
  );
  final selector = typed.AssociativeMatchSelector<Logic>(
    matchVector: matcher.byteOverlaps,
    selectionValues: localSequences,
    preference: ({
      required candidateValue,
      required selectedValue,
      required candidateIndex,
      required selectedIndex,
      required name,
    }) =>
        isOlderWrappingAge(
      candidateAge: candidateValue,
      selectedAge: selectedValue,
      name: '${name}_candidate_$candidateIndex',
    ),
    selectionName: 'oldest_wrapping',
    name: '${name}_oldest_load',
  );
  addOutput('violation') <= selector.valid;
  addOutput('violatingLoadIndex', width: selector.indexWidth) <=
      selector.selectedIndex;
  addOutput('violatingLoadOneHot', width: loadCount) <=
      selector.selectedOneHot;
  addOutput('violatingLoads', width: loadCount) <= matcher.byteOverlaps;
}