Repository navigation
Expand file tree
/
Copy pathCache.h
More file actions
109 lines (85 loc) · 2.37 KB
/
Copy pathCache.h
File metadata and controls
109 lines (85 loc) · 2.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
LRU Cache Simulator
3/4/19
Developers: Bruno E. Gracia Villalobos
Ryan Walker
*/
#ifndef CACHE_H
#define CACHE_H
#include <cstdint>
#include <math.h>
#include <vector>
#include <fstream>
#include <iostream>
#include <bitset>
#include <sstream>
#include <stdio.h>
#include <unordered_map>
#include <list>
#include <algorithm> //for finding in a list
using namespace std;
namespace G
{
class Cache {
typedef bitset<32> bits;
struct mem_address
{
bits mem;
bits tag;
bits index;
bits offset;
};
// typedef unordered_map<mem_address, int> entry;
typedef mem_address* entry;
typedef bits tagentry;
private:
/*User input values*/
int capacity;
int block_size;
int assoc;
/*Calculated values*/
int blocks;
int sets;
int lines; //Sinashan: Cache lines
int offset;
int index;
int tag;
int memoryLength;
int hits;
int misses;
int blocksfilled;
/*Cache storage*/
vector<bits> memory; //Stores the entire memory from example.trc
vector<int> bSize; //Sinashan: Block size associated with that address
vector<list<tagentry>> tagCache; //Stores the entire cache as a vector of lists(sets)
vector<list<tagentry>::iterator> tagIt; //Stores the iterators for each set
unordered_map<bits, mem_address*> mapCache; //Experimental
vector<bits> tags; //Stores the tag bits as a bitset
vector<int> intTags; //Stores the tag bits as ints
vector<bits> indexes; //Stores the index bits as a bitset
vector<int> intIndexes; //Stores the index bits as ints
vector<bits> offsets; //Stores the offset bits as a bitset
vector<int> intOffsets; //Stores offset bits as ints
mem_address* bank; //Array of structures representing each memory address
/*Member functions*/
int bitsToInt(bits& h);
bits getTag(bits& h);
bits getIndex(bits& h);
bits getOffset(bits& h);
bits hexToBin(string& s);
void createCache();
/*LRU Functions*/
void checkEntry(mem_address& adr);
void deleteMemEntry(mem_address*& adr);
void printMemAdr(mem_address& adr);
void printSet(list<entry>& l);
void printSet(list<tagentry>& l);
public:
/*Constructor and Destructor*/
Cache(int& C, int& b, int& N);
~Cache();
void readMemory(); //Sinashan: Different file names for different workloads
void testMem();
};
}
#endif