-
Notifications
You must be signed in to change notification settings - Fork 11
/
branchpred.h
82 lines (66 loc) · 2.02 KB
/
branchpred.h
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
// -*- c++ -*-
//
// Branch Prediction
//
// Copyright 2003-2008 Matt T. Yourst <[email protected]>
//
// This program is free software; it is licensed under the
// GNU General Public License, Version 2.
//
#ifndef _BRANCHPRED_H_
#define _BRANCHPRED_H_
#include <ptlsim.h>
#define BRANCH_HINT_UNCOND 0
#define BRANCH_HINT_COND (1 << 0)
#define BRANCH_HINT_INDIRECT (1 << 1)
#define BRANCH_HINT_CALL (1 << 2)
#define BRANCH_HINT_RET (1 << 3)
struct ReturnAddressStackEntry {
int idx;
W32 uuid;
W64 rip;
operator W64() const { return rip; }
ReturnAddressStackEntry() { }
ReturnAddressStackEntry(W64 uuid, W64 rip) {
this->uuid = uuid;
this->rip = rip;
this->idx = -1;
}
// Required by Queue<> template class:
void init(int i) { idx = i; }
void validate() { }
int index() const { return idx; }
};
ostream& operator <<(ostream& os, const ReturnAddressStackEntry& e);
struct PredictorUpdate {
W64 uuid;
byte* cp1;
byte* cp2;
byte* cpmeta;
// predicted directions:
W32 ctxid:8, flags:8, bimodal:1, twolevel:1, meta:1, ras_push:1;
ReturnAddressStackEntry ras_old;
};
extern W64 branchpred_ras_pushes;
extern W64 branchpred_ras_overflows;
extern W64 branchpred_ras_pops;
extern W64 branchpred_ras_underflows;
extern W64 branchpred_ras_annuls;
struct BranchPredictorImplementation;
struct BranchPredictorInterface {
// Pointer to private implementation:
BranchPredictorImplementation* impl;
BranchPredictorInterface() { impl = null; }
void init();
void reset();
void destroy();
W64 predict(PredictorUpdate& update, int type, W64 branchaddr, W64 target);
void update(PredictorUpdate& update, W64 branchaddr, W64 target);
void updateras(PredictorUpdate& predinfo, W64 branchaddr);
void annulras(const PredictorUpdate& predinfo);
void flush();
};
ostream& operator <<(ostream& os, const BranchPredictorInterface& branchpred);
extern BranchPredictorInterface branchpred;
static const char* branchpred_outcome_names[2] = {"mispred", "correct"};
#endif // _BRANCHPRED_H_