-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathstats.js
217 lines (182 loc) · 5.87 KB
/
stats.js
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// JSDoc のタイプチェックに型を認識させるため
let Op = require("./op").Op; // eslint-disable-line
class GenericStats{
constructor(lastID, lastRID, lastCycle){
this.stats_ = {
numFetchedOps: lastID,
numCommittedOps: lastRID,
numCycles: lastCycle,
numFlush: 0,
numFlushedOps: 0,
numBrFlushedOps: 0,
numJumpFlushedOps: 0,
numSpeculativeMemFlushedOps: 0,
numFetchedBr: 0,
numRetiredBr: 0,
numBrPredMiss: 0,
rateBrPredMiss: 0,
mpkiBrPred: 0,
numFetchedJump: 0,
numRetiredJump: 0,
numJumpPredMiss: 0,
rateJumpPredMiss: 0,
mpkiJumpPred: 0,
numFetchedStore: 0,
numRetiredStore: 0,
numSpeculativeMemMiss: 0,
rateSpeculativeMemMiss: 0,
mpkiSpeculativeMemMiss: 0,
ipc: lastRID / lastCycle
};
this.prevBr_ = false;
this.prevJump_ = false;
this.prevStore_ = false;
this.prevFlushed_ = false;
this.inBrFlush_ = false;
this.inJumpFlush_ = false;
this.inMemFlush_ = false;
this.isDetected_ = true; // 常に true
}
get name(){
return "GenericStats";
}
get stats() {return this.stats_;}
finish(){
// post process
let s = this.stats_;
s.rateBrPredMiss = s.numBrPredMiss / s.numRetiredBr;
s.mpkiBrPred = s.numBrPredMiss / s.numCommittedOps * 1000;
s.rateJumpPredMiss = s.numJumpPredMiss / s.numRetiredJump;
s.mpkiJumpPred = s.numJumpPredMiss / s.numCommittedOps * 1000;
s.rateSpeculativeMemMiss = s.numSpeculativeMemMiss / s.numRetiredStore;
s.mpkiSpeculativeMemMiss = s.numSpeculativeMemMiss / s.numCommittedOps * 1000;
}
/** @param {Op} op */
update(op) {
let s = this.stats_;
if (op.flush) {
if (!this.prevFlushed_) {
// 一つ前の命令がフラッシュされていなければ,ここがフラッシュの起点
s.numFlush++;
if (this.prevBr_) {
this.inBrFlush_ = true;
s.numBrPredMiss++;
}
if (this.prevJump_) {
this.inJumpFlush_ = true;
s.numJumpPredMiss++;
}
if (this.prevStore_) {
this.inMemFlush_ = true;
s.numSpeculativeMemMiss++;
}
}
// Count the number of flushed ops
s.numFlushedOps++;
if (this.inBrFlush_) {
s.numBrFlushedOps++;
}
else if (this.inJumpFlush_) {
s.numJumpFlushedOps++;
}
else if (this.inMemFlush_) {
s.numSpeculativeMemFlushedOps++;
}
}
else {
this.inBrFlush_ = false;
this.inJumpFlush_ = false;
this.inMemFlush_ = false;
}
this.prevFlushed_ = op.flush;
if (this.isBranch_(op.labelName)) {
s.numFetchedBr++;
if (op.retired) {
s.numRetiredBr++;
}
this.prevBr_ = true;
}
else {
this.prevBr_ = false;
}
if (this.isJump_(op.labelName)) {
s.numFetchedJump++;
if (op.retired) {
s.numRetiredJump++;
}
this.prevJump_ = true;
}
else {
this.prevJump_ = false;
}
if (this.isStore_(op.labelName)) {
s.numFetchedStore++;
if (op.retired) {
s.numRetiredStore++;
}
this.prevStore_ = true;
}
else {
this.prevStore_ = false;
}
}
// ラベル内に b で始まる単語が入っていれば分岐
isBranch_(text){
return text.match(/[\s][b][^\s]*[\s]*/);
}
// j, call, ret はジャンプ
isJump_(text){
return text.match(/[\s]([j])|(call)|(ret)[^\s]*[\s]*/);
}
// st,sw,sh,sb から始まっていたらストア
isStore_(text){
return text.match(/[\s](st)|(sw)|(sh)|(sb)[^\s]*[\s]*/);
}
get isDetected() {return this.isDetected_;}
}
class X86_Gem5_Stats extends GenericStats{
constructor(lastID, lastRID, lastCycle){
super(lastID, lastRID, lastCycle);
this.isDetected_ = false;
}
get name(){
return "X86_Gem5_Stats";
}
update(op){
super.update(op);
if (!this.isDetected_ ) {
let text = op.labelName;
if (text.match(/[eErR][aAbBcCdD][xX][^,]*,[^,]*[eErR][aAbBcCdD][xX]/)) {
this.isDetected_ = true;
}
if (text.match(/[xXyY][mM][mM][^,]*,[^,]*[xXyY][mM][mM]/)) {
this.isDetected_ = true;
}
if (this.isDetected_) {
console.log(`Detected X86-Gem5 from '${text}' in X86_Gem5_Stats`);
}
}
}
// J で始まり JMP ではなく,wrip に分解される命令は条件分岐
isBranch_(text){
return text.match(/[\s]*[jJ][^mM][^:]+:\s*wrip/);
}
// jmX, call, ret で wrip はジャンプ
isJump_(text){
return text.match(/([\s]*([jJ][mM])|([cC][aA][lL][lL])|([rR][eE][tT]))[^:]+:\s*wrip/);
}
// : st はストア
isStore_(text){
return text.match(/[\s]*[^:]+:\s*st/);
}
}
/**
* @returns {GenericStats[]} */
function CreateStats(lastID, lastRID, lastCycle){
return [
new X86_Gem5_Stats(lastID, lastRID, lastCycle),
new GenericStats(lastID, lastRID, lastCycle),
];
}
//module.exports.GenericStats = GenericStats;
module.exports.CreateStats = CreateStats;