-
Notifications
You must be signed in to change notification settings - Fork 2
/
RP_BIP.cpp
105 lines (92 loc) · 2.31 KB
/
RP_BIP.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
95
96
97
98
99
100
101
102
103
104
105
#include "RP_BIP.h"
#include "stdlib.h"
unsigned RP_BIP::insertionPosition(unsigned set, unsigned slice)
{
// check for invalid lines
for (unsigned i = 0; i < ways_; i++)
{
if (!memory_[slice * lines_ + set * ways_ + i].valid)
{
return i;
}
}
unsigned way = 0;
for (unsigned i = 0; i < ways_; i++)
{
if (memory_[slice * lines_ + set * ways_ + i].time == 0)
{
way = i;
break;
}
}
return way;
}
InsertionPosition RP_BIP::insertionPosition(CacheSet* set, unsigned slice)
{
unsigned subset, way;
for (subset = 0; subset < subsets_; subset++)
{
for (way = 0; way < subset_ways_; way++)
{
if (!(*c_memory_)(slice, subset, set, way).valid)
{
return { subset, way };
}
}
}
subset = 0;
if (subsets_ != 1)
subset = rand() % subsets_;
for (way = 0; way < subset_ways_; way++)
{
if ((*c_memory_)(slice, subset, set, way).time == 0)
{
break;
}
}
return { subset, way };
}
void RP_BIP::updateSet(unsigned set, unsigned slice, unsigned way, bool replacement)
{
int old_pos = memory_[slice * lines_ + set * ways_ + way].time;
if (replacement && rand() % 32)
{
for (unsigned i = 0; i < ways_; i++)
{
if (memory_[slice * lines_ + set * ways_ + i].time < old_pos)
memory_[slice * lines_ + set * ways_ + i].time++;
}
memory_[slice * lines_ + set * ways_ + way].time = 0;
return;
}
for (unsigned i = 0; i < ways_; i++)
{
if (memory_[slice * lines_ + set * ways_ + i].time > old_pos)
memory_[slice * lines_ + set * ways_ + i].time--;
}
memory_[slice * lines_ + set * ways_ + way].time = ways_ - 1;
}
void RP_BIP::updateSet(CacheLine& line, CacheSet *set, unsigned slice, unsigned subset, unsigned way, bool replacement)
{
int old_pos = line.time;
if (replacement && rand() % 32)
{
for (unsigned i = 0; i < subset_ways_; i++)
{
if ((*c_memory_)(slice, subset, set, i).time < old_pos)
(*c_memory_)(slice, subset, set, i).time++;
}
line.time = 0;
return;
}
for (unsigned i = 0; i < subset_ways_; i++)
{
if ((*c_memory_)(slice, subset, set, i).time > old_pos)
(*c_memory_)(slice, subset, set, i).time--;
}
line.time = subset_ways_ - 1;
}
RPolicy* RP_BIP::getCopy()
{
return static_cast<RPolicy*>(new RP_BIP(*this));
}