-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocalHistory.cpp
93 lines (77 loc) · 2.73 KB
/
localHistory.cpp
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
#include "smithCounter.h"
#include "stats.h"
#include "branchHistoryRegister.h"
#include <iostream>
#include <iomanip>
#include <istream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
//Sean Blucker
using namespace std;
using namespace csci5814;
int main()
{
Stats smith_stats;
SmithCounter smith_array[128];
BranchHistoryRegister bhr[4];
string branch;
string pathIdentifier;
int instruction;
bool pathPrediction;
bool takenPath;
ifstream input("branch_trace.dat");
while (getline(input,branch,' '))
{
if(input.eof())
{
break;
}
getline(input,pathIdentifier,'\n');
instruction = atoi(branch.c_str());
int branchHistoryArrayIndex = (instruction/4) & 0x3;
int smithArrayIndex = (((instruction/4) << (bhr[branchHistoryArrayIndex].getSize())) | (bhr[branchHistoryArrayIndex].getValue() & 0xF)) & 0xFF;
pathPrediction = smith_array[smithArrayIndex].getPrediction();
if (pathIdentifier.find('T') != std::string::npos)
{
takenPath=true;
smith_stats.incrementBranchTakenCount();
}
else if (pathIdentifier.find('N') != std::string::npos)
{
takenPath=false;
smith_stats.incrementBranchNotTakenCount();
}
if (pathPrediction && takenPath)
{
smith_array[smithArrayIndex].updatePrediction(pathIdentifier);
bhr[branchHistoryArrayIndex].updateBranchHistoryRegister(pathIdentifier);
smith_stats.incrementCorrectlyPredictedTakenBranches();
}
else if (pathPrediction && !takenPath)
{
smith_array[smithArrayIndex].updatePrediction(pathIdentifier);
bhr[branchHistoryArrayIndex].updateBranchHistoryRegister(pathIdentifier);
}
else if (!pathPrediction && !takenPath)
{
smith_array[smithArrayIndex].updatePrediction(pathIdentifier);
bhr[branchHistoryArrayIndex].updateBranchHistoryRegister(pathIdentifier);
smith_stats.incrementCorrectlyPredictedNotTakenBranches();
}
else if (!pathPrediction && takenPath)
{
smith_array[smithArrayIndex].updatePrediction(pathIdentifier);
bhr[branchHistoryArrayIndex].updateBranchHistoryRegister(pathIdentifier);
}
smith_stats.incrementBranches();
}
input.close();
cout << "Number of branches: " << smith_stats.getBranches() << endl;
cout << "Number of branches taken: " << smith_stats.getBranchTakenCount() << endl;
cout << "Number taken branches correctly predicted: " << smith_stats.getCorrectlyPredictedTakenBranches() << endl;
cout << "Number of branches not taken: " << smith_stats.getBranchNotTakenCount() << std::endl;
cout << "Number not taken branches correctly predicted: " << smith_stats.getCorrectlyPredictedNotTakenBranches() << endl;
cout << "Overall rate of correct predictions: " << smith_stats.getPercent() << "%" << endl;
return 0;
}