forked from jiangxincode/CacheSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LRU.cpp
96 lines (81 loc) · 2.29 KB
/
LRU.cpp
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
#include "base.h"
using namespace std;
void LruHitProcess() // if the replacement policy is LRU,and hit
{
if(t_assoc == full_associative)
{
for(i=0; i<i_num_line; i++)
{
if(LRU_priority[i]<LRU_priority[current_line] && cache_item[current_line][30]==true)
{
LRU_priority[i]++; // 如果该行比正在访问的行计数器值小,并且该行中hit为true
}
}
LRU_priority[current_line] = 0;
}
else if(t_assoc == set_associative)
{
for(i=(current_set*i_cache_set); i<((current_set+1)*i_cache_set); i++)
{
if(LRU_priority[i]<LRU_priority[current_line] && cache_item[current_line][30]==true)
{
LRU_priority[i]++; // 如果该行比正在访问的行计数器值小,并且该行中hit为true
}
}
LRU_priority[current_line] = 0;
}
}
void LruUnhitSpace() // if the replacement policy is LRU,and not hit,but there has a spaceline
{
if(t_assoc == full_associative)
{
for(i=0; i<i_num_line; i++)
{
if(cache_item[current_line][30]==true)
{
LRU_priority[i]++; // 如果该行该行中hit为true
}
}
LRU_priority[current_line] = 0;
}
else if(t_assoc == set_associative)
{
for(i=(current_set*i_cache_set); i<((current_set+1)*i_cache_set); i++)
{
if(cache_item[current_line][30]==true)
{
LRU_priority[i]++; // 如果该行该行中hit为true
}
}
LRU_priority[current_line] = 0;
}
}
void LruUnhitUnspace()
{
if(t_assoc == full_associative)
{
temp = LRU_priority[0];
for(i=0; i<i_num_line; i++)
{
if(LRU_priority[i]>=temp)
{
temp = LRU_priority[i];
j = i;
}
}
current_line = j;
}
if(t_assoc == set_associative)
{
temp = LRU_priority[current_set*i_cache_set];
for(i=(current_set*i_cache_set); i<((current_set+1)*i_cache_set); i++)
{
if(LRU_priority[i]>=temp)
{
temp = LRU_priority[i];
j = i;
}
}
current_line = j;
}
}