-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpBimodal.cpp
127 lines (112 loc) · 5.76 KB
/
pBimodal.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
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
#include "pBimodal.h"
bimodal_F::bimodal_F(std::string filepath,int s, int gh, int ph){
this->filepath=filepath; //Compress file entry
this->s=s; // Branch History Table (BHT) size
this->gh=gh; //GShare size (given value)
this->ph=ph; //PShare size (given value)
};
void bimodal_F::begin_prediction_B(){
int Table_Nentry = pow(2, s); // 2^s
int counter_miss_T = 0; // Incorrect Taken branches
int counter_miss_N = 0; // Incorrect Not Taken branches
int counter_T = 0; // Right Taken branches
int counter_N = 0; // Right Not Taken branches
char *Table = (char *)calloc(Table_Nentry, sizeof(char));
long mask = Table_Nentry - 1; // mask size for redirecting network
std::string op_mode = "Bimodal";
int num_branch = 0; // number of branches (jumps)
/////////
time_t current_time;
time_t final_time;
time(¤t_time); // capture time
std::ofstream results_file ("results/result_sum_bimodal.txt", std::ofstream::out); // result file write
if(!results_file) // if no file
{
std::cout<<"ERROR, there is no file created ............. ERROR ..... ERROR";
}
/////// File open
for (std::string line; std::getline(std::cin, line);) {
long pc_dd = 0;
char result = ' ';
sscanf(line.c_str(), "%ld %c", &pc_dd, &result);
// std::string pc_dd_10 = line.substr(0,10); // Decimal direction // position // how many
// char result = line.substr(11,1).c_str()[0]; // Result? -> T or N
// long pc_dd = (int)std::strtol(pc_dd_10.c_str(), nullptr, 10); // 10 is the base which parse the string
if ((result != 'N') && (result != 'T')) {
std::cout << "Parser error at line " << num_branch << std::endl;
}
long pc_mask_access = pc_dd & mask;
//std::cout << "Address " << pc_dd << " mapped to " << pc_mask_access << " with mask " << mask << " and result " << result << std::endl;
if (Table[pc_mask_access] <= 1) {
if (result == 'N') {
counter_N++;
} else {
counter_miss_T++;
}
} else {
if (result == 'T') {
counter_T++;
} else {
counter_miss_N++;
}
}
// Adjust counters based on result
if (result == 'N') {
// Decrement if not 0
if (Table[pc_mask_access] > 0) {
Table[pc_mask_access]--;
}
} else {
// Increment if 3
if (Table[pc_mask_access] < 3) {
Table[pc_mask_access]++;
}
}
num_branch++; // count all lines
}
time(&final_time); // capture time
int ex_time = difftime(final_time,current_time);
float percentage = ((float)(counter_T + counter_N)*(float)100)/(float)num_branch; // for all lines
/////////////////////Results////////////////////////////////////////////////////
results_file << "------------------------------------------------------------------------ \n";
results_file << "Prediction parameters: \n ";
results_file << "------------------------------------------------------------------------ \n";
results_file << "Branch prediction type: " << op_mode << std::endl;
results_file << "BHT size (entries): " << Table_Nentry << std::endl;
results_file << "Global history register size: " << gh << std::endl;
results_file << "Private history register size: " << ph << std::endl;
results_file << "------------------------------------------------------------------------ \n";
results_file << "Simulation results: " << std::endl;
results_file << "------------------------------------------------------------------------\n";
results_file << "Number of branch: " << num_branch << std::endl;
results_file << "Number of correct prediction of taken branches: " << counter_T << std::endl;
results_file << "Number of incorrect prediction of taken branches: " << counter_miss_T << std::endl;
results_file << "Correct prediction of not taken branches: " << counter_N << std::endl;
results_file << "Incorrect prediction of not taken branches: " << counter_miss_N << std::endl;
results_file << "Percentage of correct predictions: " << percentage << "%" <<std::endl;
results_file << "Time running: " << ex_time << std::endl;
/////////////////////Results////////////////////////////////////////////////////
std::cout << "------------------------------------------------------------------------ \n";
std::cout << "Prediction parameters: \n ";
std::cout << "------------------------------------------------------------------------ \n";
std::cout << "Branch prediction type: " << op_mode << std::endl;
std::cout << "BHT size (entries): " << Table_Nentry << std::endl;
std::cout << "Global history register size: " << gh << std::endl;
std::cout << "Private history register size: " << ph << std::endl;
std::cout << "------------------------------------------------------------------------ \n";
std::cout << "Simulation results: " << std::endl;
std::cout << "------------------------------------------------------------------------\n";
std::cout << "Number of branch: " << num_branch << std::endl;
std::cout << "Number of correct prediction of taken branches: " << counter_T << std::endl;
std::cout << "Number of incorrect prediction of taken branches: " << counter_miss_T << std::endl;
std::cout << "Correct prediction of not taken branches: " << counter_N << std::endl;
std::cout << "Incorrect prediction of not taken branches: " << counter_miss_N << std::endl;
std::cout << "Percentage of correct predictions: " << percentage << "%" <<std::endl;
std::cout << "Time running: " << ex_time << " seconds" << std::endl;
//
// std::cout << "\n\n ***** \n\n" << std::endl;
// std::cout << "The number of branches analyzed is " << stop_analize << " so consider that in this results " << std::endl;
// std::cout << "If you want more lines review the code and remove: stop_analize condition " << std::endl;
//
free(Table);
} // end all