-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathreplacement_state.h
138 lines (110 loc) · 4.09 KB
/
replacement_state.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#ifndef REPL_STATE_H
#define REPL_STATE_H
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// //
// This file is distributed as part of the Cache Replacement Championship //
// workshop held in conjunction with ISCA'2010. //
// //
// //
// Everyone is granted permission to copy, modify, and/or re-distribute //
// this software. //
// //
// Please contact Aamer Jaleel <[email protected]> should you have any //
// questions //
// //
////////////////////////////////////////////////////////////////////////////////
#include <cstdlib>
#include <cassert>
#include "utils.h"
#include "crc_cache_defs.h"
#include <iostream>
#include <bitset>
#include <sstream>
using namespace std;
#define GET_TAUS(name, var) \
{ \
char *value = getenv(name); \
stringstream strValue; \
strValue << value; \
strValue >> var; \
}
// Replacement Policies Supported
typedef enum {
CRC_REPL_LRU = 0,
CRC_REPL_RANDOM = 1,
CRC_REPL_CONTESTANT = 2
} ReplacemntPolicy;
// Replacement State Per Cache Line
typedef struct
{
UINT32 LRUstackposition;
// CONTESTANTS: Add extra state per cache line here
bool reuse_bit;
bitset<4> lru;
} LINE_REPLACEMENT_STATE;
struct Features
{
bitset<8> PC_0;
bitset<8> PC_1;
bitset<8> PC_2;
bitset<8> PC_3;
bitset<8> tag_rs_4;
bitset<8> tag_rs_7;
};
struct sampler
{
bool valid;
bitset<4> lru;
Features features;
int y_out;
Addr_t partial_tag;
}; // Jimenez's structures
// The implementation for the cache replacement policy
class CACHE_REPLACEMENT_STATE
{
public:
LINE_REPLACEMENT_STATE **repl;
sampler **sampler_sets;
int **weight_table;
// bitset<15> *plru;
Addr_t pc_hist[4];
private:
UINT32 numsets;
UINT32 assoc;
UINT32 replPolicy;
COUNTER mytimer; // tracks # of references to the cache
// CONTESTANTS: Add extra state for cache here
public:
ostream &PrintStats(ostream &out);
// The constructor CAN NOT be changed
CACHE_REPLACEMENT_STATE(UINT32 _sets, UINT32 _assoc, UINT32 _pol);
INT32 GetVictimInSet(UINT32 tid, UINT32 setIndex, const LINE_STATE *vicSet, UINT32 assoc, Addr_t PC, Addr_t paddr, UINT32 accessType);
void UpdateReplacementState(UINT32 setIndex, INT32 updateWayID);
void SetReplacementPolicy(UINT32 _pol) { replPolicy = _pol; }
void IncrementTimer() { mytimer++; }
void UpdateReplacementState(UINT32 setIndex, INT32 updateWayID, const LINE_STATE *currLine,
UINT32 tid, Addr_t PC, UINT32 accessType, bool cacheHit);
~CACHE_REPLACEMENT_STATE(void);
private:
void InitReplacementState();
INT32 Get_Random_Victim(UINT32 setIndex);
INT32 Get_LRU_Victim(UINT32 setIndex);
INT32 Get_My_Victim(UINT32 setIndex, Addr_t PC, Addr_t paddr);
void UpdateLRU(UINT32 setIndex, INT32 updateWayID);
void UpdateMyPolicy(UINT32 setIndex, INT32 updateWayID, const LINE_STATE *currLine,
Addr_t PC, bool cacheHit);
// utilities
void update_PCs(const Addr_t current_PC);
Features compute_features(const Addr_t PC, const Addr_t address, const bool PC_is_updated);
// prediction and training
int predict(const Features &features);
void train(const Features &features, bool increment);
// Cache LRU get and update
int get_cache_LRU_index(const int index);
void update_cache_LRU_state(const int unsigned index, const unsigned int way);
// LRU get and update
int get_LRU_index(const int index);
void update_LRU_state(const int index, const int way);
};
#endif