-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenericCache.hpp
69 lines (55 loc) · 1.64 KB
/
GenericCache.hpp
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
struct BLOCKS{
bool v;
bool d;
uint32_t tag;
uint32_t address;
int lru;
};
struct StreamBuffers{ // N stream buffers to be created and initialized
bool v;
int lru;
int queue_pointer;
uint32_t *memoryblocks; // memory blocks of stream buffer of size M
//uint32_t *addressBlocks;
};
class GenericCache
{
private:
uint32_t blocksize;
uint32_t size;
uint32_t assoc;
int N;
int M;
int cache_level;
struct StreamBuffers *streamBuffers;
struct BLOCKS **cacheBlocks;
GenericCache *nextCache;
//uint32_t block_offset_addr;
//uint32_t index_addr;
//uint32_t tag_addr;
int number_of_sets;
int block_offset_width; int index_width; int tag_width;
bool stream_buffer_present = false;
int activeStreamBuffer;//n
int activeMemoryBlock;//m
int constant_M; //experimental
void LRU_Update(uint32_t, int); //accepts index and the LRU
void LRU_Update_stream_buffer(int);
void CacheWriteAdj(uint32_t);
void CacheReadAdj(uint32_t);
uint32_t evictVictim(uint32_t);
public:
int reads=0; int read_misses=0; int writes=0; int write_misses=0;
double miss_rate=0; int writebacks = 0;
int prefetch_read=0; int prefetch_read_misses=0;
GenericCache();
GenericCache(uint32_t, uint32_t, uint32_t, int, int, int, GenericCache*);
void addressDecoder(uint32_t, uint32_t*, uint32_t*, uint32_t*);
void addressDecoder_sb(uint32_t, uint32_t*, uint32_t*);
void cacheRead(uint32_t);
void cacheWrite(uint32_t);
bool readStreamBuffer(uint32_t);
void prefetch(uint32_t);
void PrintContents();
void PrintStreamBufferContents();
};