-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbimodal.cc
55 lines (41 loc) · 1.23 KB
/
bimodal.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
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <iostream>
using namespace std;
// Index size (M)
int* bimodal(int m, char *tracefile, vector<int> table) {
bool actual_taken;
bool pred_taken;
// File
ifstream InFile(tracefile);
string line;
// Stats
int predictions = 0;
int mispredictions = 0;
int pc = 0;
// Find and predict at each branch
while (getline(InFile, line)) {
actual_taken = (line[7] == 't');
// Get PC
pc = stoi(line.substr(0,6), 0, 16);
int index = (pc >> 2) % (1 << m);
// Predict and update
int value = table[index];
pred_taken = (value >= 4);
if (actual_taken && value < 7)
table[index]++;
else if (!actual_taken && value > 0)
table[index]--;
predictions++;
if (actual_taken != pred_taken) mispredictions++;
}
InFile.close();
// Return results
int *ret = (int *)malloc(sizeof(int) * (table.size() + 2));
ret[0] = predictions;
ret[1] = mispredictions;
for (long unsigned int i = 0; i < table.size(); i++)
ret[i+2] = table.at(i);
return ret;
}