-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcacheSim.cpp
More file actions
76 lines (61 loc) · 1.91 KB
/
cacheSim.cpp
File metadata and controls
76 lines (61 loc) · 1.91 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
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include "cache.h"
int total_loads = 0;
int total_stores = 0;
int load_hits = 0;
int load_misses = 0;
int store_hits = 0;
int store_misses = 0;
int total_cycles = 0;
void solve(Cache* c, char ty, unsigned int hexMemAdd, int f)
{
QueryRecord* q = c->genQuery(ty, hexMemAdd, f);
c->execute(q);
if (q->isTypeRead)
{
total_loads++;
if (q->gotHit) load_hits++; else load_misses++;
}
else
{
total_stores++;
if (q->gotHit) store_hits++; else store_misses++;
}
total_cycles += q->n_cycles;
delete q;
// q->display();
}
int main(int argc, char *argv[])
{
std::string s1 = argv[4];
std::string s2 = argv[5];
std::string s3 = argv[6];
bool a = (s1 == "write-allocate") ? true : false;
bool b = (s2 == "write-through") ? true : false;
bool c = (s3 == "lru") ? true : false;
for (int i = 0; i < 7; i++)
{
std::cout << argv[i] << " ";
}
std::cout << "\n";
Cache* cac = new Cache(std::stoi(argv[1]), std::stoi(argv[2]), std::stoi(argv[3]), a, b, c);
char ty;
while (std::cin >> ty) {
unsigned int hexMemAdd; int f;
std::cin>> std::hex >> hexMemAdd >> std::dec >> f;
// std::cout << ty << " " << hexMemAdd << " " << f << "\n";
solve(cac, ty, hexMemAdd, f);
}
delete cac;
std::cout << "Total loads: " << total_loads << std::endl;
std::cout << "Total stores: " << total_stores << std::endl;
std::cout << "Load hits: " << load_hits << std::endl;
std::cout << "Load misses: " << load_misses << std::endl;
std::cout << "Store hits: " << store_hits << std::endl;
std::cout << "Store misses: " << store_misses << std::endl;
std::cout << "Total cycles: " << total_cycles << std::endl;
return 0;
}