-
Notifications
You must be signed in to change notification settings - Fork 2
/
RP_RANDOM.cpp
49 lines (41 loc) · 1.09 KB
/
RP_RANDOM.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
#include "stdlib.h"
#include "RP_RANDOM.h"
unsigned RP_RANDOM::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;
}
}
return rand() % ways_;
}
InsertionPosition RP_RANDOM::insertionPosition(CacheSet* set, unsigned slice)
{
unsigned subset;
for (subset = 0; subset < subsets_; subset++)
{
for (unsigned 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_;
return { subset, rand() % subset_ways_ };
}
// TODO SAVE SOME CYCLES BY NOT CALLING THESE IF POLICY ISNT RANDOM
void RP_RANDOM::updateSet(unsigned set, unsigned slice, unsigned way, bool replacement)
{}
void RP_RANDOM::updateSet(CacheLine& line, CacheSet *set, unsigned slice, unsigned subset, unsigned way, bool replacement)
{}
RPolicy* RP_RANDOM::getCopy()
{
return static_cast<RPolicy*>(new RP_RANDOM(*this));
}