1 | #ifdef SYSTEMC |
---|
2 | /* |
---|
3 | * $Id: Two_Level_Branch_Predictor_transition.cpp 146 2011-02-01 20:57:54Z rosiere $ |
---|
4 | * |
---|
5 | * [ Description ] |
---|
6 | * |
---|
7 | */ |
---|
8 | |
---|
9 | #include "Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Direction/Meta_Predictor/Two_Level_Branch_Predictor/include/Two_Level_Branch_Predictor.h" |
---|
10 | // #include <assert.h> |
---|
11 | |
---|
12 | namespace morpheo { |
---|
13 | namespace behavioural { |
---|
14 | namespace core { |
---|
15 | namespace multi_front_end { |
---|
16 | namespace front_end { |
---|
17 | namespace prediction_unit { |
---|
18 | namespace direction { |
---|
19 | namespace meta_predictor { |
---|
20 | namespace two_level_branch_predictor { |
---|
21 | |
---|
22 | |
---|
23 | #undef FUNCTION |
---|
24 | #define FUNCTION "Two_Level_Branch_Predictor::transition" |
---|
25 | void Two_Level_Branch_Predictor::transition (void) |
---|
26 | { |
---|
27 | log_begin(Two_Level_Branch_Predictor,FUNCTION); |
---|
28 | log_function(Two_Level_Branch_Predictor,FUNCTION,_name.c_str()); |
---|
29 | |
---|
30 | if (PORT_READ(in_NRESET) == 0) |
---|
31 | { |
---|
32 | } |
---|
33 | else |
---|
34 | { |
---|
35 | // =================================================================== |
---|
36 | // =====[ PREDICT ]=================================================== |
---|
37 | // =================================================================== |
---|
38 | |
---|
39 | for (uint32_t i=0; i<_param->_nb_inst_predict; ++i) |
---|
40 | if (PORT_READ(in_PREDICT_VAL[i]) and internal_PREDICT_ACK[i]) |
---|
41 | { |
---|
42 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * PREDICT [%d]",i); |
---|
43 | |
---|
44 | // Predict if |
---|
45 | // * update_on_prediction and direction is valid |
---|
46 | if (_param->_update_on_prediction) |
---|
47 | if (PORT_READ(in_PREDICT_DIRECTION_VAL [i])) |
---|
48 | { |
---|
49 | Tcontrol_t direction = PORT_READ(in_PREDICT_DIRECTION [i]); |
---|
50 | |
---|
51 | if (_param->_have_bht) |
---|
52 | { |
---|
53 | Thistory_t bht_num_reg = internal_PREDICT_BHT_NUM_REG [i]; |
---|
54 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht_num_reg : %lld",bht_num_reg); |
---|
55 | |
---|
56 | // #ifdef DEBUG_TEST |
---|
57 | // assert(bht_num_reg < _param->_bht_nb_shifter); |
---|
58 | // #endif |
---|
59 | |
---|
60 | Thistory_t bht_history = reg_BHT[bht_num_reg]; |
---|
61 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht_history (old): %llx",bht_history); |
---|
62 | |
---|
63 | |
---|
64 | bht_history = ((bht_history<<1) | direction)&_param->_bht_history_mask ; |
---|
65 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht_history (new): %llx",bht_history); |
---|
66 | reg_BHT [bht_num_reg] = bht_history; |
---|
67 | } |
---|
68 | |
---|
69 | if (_param->_have_pht) |
---|
70 | { |
---|
71 | Thistory_t pht_num_reg = internal_PREDICT_PHT_NUM_REG [i]; |
---|
72 | Thistory_t pht_num_bank= internal_PREDICT_PHT_NUM_BANK [i]; |
---|
73 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_num_reg : %lld",pht_num_reg); |
---|
74 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_num_bank : %lld",pht_num_bank); |
---|
75 | |
---|
76 | Thistory_t pht_history = reg_PHT [pht_num_bank][pht_num_reg]; |
---|
77 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_history (old): %llx",pht_history); |
---|
78 | |
---|
79 | // TODO -> don't change PHT here ! |
---|
80 | Thistory_t min = 0; |
---|
81 | Thistory_t max = _param->_pht_counter_max; |
---|
82 | |
---|
83 | // PHT : saturation counter |
---|
84 | switch (_param->_pht_scheme) |
---|
85 | { |
---|
86 | case PHT_SCHEME_COUNTER : |
---|
87 | { |
---|
88 | pht_history = (direction==1)?((pht_history<max)?(pht_history+1):(max)):((pht_history>min)?(pht_history-1):(min)); |
---|
89 | break; |
---|
90 | } |
---|
91 | case PHT_SCHEME_FSM : |
---|
92 | { |
---|
93 | Thistory_t down = _param->_pht_threshold_down; |
---|
94 | Thistory_t up = _param->_pht_threshold_up; |
---|
95 | |
---|
96 | pht_history = (direction==1)?(((pht_history==max) or (pht_history==up))?(max):(pht_history+1)):(((pht_history==min) or (pht_history==down))?(min):(pht_history-1)); |
---|
97 | break; |
---|
98 | } |
---|
99 | default : |
---|
100 | { |
---|
101 | break; |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_history (new): %llx",pht_history); |
---|
106 | |
---|
107 | reg_PHT [pht_num_bank][pht_num_reg] = pht_history; |
---|
108 | } |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | // =================================================================== |
---|
113 | // =====[ UPDATE ]==================================================== |
---|
114 | // =================================================================== |
---|
115 | |
---|
116 | for (uint32_t i=0; i<_param->_nb_inst_update; ++i) |
---|
117 | if (PORT_READ(in_UPDATE_VAL[i]) and internal_UPDATE_ACK[i]) |
---|
118 | { |
---|
119 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * UPDATE [%d]",i); |
---|
120 | if (_param->_update_on_prediction) |
---|
121 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * miss : %d",PORT_READ(in_UPDATE_MISS [i])); |
---|
122 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * update_on_predict: %d",_param->_update_on_prediction); |
---|
123 | |
---|
124 | // Update if |
---|
125 | // * update_on_prediction and miss |
---|
126 | // * not update_on_prediction |
---|
127 | Tcontrol_t history_val = PORT_READ(in_UPDATE_HISTORY_VAL [i]); |
---|
128 | |
---|
129 | if (not _param->_update_on_prediction or |
---|
130 | (_param->_update_on_prediction and PORT_READ(in_UPDATE_MISS [i])) or |
---|
131 | not history_val // static_prediction |
---|
132 | ) |
---|
133 | { |
---|
134 | Taddress_t address = PORT_READ(in_UPDATE_ADDRESS [i]); |
---|
135 | Thistory_t history = PORT_READ(in_UPDATE_HISTORY [i]); |
---|
136 | Tcontrol_t direction = PORT_READ(in_UPDATE_DIRECTION [i])&1; |
---|
137 | |
---|
138 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * address : %.8x",address); |
---|
139 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * direction : %d",direction); |
---|
140 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * history_val : %d",direction); |
---|
141 | |
---|
142 | Thistory_t pht_bht_history = 0; |
---|
143 | |
---|
144 | if (_param->_have_bht) |
---|
145 | { |
---|
146 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht"); |
---|
147 | |
---|
148 | Thistory_t bht_history = (history>>_param->_bht_history_shift )&_param->_bht_history_mask; |
---|
149 | Thistory_t bht_num_reg = address & _param->_bht_address_mask; |
---|
150 | |
---|
151 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht_history (old): %llx",bht_history); |
---|
152 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht_num_reg : %llx",bht_num_reg); |
---|
153 | |
---|
154 | // BHT : shift register |
---|
155 | if (not history_val) |
---|
156 | { |
---|
157 | bht_history = (direction)?_param->_bht_init_take:_param->_bht_init_ntake; |
---|
158 | } |
---|
159 | else |
---|
160 | { |
---|
161 | bht_history = ((bht_history<<1) | direction)&_param->_bht_history_mask ; |
---|
162 | } |
---|
163 | |
---|
164 | pht_bht_history = bht_history; |
---|
165 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht_history (new): %llx",bht_history); |
---|
166 | |
---|
167 | // #ifdef DEBUG_TEST |
---|
168 | // assert(bht_num_reg < _param->_bht_nb_shifter); |
---|
169 | // #endif |
---|
170 | |
---|
171 | reg_BHT [bht_num_reg] = bht_history; |
---|
172 | } |
---|
173 | |
---|
174 | if (_param->_have_pht) |
---|
175 | { |
---|
176 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht"); |
---|
177 | |
---|
178 | Thistory_t pht_history = (history>>_param->_pht_history_shift )&_param->_pht_history_mask; |
---|
179 | Thistory_t pht_num_bank= (address>>_param->_pht_address_bank_shift )&_param->_pht_address_bank_mask; |
---|
180 | Thistory_t pht_num_reg = pht_bht_history xor ((address&_param->_pht_address_share_mask)<<_param->_pht_address_share_shift); |
---|
181 | |
---|
182 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht_history (old): %llx",pht_bht_history); |
---|
183 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_history (old): %llx",pht_history); |
---|
184 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_num_reg : %llx",pht_num_reg); |
---|
185 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_num_bank : %llx",pht_num_bank); |
---|
186 | |
---|
187 | // PHT : saturation counter |
---|
188 | if (not history_val) |
---|
189 | { |
---|
190 | pht_history = (direction)?_param->_pht_init_take:_param->_pht_init_ntake; |
---|
191 | } |
---|
192 | else |
---|
193 | { |
---|
194 | Thistory_t min = 0; |
---|
195 | Thistory_t max = _param->_pht_counter_max; |
---|
196 | |
---|
197 | // PHT : saturation counter |
---|
198 | switch (_param->_pht_scheme) |
---|
199 | { |
---|
200 | case PHT_SCHEME_COUNTER : |
---|
201 | { |
---|
202 | // [ 11 ] -- NT -> [ 10 ] |
---|
203 | // [ ] <- T -- [ ] |
---|
204 | // ^ | |
---|
205 | // | | |
---|
206 | // T NT |
---|
207 | // | | |
---|
208 | // | V |
---|
209 | // [ 00 ] -- T -> [ 01 ] |
---|
210 | // [ ] <- NT -- [ ] |
---|
211 | |
---|
212 | pht_history = (direction==1)?((pht_history<max)?(pht_history+1):(max)):((pht_history>min)?(pht_history-1):(min)); |
---|
213 | break; |
---|
214 | } |
---|
215 | case PHT_SCHEME_FSM : |
---|
216 | { |
---|
217 | // [11] -- NT -> [10] |
---|
218 | // [ ] <- T -- [ ] |
---|
219 | // ^ | |
---|
220 | // | | |
---|
221 | // T NT |
---|
222 | // | | |
---|
223 | // | V |
---|
224 | // [00] -- NT -> [00] |
---|
225 | // [ ] <- T -- [ ] |
---|
226 | |
---|
227 | Thistory_t down = _param->_pht_threshold_down; |
---|
228 | Thistory_t up = _param->_pht_threshold_up; |
---|
229 | |
---|
230 | pht_history = (direction==1)?(((pht_history==max) or (pht_history==up))?(max):(pht_history+1)):(((pht_history==min) or (pht_history==down))?(min):(pht_history-1)); |
---|
231 | break; |
---|
232 | } |
---|
233 | default : |
---|
234 | { |
---|
235 | break; |
---|
236 | } |
---|
237 | } |
---|
238 | } |
---|
239 | |
---|
240 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_history (new): %llx",pht_history); |
---|
241 | |
---|
242 | reg_PHT [pht_num_bank][pht_num_reg] = pht_history; |
---|
243 | } |
---|
244 | } |
---|
245 | } |
---|
246 | } |
---|
247 | |
---|
248 | #if defined(DEBUG) and DEBUG_Two_Level_Branch_Predictor and (DEBUG >= DEBUG_TRACE) |
---|
249 | |
---|
250 | # if 0 |
---|
251 | { |
---|
252 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * Dump Two_Level_Branch_Predictor"); |
---|
253 | |
---|
254 | if (_param->_have_bht) |
---|
255 | { |
---|
256 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * Dump BHT"); |
---|
257 | |
---|
258 | uint32_t limit = 4; |
---|
259 | |
---|
260 | for (uint32_t i=0; i<_param->_bht_nb_shifter; i+=limit) |
---|
261 | { |
---|
262 | std::string str = ""; |
---|
263 | |
---|
264 | for (uint32_t j=0; j<limit; j++) |
---|
265 | { |
---|
266 | uint32_t index = i+j; |
---|
267 | if (index >= _param->_bht_nb_shifter) |
---|
268 | break; |
---|
269 | else |
---|
270 | { |
---|
271 | str+=toString("[%.4d] %.4x ",index,reg_BHT[index]); |
---|
272 | } |
---|
273 | } |
---|
274 | |
---|
275 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," %s",str.c_str()); |
---|
276 | } |
---|
277 | } |
---|
278 | |
---|
279 | if (_param->_have_pht) |
---|
280 | { |
---|
281 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * Dump PHT"); |
---|
282 | |
---|
283 | uint32_t limit = 4; |
---|
284 | |
---|
285 | for (uint32_t num_bank=0; num_bank <_param->_pht_nb_bank; ++num_bank) |
---|
286 | { |
---|
287 | if (_param->_pht_size_bank == 1) |
---|
288 | { |
---|
289 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," [%.4d][0000] %4x",num_bank,reg_PHT[num_bank][0]); |
---|
290 | } |
---|
291 | else |
---|
292 | { |
---|
293 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," [%.4d]",num_bank); |
---|
294 | |
---|
295 | for (uint32_t i=0; i<_param->_pht_size_bank; i+=limit) |
---|
296 | { |
---|
297 | std::string str = ""; |
---|
298 | |
---|
299 | for (uint32_t j=0; j<limit; j++) |
---|
300 | { |
---|
301 | uint32_t index = i+j; |
---|
302 | if (index >= _param->_pht_size_bank) |
---|
303 | break; |
---|
304 | else |
---|
305 | str+=toString("[%.4d] %.4x ",index,reg_PHT[num_bank][index]); |
---|
306 | } |
---|
307 | |
---|
308 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," %s",str.c_str()); |
---|
309 | } |
---|
310 | } |
---|
311 | } |
---|
312 | } |
---|
313 | } |
---|
314 | # endif |
---|
315 | #endif |
---|
316 | |
---|
317 | #if defined(STATISTICS) or defined(VHDL_TESTBENCH) |
---|
318 | end_cycle (); |
---|
319 | #endif |
---|
320 | |
---|
321 | log_end(Two_Level_Branch_Predictor,FUNCTION); |
---|
322 | }; |
---|
323 | |
---|
324 | }; // end namespace two_level_branch_predictor |
---|
325 | }; // end namespace meta_predictor |
---|
326 | }; // end namespace direction |
---|
327 | }; // end namespace prediction_unit |
---|
328 | }; // end namespace front_end |
---|
329 | }; // end namespace multi_front_end |
---|
330 | }; // end namespace core |
---|
331 | |
---|
332 | }; // end namespace behavioural |
---|
333 | }; // end namespace morpheo |
---|
334 | #endif |
---|