-
Notifications
You must be signed in to change notification settings - Fork 1
/
cache.hpp
61 lines (42 loc) · 1.53 KB
/
cache.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
#pragma once
#include "cache_set.hpp"
#include "state.hpp"
#include <cstddef>
#include <iostream>
#include <list>
#include <vector>
using namespace std;
class CacheSet;
class Cache {
public:
// deals with the LRU
unsigned int associativity;
unsigned int blockSize;
unsigned int cacheSize;
unsigned int offsetBits;
unsigned int setIndexBits;
unsigned int tagBits;
unsigned int offsetMask;
unsigned int setIndexMask;
std::vector<CacheSet> cache;
// the cache is being split into tag, index and offset
// offset --> blockSize
// index --> location of the block
// tag --> is the associated memory stored in the cache
public:
Cache(unsigned int cacheSize, unsigned int associativity, unsigned int blockSize);
unsigned int getIndex(unsigned int address);
unsigned int getTag(unsigned int address);
unsigned int getIndexWithTag(unsigned int address);
unsigned int reverseGeneralAddress(unsigned int tag, unsigned int index);
bool checkCacheLine(unsigned int address);
bool invalidateCacheLine(unsigned int address);
void addCacheLine(unsigned int address, State state);
bool readCacheLine(unsigned int address);
bool updateCacheLine(unsigned int address, State state);
State getCacheLineState(unsigned int address);
bool setCacheLineState(unsigned int address, State state);
State getLRUCacheLineState(unsigned int address);
bool checkCacheLineFull(unsigned int address);
unsigned int getLRUCacheLineAddress(unsigned int address);
};