-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcacheSim.cpp
More file actions
99 lines (80 loc) · 2.32 KB
/
cacheSim.cpp
File metadata and controls
99 lines (80 loc) · 2.32 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
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include "Cache.h"
using std::string;
using std::cout;
using std::endl;
using std::cerr;
using std::ifstream;
using std::stringstream;
int main(int argc, char *argv[]) {
if (argc < 21) {
cerr << "Not enough arguments" << endl;
return 0;
}
// File
// Assuming it is the first argument
char * fileString = argv[1];
ifstream file(fileString); //input file stream
string line;
if (!file || !file.good()) {
// File doesn't exist or some other error
cerr << "File not found" << endl;
return 0;
}
unsigned int MemCyc = 0, BSize = 0, L1Size = 0, L2Size = 0,L1Assoc = 0,L2Assoc = 0,
L1Cyc = 0,L2Cyc = 0,WrAlloc = 0,VicCache = 0;
for (int i = 2; i < 21; i += 2) {
string s(argv[i]);
if (s == "--mem-cyc") {
MemCyc = atoi(argv[i + 1]);
} else if (s == "--bsize") {
BSize = atoi(argv[i + 1]);
} else if (s == "--l1-size") {
L1Size = atoi(argv[i + 1]);
} else if (s == "--l2-size") {
L2Size = atoi(argv[i + 1]);
} else if (s == "--l1-cyc") {
L1Cyc = atoi(argv[i + 1]);
} else if (s == "--l2-cyc") {
L2Cyc = atoi(argv[i + 1]);
} else if (s == "--l1-assoc") {
L1Assoc = atoi(argv[i + 1]);
} else if (s == "--l2-assoc") {
L2Assoc = atoi(argv[i + 1]);
} else if (s == "--wr-alloc") {
WrAlloc = atoi(argv[i + 1]);
} else if (s == "--vic-cache") {
VicCache = atoi(argv[i + 1]);
} else {
cerr << "Error in arguments" << endl;
return 0;
}
}
while (getline(file, line))
{
stringstream ss(line);
string address;
char operation = 0; // read (R) or write (W)
if (!(ss >> operation >> address)) {
// Operation appears in an Invalid format
cout << "Command Format error" << endl;
return 0;
}
// DEBUG - remove this line
cout << "operation: " << operation;
string cutAddress = address.substr(2); // Removing the "0x" part of the address
// DEBUG - remove this line
cout << ", address (hex)" << cutAddress;
unsigned long int num = 0;
num = strtoul(cutAddress.c_str(), NULL, 16);
// DEBUG - remove this line
cout << " (dec) " << num << endl;
}
printf("L1miss=%.03f ", L1MissRate);
printf("L2miss=%.03f ", L2MissRate);
printf("AccTimeAvg=%.03f\n", avgAccTime);
return 0;
}