-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
280 lines (221 loc) · 12.5 KB
/
main.cpp
File metadata and controls
280 lines (221 loc) · 12.5 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <tuple>
#include <sstream>
#include <map>
#include <cmath>
#include <iomanip>
//TAI TRAN
#include "directMap.h"
#include "fullAss.h"
#include "setAss.h"
using namespace std;
int main(){
string hexAddress, temp;
vector<int> values = {1024, 2048, 4096, 8192, 16384};
vector<string>addressStore;
bool FIFO = true;
bool LRU = false;
fstream trace;
trace.open("traceFiles/gcc.trace");
// //Capture data
while (trace >> temp) {
trace >> hexAddress;
hexAddress = hexAddress;
trace >> temp;
addressStore.push_back(hexAddress);
}
//**************BEGIN*****************
//***CACHE SIZE: 1024***
DirectMapped d_cache_1024(1024, 64);
FullyAssociative f_cache_1024_FIFO(1024, 64, FIFO);
SetAssociative s2_cache_1024_FIFO(1024, 64, 2, FIFO);
SetAssociative s4_cache_1024_FIFO(1024, 64, 4, FIFO);
SetAssociative s8_cache_1024_FIFO(1024, 64, 8, FIFO);
FullyAssociative f_cache_1024_LRU(1024, 64, LRU);
SetAssociative s2_cache_1024_LRU(1024, 64, 2, LRU);
SetAssociative s4_cache_1024_LRU(1024, 64, 4, LRU);
SetAssociative s8_cache_1024_LRU(1024, 64, 8, LRU);
for (int j = 0; j < addressStore.size(); j++){
d_cache_1024.accessCache(addressStore.at(j));
f_cache_1024_FIFO.accessCache(addressStore.at(j));
s2_cache_1024_FIFO.accessCache(addressStore.at(j), FIFO);
s4_cache_1024_FIFO.accessCache(addressStore.at(j), FIFO);
s8_cache_1024_FIFO.accessCache(addressStore.at(j), FIFO);
f_cache_1024_LRU.accessCache(addressStore.at(j));
s2_cache_1024_LRU.accessCache(addressStore.at(j), LRU);
s4_cache_1024_LRU.accessCache(addressStore.at(j), LRU);
s8_cache_1024_LRU.accessCache(addressStore.at(j), LRU);
}
cout << "________________________________________________________________" << endl;
cout << "______________________________1024______________________________" << endl;
cout << "Direct map cache: " << d_cache_1024.getHitRate() << endl;
cout << "FIFO:" << endl;
cout << "Fully associative cache: " << f_cache_1024_FIFO.getHitRate() << endl;
cout << "2 Set associative cache: " << s2_cache_1024_FIFO.getHitRate() << endl;
cout << "4 Set associative cache: " << s4_cache_1024_FIFO.getHitRate() << endl;
cout << "8 Set associative cache: " << s8_cache_1024_FIFO.getHitRate() << endl;
cout << "-------------------------------------------------" << endl;
cout << "LRU:" << endl;
cout << "Fully associative cache: " << f_cache_1024_LRU.getHitRate() << endl;
cout << "2 Set associative cache: " << s2_cache_1024_LRU.getHitRate() << endl;
cout << "4 Set associative cache: " << s4_cache_1024_LRU.getHitRate() << endl;
cout << "8 Set associative cache: " << s8_cache_1024_LRU.getHitRate() << endl;
cout << "________________________________________________________________" << endl;
//***CACHE SIZE: 1024, FIFO POLICY END***
//***************END******************
//**************BEGIN*****************
//***CACHE SIZE: 2048, FIFO POLICY BEGIN***
DirectMapped d_cache_2048(2048, 64);
FullyAssociative f_cache_2048_FIFO(2048, 64, FIFO);
SetAssociative s2_cache_2048_FIFO(2048, 64, 2, FIFO);
SetAssociative s4_cache_2048_FIFO(2048, 64, 4, FIFO);
SetAssociative s8_cache_2048_FIFO(2048, 64, 8, FIFO);
FullyAssociative f_cache_2048_LRU(2048, 64, LRU);
SetAssociative s2_cache_2048_LRU(2048, 64, 2, LRU);
SetAssociative s4_cache_2048_LRU(2048, 64, 4, LRU);
SetAssociative s8_cache_2048_LRU(2048, 64, 8, LRU);
for (int j = 0; j < addressStore.size(); j++){
d_cache_2048.accessCache(addressStore.at(j));
f_cache_2048_FIFO.accessCache(addressStore.at(j));
s2_cache_2048_FIFO.accessCache(addressStore.at(j), FIFO);
s4_cache_2048_FIFO.accessCache(addressStore.at(j), FIFO);
s8_cache_2048_FIFO.accessCache(addressStore.at(j), FIFO);
f_cache_2048_LRU.accessCache(addressStore.at(j));
s2_cache_2048_LRU.accessCache(addressStore.at(j), LRU);
s4_cache_2048_LRU.accessCache(addressStore.at(j), LRU);
s8_cache_2048_LRU.accessCache(addressStore.at(j), LRU);
}
cout << "______________________________2048______________________________" << endl;
cout << "Direct map cache: " << d_cache_2048.getHitRate() << endl;
cout << "FIFO:" << endl;
cout << "Fully associative cache: " << f_cache_2048_FIFO.getHitRate() << endl;
cout << "2 Set associative cache: " << s2_cache_2048_FIFO.getHitRate() << endl;
cout << "4 Set associative cache: " << s4_cache_2048_FIFO.getHitRate() << endl;
cout << "8 Set associative cache: " << s8_cache_2048_FIFO.getHitRate() << endl;
cout << "-------------------------------------------------" << endl;
cout << "LRU:" << endl;
cout << "Fully associative cache: " << f_cache_2048_LRU.getHitRate() << endl;
cout << "2 Set associative cache: " << s2_cache_2048_LRU.getHitRate() << endl;
cout << "4 Set associative cache: " << s4_cache_2048_LRU.getHitRate() << endl;
cout << "8 Set associative cache: " << s8_cache_2048_LRU.getHitRate() << endl;
cout << "________________________________________________________________" << endl;
//***CACHE SIZE: 2048, FIFO POLICY END***
//***************END******************
//**************BEGIN*****************
//***CACHE SIZE: 4096, FIFO POLICY BEGIN***
DirectMapped d_cache_4096(4096, 64);
FullyAssociative f_cache_4096_FIFO(4096, 64, FIFO);
SetAssociative s2_cache_4096_FIFO(4096, 64, 2, FIFO);
SetAssociative s4_cache_4096_FIFO(4096, 64, 4, FIFO);
SetAssociative s8_cache_4096_FIFO(4096, 64, 8, FIFO);
FullyAssociative f_cache_4096_LRU(4096, 64, LRU);
SetAssociative s2_cache_4096_LRU(4096, 64, 2, LRU);
SetAssociative s4_cache_4096_LRU(4096, 64, 4, LRU);
SetAssociative s8_cache_4096_LRU(4096, 64, 8, LRU);
for (int j = 0; j < addressStore.size(); j++){
d_cache_4096.accessCache(addressStore.at(j));
f_cache_4096_FIFO.accessCache(addressStore.at(j));
s2_cache_4096_FIFO.accessCache(addressStore.at(j), FIFO);
s4_cache_4096_FIFO.accessCache(addressStore.at(j), FIFO);
s8_cache_4096_FIFO.accessCache(addressStore.at(j), FIFO);
f_cache_4096_LRU.accessCache(addressStore.at(j));
s2_cache_4096_LRU.accessCache(addressStore.at(j), LRU);
s4_cache_4096_LRU.accessCache(addressStore.at(j), LRU);
s8_cache_4096_LRU.accessCache(addressStore.at(j), LRU);
}
cout << "______________________________4096______________________________" << endl;
cout << "Direct map cache: " << d_cache_4096.getHitRate() << endl;
cout << "FIFO:" << endl;
cout << "Fully associative cache: " << f_cache_4096_FIFO.getHitRate() << endl;
cout << "2 Set associative cache: " << s2_cache_4096_FIFO.getHitRate() << endl;
cout << "4 Set associative cache: " << s4_cache_4096_FIFO.getHitRate() << endl;
cout << "8 Set associative cache: " << s8_cache_4096_FIFO.getHitRate() << endl;
cout << "-------------------------------------------------" << endl;
cout << "LRU:" << endl;
cout << "Fully associative cache: " << f_cache_4096_LRU.getHitRate() << endl;
cout << "2 Set associative cache: " << s2_cache_4096_LRU.getHitRate() << endl;
cout << "4 Set associative cache: " << s4_cache_4096_LRU.getHitRate() << endl;
cout << "8 Set associative cache: " << s8_cache_4096_LRU.getHitRate() << endl;
cout << "________________________________________________________________" << endl;
//***CACHE SIZE: 4096, FIFO POLICY END***
//***************END******************
//**************BEGIN*****************
//***CACHE SIZE: 8192, FIFO POLICY BEGIN***
DirectMapped d_cache_8192(8192, 64);
FullyAssociative f_cache_8192_FIFO(8192, 64, FIFO);
SetAssociative s2_cache_8192_FIFO(8192, 64, 2, FIFO);
SetAssociative s4_cache_8192_FIFO(8192, 64, 4, FIFO);
SetAssociative s8_cache_8192_FIFO(8192, 64, 8, FIFO);
FullyAssociative f_cache_8192_LRU(8192, 64, LRU);
SetAssociative s2_cache_8192_LRU(8192, 64, 2, LRU);
SetAssociative s4_cache_8192_LRU(8192, 64, 4, LRU);
SetAssociative s8_cache_8192_LRU(8192, 64, 8, LRU);
for (int j = 0; j < addressStore.size(); j++){
d_cache_8192.accessCache(addressStore.at(j));
f_cache_8192_FIFO.accessCache(addressStore.at(j));
s2_cache_8192_FIFO.accessCache(addressStore.at(j), FIFO);
s4_cache_8192_FIFO.accessCache(addressStore.at(j), FIFO);
s8_cache_8192_FIFO.accessCache(addressStore.at(j), FIFO);
f_cache_8192_LRU.accessCache(addressStore.at(j));
s2_cache_8192_LRU.accessCache(addressStore.at(j), LRU);
s4_cache_8192_LRU.accessCache(addressStore.at(j), LRU);
s8_cache_8192_LRU.accessCache(addressStore.at(j), LRU);
}
cout << "______________________________8192______________________________" << endl;
cout << "Direct map cache: " << d_cache_8192.getHitRate() << endl;
cout << "FIFO:" << endl;
cout << "Fully associative cache: " << f_cache_8192_FIFO.getHitRate() << endl;
cout << "2 Set associative cache: " << s2_cache_8192_FIFO.getHitRate() << endl;
cout << "4 Set associative cache: " << s4_cache_8192_FIFO.getHitRate() << endl;
cout << "8 Set associative cache: " << s8_cache_8192_FIFO.getHitRate() << endl;
cout << "-------------------------------------------------" << endl;
cout << "LRU:" << endl;
cout << "Fully associative cache: " << f_cache_8192_LRU.getHitRate() << endl;
cout << "2 Set associative cache: " << s2_cache_8192_LRU.getHitRate() << endl;
cout << "4 Set associative cache: " << s4_cache_8192_LRU.getHitRate() << endl;
cout << "8 Set associative cache: " << s8_cache_8192_LRU.getHitRate() << endl;
cout << "________________________________________________________________" << endl;
//***CACHE SIZE: 8192, FIFO POLICY END***
//***************END******************
//**************BEGIN*****************
//***CACHE SIZE: 16384, FIFO POLICY BEGIN***
DirectMapped d_cache_16384(16384, 64);
FullyAssociative f_cache_16384_FIFO(16384, 64, FIFO);
SetAssociative s2_cache_16384_FIFO(16384, 64, 2, FIFO);
SetAssociative s4_cache_16384_FIFO(16384, 64, 4, FIFO);
SetAssociative s8_cache_16384_FIFO(16384, 64, 8, FIFO);
FullyAssociative f_cache_16384_LRU(16384, 64, LRU);
SetAssociative s2_cache_16384_LRU(16384, 64, 2, LRU);
SetAssociative s4_cache_16384_LRU(16384, 64, 4, LRU);
SetAssociative s8_cache_16384_LRU(16384, 64, 8, LRU);
for (int j = 0; j < addressStore.size(); j++){
d_cache_16384.accessCache(addressStore.at(j));
f_cache_16384_FIFO.accessCache(addressStore.at(j));
s2_cache_16384_FIFO.accessCache(addressStore.at(j), FIFO);
s4_cache_16384_FIFO.accessCache(addressStore.at(j), FIFO);
s8_cache_16384_FIFO.accessCache(addressStore.at(j), FIFO);
f_cache_16384_LRU.accessCache(addressStore.at(j));
s2_cache_16384_LRU.accessCache(addressStore.at(j), LRU);
s4_cache_16384_LRU.accessCache(addressStore.at(j), LRU);
s8_cache_16384_LRU.accessCache(addressStore.at(j), LRU);
}
cout << "______________________________16384______________________________" << endl;
cout << "Direct map cache: " << d_cache_16384.getHitRate() << endl;
cout << "FIFO:" << endl;
cout << "Fully associative cache: " << f_cache_16384_FIFO.getHitRate() << endl;
cout << "2 Set associative cache: " << s2_cache_16384_FIFO.getHitRate() << endl;
cout << "4 Set associative cache: " << s4_cache_16384_FIFO.getHitRate() << endl;
cout << "8 Set associative cache: " << s8_cache_16384_FIFO.getHitRate() << endl;
cout << "-------------------------------------------------" << endl;
cout << "LRU:" << endl;
cout << "Fully associative cache: " << f_cache_16384_LRU.getHitRate() << endl;
cout << "2 Set associative cache: " << s2_cache_16384_LRU.getHitRate() << endl;
cout << "4 Set associative cache: " << s4_cache_16384_LRU.getHitRate() << endl;
cout << "8 Set associative cache: " << s8_cache_16384_LRU.getHitRate() << endl;
cout << "________________________________________________________________" << endl;
//***CACHE SIZE: 16384, FIFO POLICY END***
//***************END******************
}