-
Notifications
You must be signed in to change notification settings - Fork 2
/
RP_PLRU.h
57 lines (46 loc) · 1.67 KB
/
RP_PLRU.h
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
#ifndef CODE_RP_PLRU_H
#define CODE_RP_PLRU_H
#include "RPolicy.h"
#include <cstring>
class RP_PLRU : public RPolicy
{
public:
RP_PLRU(CacheConfig config) : RPolicy(config)
{
way_bits_ = config.way_bits;
subset_way_bits_ = way_bits_;
slices_ = config.slices;
//memory allocated in initCopy(), original version does not need this
plru_sets_ = NULL;
name_ = "RP_PLRU";
};
~RP_PLRU() override {
if (plru_sets_ != NULL)
free(plru_sets_);
};
unsigned insertionPosition(unsigned set, unsigned slice) override;
InsertionPosition insertionPosition(CacheSet* set, unsigned slice) override;
void updateSet(unsigned set, unsigned slice, unsigned way, bool replacement) override;
void updateSet(CacheLine& line, CacheSet *set, unsigned slice, unsigned subset, unsigned way, bool replacement) override;
/* Sets the number of subsets in the cache configuration, this has to be done manually in the *Cache.cpp */
void setSubsets(unsigned subsets) override
{
if (subsets == 1)
return;
subsets_ = subsets;
subset_ways_ = ways_ / subsets_;
subset_way_bits_ = log2(subset_ways_);
plru_sets_ = (uint64_t*) realloc(plru_sets_, sets_ * subsets_ * slices_ * sizeof(*plru_sets_));
};
void reset() override { memset(plru_sets_, 0, sets_*subsets_*slices_*sizeof(*plru_sets_)); };
RPolicy* getCopy() override;
void initCopy() {
plru_sets_ = (uint64_t*)malloc(sets_ * subsets_ * slices_ * sizeof(*plru_sets_));
};
private:
unsigned way_bits_;
unsigned subset_way_bits_;
unsigned slices_;
uint64_t *plru_sets_;
};
#endif //CODE_RP_PLRU_H