-
Notifications
You must be signed in to change notification settings - Fork 0
/
smith.cc
43 lines (33 loc) · 995 Bytes
/
smith.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
#include <fstream>
#include <cmath>
using namespace std;
int* smith(int num_bits, char *tracefile) {
int largest_bit = 1 << (num_bits - 1);
int counter = largest_bit;
int max_count = pow(2, num_bits) - 1;
bool actual_taken;
bool pred_taken;
// File
ifstream InFile(tracefile);
string line;
// Stats
int predictions = 0;
int mispredictions = 0;
// Find and predict at each branch
while (getline(InFile, line)) {
actual_taken = (line[7] == 't');
pred_taken = (counter >= largest_bit);
if (actual_taken && counter < max_count)
counter++;
else if (!actual_taken && counter > 0)
counter--;
predictions++;
if (actual_taken != pred_taken) mispredictions++;
}
// Return results
int *ret = (int *)malloc(sizeof(int) * 3);
ret[0] = predictions;
ret[1] = mispredictions;
ret[2] = counter;
return ret;
}