-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.h
More file actions
72 lines (62 loc) · 1.37 KB
/
cache.h
File metadata and controls
72 lines (62 loc) · 1.37 KB
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
#ifndef CACHE
#define CACHE 1
#include <vector>
#include <unordered_map>
#include "memory.h"
#include "monitor.h"
namespace cache {
using std::vector;
using std::unordered_map;
using memory::Addr;
using memory::Byte;
using memory::Memory;
using monitor::Monitor;
using uint = unsigned int;
struct Line {
Line(uint b): block(1<<b) {};
uint valid : 1;
uint dirty : 1;
Addr tag;
vector<Byte> block;
};
class LRU {
public:
LRU(uint s, uint e);
void access(Addr sid, uint k);
uint get_room(Addr sid);
private:
struct Node {
Node * pre = NULL;
Node * nxt = NULL;
};
struct FixQueue {
vector<Node> node;
uint head, tail;
FixQueue(uint sz);
uint front();
void mv_back(uint x);
};
vector<FixQueue> q;
};
class Cache {
public:
Cache(uint s, uint e, uint b, Addr sz);
Byte read(Addr x);
void write(Addr x, Byte v);
void show();
private:
uint s, e, b, t;
Memory mem;
vector<vector<Line>> line;
LRU scheduler;
Monitor monitor;
Addr get_set(Addr x);
Addr get_tag(Addr x);
Addr get_off(Addr x);
uint find(vector<Line> & set, Addr tag);
uint load(Addr sid, Addr x);
void write_back(Addr sid, uint k);
void access(Addr sid, uint k);
};
}
#endif