forked from ChampSim/ChampSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase_replacement.cc
100 lines (76 loc) · 2.83 KB
/
base_replacement.cc
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "cache.h"
uint32_t CACHE::find_victim(uint32_t cpu, uint64_t instr_id, uint32_t set, const BLOCK *current_set, uint64_t ip, uint64_t full_addr, uint32_t type)
{
// baseline LRU replacement policy for other caches
return lru_victim(cpu, instr_id, set, current_set, ip, full_addr, type);
}
void CACHE::update_replacement_state(uint32_t cpu, uint32_t set, uint32_t way, uint64_t full_addr, uint64_t ip, uint64_t victim_addr, uint32_t type, uint8_t hit)
{
if (type == WRITEBACK) {
if (hit) // wrietback hit does not update LRU state
return;
}
return lru_update(set, way);
}
uint32_t CACHE::lru_victim(uint32_t cpu, uint64_t instr_id, uint32_t set, const BLOCK *current_set, uint64_t ip, uint64_t full_addr, uint32_t type)
{
uint32_t way = 0;
// fill invalid line first
for (way=0; way<NUM_WAY; way++) {
if (block[set][way].valid == false) {
DP ( if (warmup_complete[cpu]) {
cout << "[" << NAME << "] " << __func__ << " instr_id: " << instr_id << " invalid set: " << set << " way: " << way;
cout << hex << " address: " << (full_addr>>LOG2_BLOCK_SIZE) << " victim address: " << block[set][way].address << " data: " << block[set][way].data;
cout << dec << " lru: " << block[set][way].lru << endl; });
break;
}
}
// LRU victim
if (way == NUM_WAY) {
for (way=0; way<NUM_WAY; way++) {
if (block[set][way].lru == NUM_WAY-1) {
DP ( if (warmup_complete[cpu]) {
cout << "[" << NAME << "] " << __func__ << " instr_id: " << instr_id << " replace set: " << set << " way: " << way;
cout << hex << " address: " << (full_addr>>LOG2_BLOCK_SIZE) << " victim address: " << block[set][way].address << " data: " << block[set][way].data;
cout << dec << " lru: " << block[set][way].lru << endl; });
break;
}
}
}
if (way == NUM_WAY) {
cerr << "[" << NAME << "] " << __func__ << " no victim! set: " << set << endl;
assert(0);
}
return way;
}
void CACHE::lru_update(uint32_t set, uint32_t way)
{
// update lru replacement state
for (uint32_t i=0; i<NUM_WAY; i++) {
if (block[set][i].lru < block[set][way].lru) {
block[set][i].lru++;
}
}
block[set][way].lru = 0; // promote to the MRU position
}
void CACHE::replacement_final_stats()
{
}
#ifdef NO_CRC2_COMPILE
void InitReplacementState()
{
}
uint32_t GetVictimInSet (uint32_t cpu, uint32_t set, const BLOCK *current_set, uint64_t PC, uint64_t paddr, uint32_t type)
{
return 0;
}
void UpdateReplacementState (uint32_t cpu, uint32_t set, uint32_t way, uint64_t paddr, uint64_t PC, uint64_t victim_addr, uint32_t type, uint8_t hit)
{
}
void PrintStats_Heartbeat()
{
}
void PrintStats()
{
}
#endif