lookup method

({DataType? data, bool hit, int way}) lookup({
  1. required int set,
  2. required int tag,
})

Finds the lowest valid way of set whose tag is tag.

As in SetAssociativeCacheSidecars, a miss reports way zero and no payload.

Implementation

({bool hit, int way, DataType? data}) lookup(
    {required int set, required int tag}) {
  for (var way = 0; way < wayCount; way++) {
    final index = image.slot(set, way);
    if (_allocatedSlots.contains(index) && _tags[index] == tag) {
      return (hit: true, way: way, data: _payloads[index]);
    }
  }
  return (hit: false, way: 0, data: null);
}