1 | #ifdef SYSTEMC |
---|
2 | /* |
---|
3 | * $Id: Two_Level_Branch_Predictor_transition.cpp 115 2009-04-20 21:29:17Z 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 | |
---|
11 | namespace morpheo { |
---|
12 | namespace behavioural { |
---|
13 | namespace core { |
---|
14 | namespace multi_front_end { |
---|
15 | namespace front_end { |
---|
16 | namespace prediction_unit { |
---|
17 | namespace direction { |
---|
18 | namespace meta_predictor { |
---|
19 | namespace two_level_branch_predictor { |
---|
20 | |
---|
21 | |
---|
22 | #undef FUNCTION |
---|
23 | #define FUNCTION "Two_Level_Branch_Predictor::transition" |
---|
24 | void Two_Level_Branch_Predictor::transition (void) |
---|
25 | { |
---|
26 | log_begin(Two_Level_Branch_Predictor,FUNCTION); |
---|
27 | log_function(Two_Level_Branch_Predictor,FUNCTION,_name.c_str()); |
---|
28 | |
---|
29 | if (PORT_READ(in_NRESET) == 0) |
---|
30 | { |
---|
31 | } |
---|
32 | else |
---|
33 | { |
---|
34 | // =================================================================== |
---|
35 | // =====[ PREDICT ]=================================================== |
---|
36 | // =================================================================== |
---|
37 | |
---|
38 | for (uint32_t i=0; i<_param->_nb_inst_predict; ++i) |
---|
39 | if (PORT_READ(in_PREDICT_VAL[i]) and internal_PREDICT_ACK[i]) |
---|
40 | { |
---|
41 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * PREDICT [%d]",i); |
---|
42 | |
---|
43 | // Predict if |
---|
44 | // * update_on_prediction and direction is valid |
---|
45 | if (_param->_update_on_prediction) |
---|
46 | if (PORT_READ(in_PREDICT_DIRECTION_VAL [i])) |
---|
47 | { |
---|
48 | Tcontrol_t direction = PORT_READ(in_PREDICT_DIRECTION [i]); |
---|
49 | |
---|
50 | if (_param->_have_bht) |
---|
51 | { |
---|
52 | Thistory_t bht_num_reg = internal_PREDICT_BHT_NUM_REG [i]; |
---|
53 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht_num_reg : %d",bht_num_reg); |
---|
54 | |
---|
55 | Thistory_t bht_history = reg_BHT[bht_num_reg]; |
---|
56 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht_history (old): %x",bht_history); |
---|
57 | |
---|
58 | |
---|
59 | bht_history = ((bht_history<<1) | direction)&_param->_bht_history_mask ; |
---|
60 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht_history (new): %x",bht_history); |
---|
61 | reg_BHT [bht_num_reg] = bht_history; |
---|
62 | } |
---|
63 | |
---|
64 | if (_param->_have_pht) |
---|
65 | { |
---|
66 | Thistory_t pht_num_reg = internal_PREDICT_PHT_NUM_REG [i]; |
---|
67 | Thistory_t pht_num_bank= internal_PREDICT_PHT_NUM_BANK [i]; |
---|
68 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_num_reg : %d",pht_num_reg); |
---|
69 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_num_bank : %d",pht_num_bank); |
---|
70 | |
---|
71 | Thistory_t pht_history = reg_PHT [pht_num_bank][pht_num_reg]; |
---|
72 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_history (old): %x",pht_history); |
---|
73 | |
---|
74 | // PHT : saturation counter |
---|
75 | pht_history = (direction==1)?((pht_history<_param->_pht_counter_max)?(pht_history+1):(pht_history)):((pht_history>0)?(pht_history-1):(pht_history)); |
---|
76 | |
---|
77 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_history (new): %x",pht_history); |
---|
78 | |
---|
79 | reg_PHT [pht_num_bank][pht_num_reg] = pht_history; |
---|
80 | } |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | // =================================================================== |
---|
85 | // =====[ UPDATE ]==================================================== |
---|
86 | // =================================================================== |
---|
87 | |
---|
88 | for (uint32_t i=0; i<_param->_nb_inst_update; ++i) |
---|
89 | if (PORT_READ(in_UPDATE_VAL[i]) and internal_UPDATE_ACK[i]) |
---|
90 | { |
---|
91 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * UPDATE [%d]",i); |
---|
92 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * miss : %d",PORT_READ(in_UPDATE_MISS [i])); |
---|
93 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * update_on_predict: %d",_param->_update_on_prediction); |
---|
94 | |
---|
95 | // Update if |
---|
96 | // * update_on_prediction and miss |
---|
97 | // * not update_on_prediction |
---|
98 | Tcontrol_t history_val = PORT_READ(in_UPDATE_HISTORY_VAL [i]); |
---|
99 | |
---|
100 | if (not _param->_update_on_prediction or |
---|
101 | (_param->_update_on_prediction and PORT_READ(in_UPDATE_MISS [i])) or |
---|
102 | not history_val // static_prediction |
---|
103 | ) |
---|
104 | { |
---|
105 | Taddress_t address = PORT_READ(in_UPDATE_ADDRESS [i]); |
---|
106 | Thistory_t history = PORT_READ(in_UPDATE_HISTORY [i]); |
---|
107 | Tcontrol_t direction = PORT_READ(in_UPDATE_DIRECTION [i])&1; |
---|
108 | |
---|
109 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * address : %.8x",address); |
---|
110 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * direction : %d",direction); |
---|
111 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * history_val : %d",direction); |
---|
112 | |
---|
113 | Thistory_t pht_bht_history = 0; |
---|
114 | |
---|
115 | if (_param->_have_bht) |
---|
116 | { |
---|
117 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht"); |
---|
118 | |
---|
119 | Thistory_t bht_history = (history>>_param->_bht_history_shift )&_param->_bht_history_mask; |
---|
120 | Thistory_t bht_num_reg = address & _param->_bht_address_mask; |
---|
121 | |
---|
122 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht_history (old): %x",bht_history); |
---|
123 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht_num_reg : %x",bht_num_reg); |
---|
124 | |
---|
125 | // BHT : shift register |
---|
126 | if (not history_val) |
---|
127 | { |
---|
128 | bht_history = (direction)?_param->_bht_init_take:_param->_bht_init_ntake; |
---|
129 | } |
---|
130 | else |
---|
131 | { |
---|
132 | bht_history = ((bht_history<<1) | direction)&_param->_bht_history_mask ; |
---|
133 | } |
---|
134 | |
---|
135 | pht_bht_history = bht_history; |
---|
136 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht_history (new): %x",bht_history); |
---|
137 | reg_BHT [bht_num_reg] = bht_history; |
---|
138 | } |
---|
139 | |
---|
140 | if (_param->_have_pht) |
---|
141 | { |
---|
142 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht"); |
---|
143 | |
---|
144 | Thistory_t pht_history = (history>>_param->_pht_history_shift )&_param->_pht_history_mask; |
---|
145 | Thistory_t pht_num_bank= (address>>_param->_pht_address_bank_shift )&_param->_pht_address_bank_mask; |
---|
146 | Thistory_t pht_num_reg = pht_bht_history xor ((address&_param->_pht_address_share_mask)<<_param->_pht_address_share_shift); |
---|
147 | |
---|
148 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht_history (old): %x",pht_bht_history); |
---|
149 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_history (old): %x",pht_history); |
---|
150 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_num_reg : %x",pht_num_reg); |
---|
151 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_num_bank : %x",pht_num_bank); |
---|
152 | |
---|
153 | // PHT : saturation counter |
---|
154 | if (not history_val) |
---|
155 | { |
---|
156 | pht_history = (direction)?_param->_pht_init_take:_param->_pht_init_ntake; |
---|
157 | } |
---|
158 | else |
---|
159 | { |
---|
160 | pht_history = (direction==1)?((pht_history<_param->_pht_counter_max)?(pht_history+1):(pht_history)):((pht_history>0)?(pht_history-1):(pht_history)); |
---|
161 | } |
---|
162 | |
---|
163 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_history (new): %x",pht_history); |
---|
164 | |
---|
165 | reg_PHT [pht_num_bank][pht_num_reg] = pht_history; |
---|
166 | } |
---|
167 | } |
---|
168 | } |
---|
169 | } |
---|
170 | |
---|
171 | #if defined(DEBUG) and DEBUG_Two_Level_Branch_Predictor and (DEBUG >= DEBUG_TRACE) |
---|
172 | if (1) |
---|
173 | { |
---|
174 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * Dump Two_Level_Branch_Predictor"); |
---|
175 | |
---|
176 | if (_param->_have_bht) |
---|
177 | { |
---|
178 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * Dump BHT"); |
---|
179 | |
---|
180 | uint32_t limit = 4; |
---|
181 | |
---|
182 | for (uint32_t i=0; i<_param->_bht_nb_shifter; i+=limit) |
---|
183 | { |
---|
184 | std::string str = ""; |
---|
185 | |
---|
186 | for (uint32_t j=0; j<limit; j++) |
---|
187 | { |
---|
188 | uint32_t index = i+j; |
---|
189 | if (index >= _param->_bht_nb_shifter) |
---|
190 | break; |
---|
191 | else |
---|
192 | str+=toString("[%.4d] %.4x ",index,reg_BHT[index]); |
---|
193 | } |
---|
194 | |
---|
195 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," %s",str.c_str()); |
---|
196 | } |
---|
197 | } |
---|
198 | |
---|
199 | if (_param->_have_pht) |
---|
200 | { |
---|
201 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * Dump PHT"); |
---|
202 | |
---|
203 | uint32_t limit = 4; |
---|
204 | |
---|
205 | for (uint32_t num_bank=0; num_bank <_param->_pht_nb_bank; ++num_bank) |
---|
206 | { |
---|
207 | if (_param->_pht_size_bank == 1) |
---|
208 | { |
---|
209 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," [%.4d][0000] %4x",num_bank,reg_PHT[num_bank][0]); |
---|
210 | } |
---|
211 | else |
---|
212 | { |
---|
213 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," [%.4d]",num_bank); |
---|
214 | |
---|
215 | for (uint32_t i=0; i<_param->_pht_size_bank; i+=limit) |
---|
216 | { |
---|
217 | std::string str = ""; |
---|
218 | |
---|
219 | for (uint32_t j=0; j<limit; j++) |
---|
220 | { |
---|
221 | uint32_t index = i+j; |
---|
222 | if (index >= _param->_pht_size_bank) |
---|
223 | break; |
---|
224 | else |
---|
225 | str+=toString("[%.4d] %.4x ",index,reg_PHT[num_bank][index]); |
---|
226 | } |
---|
227 | |
---|
228 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," %s",str.c_str()); |
---|
229 | } |
---|
230 | } |
---|
231 | } |
---|
232 | } |
---|
233 | } |
---|
234 | #endif |
---|
235 | |
---|
236 | #if defined(STATISTICS) or defined(VHDL_TESTBENCH) |
---|
237 | end_cycle (); |
---|
238 | #endif |
---|
239 | |
---|
240 | log_end(Two_Level_Branch_Predictor,FUNCTION); |
---|
241 | }; |
---|
242 | |
---|
243 | }; // end namespace two_level_branch_predictor |
---|
244 | }; // end namespace meta_predictor |
---|
245 | }; // end namespace direction |
---|
246 | }; // end namespace prediction_unit |
---|
247 | }; // end namespace front_end |
---|
248 | }; // end namespace multi_front_end |
---|
249 | }; // end namespace core |
---|
250 | |
---|
251 | }; // end namespace behavioural |
---|
252 | }; // end namespace morpheo |
---|
253 | #endif |
---|