-
Notifications
You must be signed in to change notification settings - Fork 1
/
bp.h
executable file
·145 lines (122 loc) · 4.83 KB
/
bp.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
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
/*H**********************************************************************
* FILENAME : bp.h
* DESCRIPTION : Contains structures and prototypes for generic
* branch predictor simulator
* NOTES : -NA-
*
* AUTHOR : Utkarsh Mathur START DATE : 20 Oct 17
*
* CHANGES :
*
*H***********************************************************************/
#ifndef _BP_H
#define _BP_H
#include "all.h"
// Mask for 32 bit address
#define MSB_ONE_32_BIT 0x80000000
#define BP_LOWER_RSVD_CNT 2
// Pointer translations
typedef struct _bpT *bpPT;
typedef struct _bpPathT *bpPathPT;
typedef struct _bpControllerT *bpControllerPT;
typedef struct _tagT *tagPT;
typedef struct _tagStoreT *tagStorePT;
// Enum to hold direction like read/write
typedef enum {
BP_PATH_NOT_TAKEN = 0,
BP_PATH_TAKEN = 1,
}bpPathT;
typedef enum{
BP_TYPE_BIMODAL = 0,
BP_TYPE_GSHARE = 1,
BP_TYPE_HYBRID = 2,
BP_TYPE_BTB = 3,
}bpTypeT;
typedef struct _bpControllerT{
bpTypeT type;
bpPT bpBimodalP;
bpPT bpGshareP;
int k;
int kMask;
// Chooser table for hybrid predictor
int sizeChooserTable;
int *chooserTable;
// Metrics
int predictions;
int misPredictions;
}bpControllerT;
// Branch predictor structure.
typedef struct _bpT{
/*
* Configutration params
*/
// Placeholder for name
char name[128];
boolean btbPresent;
int btbSize;
int btbIndexSize;
int btbIndexMask;
int btbAssoc;
int btbSets;
int btbPredictions;
int btbMissTaken;
tagStorePT *tagStoreP;
//-------------------- BIMODAL/GSHARE BEGIN -------------------------
// Number of bits used to represent prediction table
int m;
int n;
bpTypeT type;
int gShareShift;
int nMsbSetMask;
// Mask to calculate index from address
int mMask;
int nMask;
int sizePredictionTable;
int *predictionTable;
// Register for GShare predictor
int globalBrHistoryReg;
//-------------------- BIMODAL/GSHARE END ---------------------------
}bpT;
typedef struct _tagT{
int tag;
boolean valid;
int counter;
}tagT;
// Tag store unit cell
typedef struct _tagStoreT{
tagPT *rowP;
}tagStoreT;
// Function prototypes. This part can be automated
// lets keep hardcoded as of now
bpPT branchPredictorInit(
char* name,
int m,
int n,
bpTypeT type,
int btbSize,
int btbAssoc
);
// bp funcs
void bpGetIndexTag( bpPT bpP, int address, int* indexBpP, int* indexBtbP, int* tagP );
void bpBtbHitUpdateLRU( bpPT bpP, int index, int setIndex );
int bpBtbFindReplacementUpdateCounterLRU( bpPT bpP, int index, int tag, int overrideSetIndex, int doOverride );
bpPathT bpPredict( bpPT bpP, int indexBp, int indexBtb, int tag, boolean *update );
void bpUpdatePredictionTable( bpPT bpP, int index, bpPathT actual, boolean btbMiss );
void bpUpdateGlobalBrHistoryTable( bpPT bpP, bpPathT actual );
void bpPrintPredictionTable( bpPT bpP );
void bpBtbPrintContents( bpPT bpP );
void bpBtbGetMetrics( bpPT bpP, int* pred, int* misPred );
// Controller funcs
bpControllerPT bpCreateController( bpPT bpBimodalP, bpPT bpGshareP, int k, bpTypeT type );
void bpControllerProcess( bpControllerPT contP, int address, bpPathT actual );
void bpControllerUpdateChooserTable( bpControllerPT contP,
int chooserIndex,
bpPathT bimodalPred,
bpPathT gsharePred,
bpPathT actual
);
int bpControllerGetChooserIndex( bpControllerPT contP, int address );
bpTypeT bpControllerHybridGetType( bpControllerPT contP, int index );
void bpControllerPrintChooserTable( bpControllerPT contP );
void bpControllerGetMetrics( bpControllerPT contP, int* predictions, int* misPredictions, double* misPredictionRate );
#endif