-
Notifications
You must be signed in to change notification settings - Fork 1
/
Cache.h
68 lines (53 loc) · 1.83 KB
/
Cache.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
#ifndef CACHE_H_
#define CACHE_H_
#include "Set.h"
#include "Memory.h"
/* Class: Cache
*
* We have implemented Set-Associative Mapping i.e. a combination
* of direct and associative-mapping techniques.
*
* Blocks of cache are grouped into sets, and the mapping allows a
* block of the main memory to reside in any block of a specific set.
*
* Main memory Address is parsed to the following format
* -----------------------------------
* | Tag Bits | Set Bits | Word Bits |
* -----------------------------------
*
* The number of bits for tag, set and word are calculated from
* the block size, cache size and associativity.
*/
class Cache {
public:
Cache(int cache_size, int block_size, int assoc, int bits_n, Memory* memory);
int get_hits(void);
int get_misses(void);
int get_cold_misses(void);
int get_capacity_misses(void);
int get_conflict_misses(void);
int get_cached(int address);
void restart(void);
~Cache(void);
private:
Set** data;
Set* data_cap;
Memory* memory;
int cache_size; // Size of cache in bytes
int block_size; // Size of block in bytes
int set_size; // Size of set in bytes
int assoc; // Associativity
int num_words; // Number of words per block
int num_sets; // Number of sets
int num_bits; // Number of bits in Main memory address
int set_bits; // Number of bits for Set
int tag_bits; // Number of bits for Tag
int word_bits; // Number of bits for Word
int set_mul; // Number to be bitwise-multiplied with location to get set index
int tag_mul; // Number to be bitwise-multiplied with location to get tag index
int word_mul; // Number to be bitwise-multiplied with location to get word index
int tag_cap_mul;// Number to be bitwise-multiplied with location to get tag index
int hits; // Number of hits
int misses[4]; // Number of misses
};
#endif /* CACHE_H_ */