-
Notifications
You must be signed in to change notification settings - Fork 0
/
sim.cc
137 lines (121 loc) · 3.95 KB
/
sim.cc
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
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cstring>
#include <bits/stdc++.h>
#include <vector>
#include "sim.hh"
using namespace std;
void print_output(int *results);
int main(int argc, char* argv[]) {
int *results;
long unsigned int i;
vector<int> table;
vector<uint8_t> hybrid_chooser_table;
vector<int> hybrid_table_b;
vector<int> hybrid_table_g;
// Print command back out
cout << "COMMAND" << endl;
for (int j = 0; j < argc - 1; j++) {
cout << argv[j] << " ";
}
cout << argv[argc-1] << endl;
cout << "OUTPUT" << endl;
// Wrong input
if (argc < 2) {
cout << "Usage: sim <sim type> <sim args>" << endl;
return 0;
}
// Run Smith
if (strcmp(argv[1], "smith") == 0) {
if (argc < 4) {
cout << "Usage: sim smith <B> <tracefile>" << endl;
return 0;
}
results = smith(stoi(argv[2]), argv[3]);
// Print results
print_output(results);
cout << "FINAL COUNTER CONTENT:" << "\t\t" << results[2];
}
// Run Bimodal
else if (strcmp(argv[1], "bimodal") == 0) {
if (argc < 4) {
cout << "Usage: sim bimodal <M2> <tracefile>" << endl;
return 0;
}
table.assign (1 << stoi(argv[2]), 4);
results = bimodal(stoi(argv[2]), argv[3], table);
// Print results
print_output(results);
cout << "FINAL BIMODAL CONTENTS"<< endl;
for (i = 0; i < table.size(); i++)
cout << i << "\t" << results[i+2] << endl;
}
// Run Gshare
else if (strcmp(argv[1], "gshare") == 0) {
if (argc < 5) {
cout << "Usage: sim gshare <M1> <N> <tracefile>" << endl;
return 0;
}
table.assign (1 << stoi(argv[2]), 4);
results = gshare(stoi(argv[2]), stoi(argv[3]), argv[4], table);
// Print results
print_output(results);
cout << "FINAL GSHARE CONTENTS"<< endl;
for (i = 0; i < table.size(); i++)
cout << i << "\t" << results[i+2] << endl;
}
// Run Hybrid
else if (strcmp(argv[1], "hybrid") == 0) {
if (argc < 7) {
cout << "Usage: sim hybrid <K> <M1> <N> <M2> <tracefile>" << endl;
return 0;
}
hybrid_table_g.assign (1 << stoi(argv[3]), 4);
hybrid_table_b.assign (1 << stoi(argv[5]), 4);
hybrid_chooser_table.assign (1 << stoi(argv[2]), 1);
results = hybrid(stoi(argv[2]), stoi(argv[3]), stoi(argv[4]), stoi(argv[5]), argv[6],
hybrid_table_g, hybrid_table_b, hybrid_chooser_table);
// Print results
print_output(results);
// Print tables
int b = 0, g = 0;
cout << "FINAL CHOOSER CONTENTS"<< endl;
for (i = 0; i < hybrid_chooser_table.size(); i++)
{
cout << i << "\t" << results[i+2] << endl;
g = i+1;
}
cout << "FINAL GSHARE CONTENTS"<< endl;
for (i = 0; i < hybrid_table_g.size(); i++)
{
cout << i << "\t" << results[g + 2] << endl;
g++;
b = g;
}
cout << "FINAL BIMODAL CONTENTS"<< endl;
for (i = 0; i < hybrid_table_b.size(); i++)
{
cout << i << "\t" << results[b+2] << endl;
b++;
}
} else {
cout << "Not a valid sim type! Choose from smith, bimodal, gshare, or hybrid" << endl;
return 0;
}
return 0;
}
// Print formatted output
void print_output(int *results)
{
// Stats
int predictions = results[0];
int mispredictions = results[1];
double mis_rate = (100.0 * mispredictions) / predictions;
// Output formatted
cout.precision(4);
cout << "number of predictions:" << "\t\t" << predictions << endl;
cout << "number of mispredictions:" << "\t" << mispredictions << endl;
cout << "misprediction rate:" << fixed << setprecision(2) << "\t\t"<< mis_rate << "%" << endl;
}