CohereSim: A Bus-based Cache Simulator  v3.3
A tool for education in computing - learn about coherence protocols, replacement policies, and SMP vs DSM
replacement_policy.h
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include "cache_abc.h"
7 
10 public:
11 
18  virtual ~ReplacementPolicy() {}
19 
23  virtual uint32_t getVictim(uint32_t set_idx) { return 0; }
24 
28  virtual void touch(uint32_t set_idx, uint32_t way_idx) {}
29 
32  virtual void printState(uint32_t set_idx) {}
33 
34 protected:
35 
38 
40  uint32_t num_sets;
42  uint32_t assoc;
43 };
44 
47 #define ADD_REPLACER_TO_CMD_LINE(rep_pol) static int register_replacement = []() { \
48 if (replacement_map == nullptr) replacement_map = new std::map<std::string, rep_factory_t, ci_less>(); \
49 (*replacement_map)[#rep_pol] = [](CacheABC& cache, uint32_t num_sets, uint32_t assoc) \
50 { return new rep_pol(cache, num_sets, assoc); }; return 0; }()
Declaration of the cache interface class.
The cache interface.
Definition: cache_abc.h:9
The base class for replacement policies.
Definition: replacement_policy.h:9
virtual uint32_t getVictim(uint32_t set_idx)
Determine which line of a range of lines to replace.
Definition: replacement_policy.h:23
virtual void touch(uint32_t set_idx, uint32_t way_idx)
Notify the replacement policy that a line was just accessed.
Definition: replacement_policy.h:28
ReplacementPolicy(CacheABC &cache, uint32_t num_sets, uint32_t assoc)
Construct a new replacement policy.
Definition: replacement_policy.h:16
uint32_t num_sets
The number of sets in the cache.
Definition: replacement_policy.h:40
virtual void printState(uint32_t set_idx)
Print out the replacer's internal state.
Definition: replacement_policy.h:32
uint32_t assoc
The associativity of the cache.
Definition: replacement_policy.h:42
CacheABC & cache
The parent cache.
Definition: replacement_policy.h:37