-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache.hpp
65 lines (48 loc) · 1.56 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
62
63
#ifndef CACHE_HEADER
#define CACHE_HEADER
#include<bits/stdc++.h>
using namespace std;
enum replacement_algo {FIFO = 1, LRU = 2};
enum cache_type {direct_mapped = 1, fully_associative = 2, set_associative = 3};
string decimal_to_hex_string(int);
struct cache{
bool validBit;
int tag;
string data;
cache(){}
cache(int validBit, int tag, string data)
: validBit(validBit), tag(tag), data(data) {}
};
class cache_impl{
public:
int block_size; // in words
int num_sets;
int set_ways;
int cache_size; //in words
int num_lines;
int block_offset_bits;
int word_size = 4;
cache_type c_type;
replacement_algo repl_algo;
vector<int> address;
ifstream file;
map<int, cache> direct_cache; // map<line_num, cache>
map<int, list<cache>> set_associative_cache; // map<set_num, list of values in the set>
vector<deque<cache>> set_associative_cache_FIFO;
map<int, cache> fully_associative_cache; // map<tag, cache>
int ind;
deque<cache> fully_associative_cache_fifo;
list<int> fa_keys;
int miss = 0, hit = 0;
cache_impl();
void set_cache_parameters(int, int, int);
void retrieve_value_from_direct_cache(int);
void retrieve_value_from_set_associative_cache_LRU(int);
void retrieve_value_from_set_associative_cache_FIFO(int);
void retrieve_value_from_fully_associative_cache_LRU(int);
void retrieve_value_from_fully_associative_cache_FIFO(int);
void call_appropriate_cache(int);
void print_appropriate_cache_state();
~cache_impl();
};
#endif