-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathreference.cpp
More file actions
96 lines (81 loc) · 3.01 KB
/
reference.cpp
File metadata and controls
96 lines (81 loc) · 3.01 KB
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
#include <iostream>
#include "trace_reader.hpp"
#include "seznec_cbp2025.h"
CBP2025 PRED;
int main(int argc, char * argv[])
{
if (argc != 5) {
printf("Expected three arguments: the instruction stream, warmup instructions, and measurement instructions\n");
return -1;
}
trace_reader reader(argv[1], argv[2]);
uint64_t warmup_instructions = atoi(argv[3]);
uint64_t measurement_instructions = atoi(argv[4]);
uint64_t total_instructions = warmup_instructions + measurement_instructions;
uint64_t ninstr = 0;
uint64_t nbranch = 0;
uint64_t ncondbr = 0;
uint64_t nmisp = 0;
uint64_t nblock = 0;
bool warmed_up = (warmup_instructions==0);
try {
while (ninstr < total_instructions) {
auto inst = reader.next_instruction();
ninstr++;
if (!inst.branch) continue; // not a branch, go to next instruction
nbranch++;
int brtype = 0;
switch (inst.inst_class) {
case INST_CLASS::BR_UNCOND_DIRECT:
case INST_CLASS::BR_CALL_DIRECT:
brtype = 0;
break;
case INST_CLASS::BR_COND:
brtype = 1;
break;
case INST_CLASS::BR_UNCOND_INDIRECT:
case INST_CLASS::BR_CALL_INDIRECT:
case INST_CLASS::BR_RETURN:
brtype = 2;
break;
default:
assert(0);
};
bool actual_dir = inst.taken_branch;
bool misprediction = false;
if (inst.inst_class == INST_CLASS::BR_COND) {
// conditional branch
ncondbr++;
bool prediction = PRED.predict(nbranch,0,inst.pc);
misprediction = (prediction != actual_dir);
if (misprediction) nmisp++;
PRED.history_update(nbranch, 0, inst.pc, brtype, actual_dir, inst.next_pc);
PRED.update(nbranch, 0, inst.pc, actual_dir, prediction, inst.next_pc);
} else {
PRED.TrackOtherInst(inst.pc, brtype, actual_dir, inst.next_pc);
}
if (inst.taken_branch || misprediction) nblock++;
if (!warmed_up && ninstr > warmup_instructions) {
warmed_up = true;
ninstr = 0;
nbranch = 0;
ncondbr = 0;
nmisp = 0;
nblock = 0;
}
}
} catch (const out_of_instructions &e) { }
std::cout << reader.name();
std::cout << "," << ninstr;
std::cout << "," << nbranch;
std::cout << "," << ncondbr;
std::cout << "," << nblock;//npred;
std::cout << "," << 0;//extra_cycles;
std::cout << "," << 0;//p1_p2_disagreements;
std::cout << "," << 0;//p1_p2_disagreements_at_block_end;
std::cout << "," << nmisp;//mispredictions;
std::cout << "," << 0;//p1_latency_cycles;
std::cout << "," << 0;//p2_latency_cycles;
std::cout << "," << 0;//int64_t(epi_fJ);
std::cout << std::endl;
}