-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolicy_base.hpp
More file actions
30 lines (22 loc) · 929 Bytes
/
Copy pathpolicy_base.hpp
File metadata and controls
30 lines (22 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#pragma once
#include <cstdint>
#include <optional>
// Abstract base class for cache replacement policies.
// Policies track tags per set and decide on hit/miss/eviction.
class CacheReplacementPolicy {
public:
using WayIndex = int16_t;
struct EvictionResult {
WayIndex way_index;
std::optional<uint16_t> evicted_tag;
};
virtual ~CacheReplacementPolicy() = default;
// Returns the way index for the given tag if present; may update usage.
virtual WayIndex get_way_index(uint16_t tag) = 0;
// Records an access: returns the way index used and the evicted tag (if any).
virtual EvictionResult record_access(uint16_t tag) = 0;
// Checks whether the tag exists in the set.
virtual bool is_in_cache(uint16_t tag) const = 0;
// Returns the tag by way index if valid; std::nullopt otherwise.
virtual std::optional<uint16_t> get_tag(WayIndex way_index) const = 0;
};