[110] | 1 | #ifdef SYSTEMC |
---|
| 2 | /* |
---|
| 3 | * $Id: Two_Level_Branch_Predictor_transition.cpp 119 2009-05-25 17:40:26Z 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" |
---|
[119] | 10 | // #include <assert.h> |
---|
[110] | 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); |
---|
[111] | 28 | log_function(Two_Level_Branch_Predictor,FUNCTION,_name.c_str()); |
---|
[110] | 29 | |
---|
[111] | 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 : %d",bht_num_reg); |
---|
| 55 | |
---|
[119] | 56 | // #ifdef DEBUG_TEST |
---|
| 57 | // assert(bht_num_reg < _param->_bht_nb_shifter); |
---|
| 58 | // #endif |
---|
| 59 | |
---|
[111] | 60 | Thistory_t bht_history = reg_BHT[bht_num_reg]; |
---|
| 61 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht_history (old): %x",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): %x",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 : %d",pht_num_reg); |
---|
| 74 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_num_bank : %d",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): %x",pht_history); |
---|
| 78 | |
---|
| 79 | // PHT : saturation counter |
---|
| 80 | pht_history = (direction==1)?((pht_history<_param->_pht_counter_max)?(pht_history+1):(pht_history)):((pht_history>0)?(pht_history-1):(pht_history)); |
---|
| 81 | |
---|
| 82 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_history (new): %x",pht_history); |
---|
| 83 | |
---|
| 84 | reg_PHT [pht_num_bank][pht_num_reg] = pht_history; |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | // =================================================================== |
---|
| 90 | // =====[ UPDATE ]==================================================== |
---|
| 91 | // =================================================================== |
---|
| 92 | |
---|
| 93 | for (uint32_t i=0; i<_param->_nb_inst_update; ++i) |
---|
| 94 | if (PORT_READ(in_UPDATE_VAL[i]) and internal_UPDATE_ACK[i]) |
---|
| 95 | { |
---|
| 96 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * UPDATE [%d]",i); |
---|
[112] | 97 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * miss : %d",PORT_READ(in_UPDATE_MISS [i])); |
---|
| 98 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * update_on_predict: %d",_param->_update_on_prediction); |
---|
[111] | 99 | |
---|
| 100 | // Update if |
---|
| 101 | // * update_on_prediction and miss |
---|
| 102 | // * not update_on_prediction |
---|
[112] | 103 | Tcontrol_t history_val = PORT_READ(in_UPDATE_HISTORY_VAL [i]); |
---|
| 104 | |
---|
| 105 | if (not _param->_update_on_prediction or |
---|
| 106 | (_param->_update_on_prediction and PORT_READ(in_UPDATE_MISS [i])) or |
---|
| 107 | not history_val // static_prediction |
---|
| 108 | ) |
---|
[111] | 109 | { |
---|
[112] | 110 | Taddress_t address = PORT_READ(in_UPDATE_ADDRESS [i]); |
---|
| 111 | Thistory_t history = PORT_READ(in_UPDATE_HISTORY [i]); |
---|
| 112 | Tcontrol_t direction = PORT_READ(in_UPDATE_DIRECTION [i])&1; |
---|
[111] | 113 | |
---|
| 114 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * address : %.8x",address); |
---|
| 115 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * direction : %d",direction); |
---|
[112] | 116 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * history_val : %d",direction); |
---|
[111] | 117 | |
---|
| 118 | Thistory_t pht_bht_history = 0; |
---|
| 119 | |
---|
| 120 | if (_param->_have_bht) |
---|
| 121 | { |
---|
[112] | 122 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht"); |
---|
| 123 | |
---|
[115] | 124 | Thistory_t bht_history = (history>>_param->_bht_history_shift )&_param->_bht_history_mask; |
---|
[111] | 125 | Thistory_t bht_num_reg = address & _param->_bht_address_mask; |
---|
| 126 | |
---|
[112] | 127 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht_history (old): %x",bht_history); |
---|
| 128 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht_num_reg : %x",bht_num_reg); |
---|
[111] | 129 | |
---|
| 130 | // BHT : shift register |
---|
[112] | 131 | if (not history_val) |
---|
[115] | 132 | { |
---|
| 133 | bht_history = (direction)?_param->_bht_init_take:_param->_bht_init_ntake; |
---|
| 134 | } |
---|
[112] | 135 | else |
---|
[115] | 136 | { |
---|
| 137 | bht_history = ((bht_history<<1) | direction)&_param->_bht_history_mask ; |
---|
| 138 | } |
---|
[112] | 139 | |
---|
| 140 | pht_bht_history = bht_history; |
---|
| 141 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht_history (new): %x",bht_history); |
---|
[119] | 142 | |
---|
| 143 | // #ifdef DEBUG_TEST |
---|
| 144 | // assert(bht_num_reg < _param->_bht_nb_shifter); |
---|
| 145 | // #endif |
---|
| 146 | |
---|
[111] | 147 | reg_BHT [bht_num_reg] = bht_history; |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | if (_param->_have_pht) |
---|
| 151 | { |
---|
[112] | 152 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht"); |
---|
| 153 | |
---|
[115] | 154 | Thistory_t pht_history = (history>>_param->_pht_history_shift )&_param->_pht_history_mask; |
---|
| 155 | Thistory_t pht_num_bank= (address>>_param->_pht_address_bank_shift )&_param->_pht_address_bank_mask; |
---|
| 156 | Thistory_t pht_num_reg = pht_bht_history xor ((address&_param->_pht_address_share_mask)<<_param->_pht_address_share_shift); |
---|
[111] | 157 | |
---|
[112] | 158 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht_history (old): %x",pht_bht_history); |
---|
| 159 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_history (old): %x",pht_history); |
---|
| 160 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_num_reg : %x",pht_num_reg); |
---|
| 161 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_num_bank : %x",pht_num_bank); |
---|
[111] | 162 | |
---|
| 163 | // PHT : saturation counter |
---|
[112] | 164 | if (not history_val) |
---|
[115] | 165 | { |
---|
| 166 | pht_history = (direction)?_param->_pht_init_take:_param->_pht_init_ntake; |
---|
| 167 | } |
---|
[112] | 168 | else |
---|
[115] | 169 | { |
---|
| 170 | pht_history = (direction==1)?((pht_history<_param->_pht_counter_max)?(pht_history+1):(pht_history)):((pht_history>0)?(pht_history-1):(pht_history)); |
---|
| 171 | } |
---|
[111] | 172 | |
---|
[112] | 173 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_history (new): %x",pht_history); |
---|
[111] | 174 | |
---|
| 175 | reg_PHT [pht_num_bank][pht_num_reg] = pht_history; |
---|
| 176 | } |
---|
| 177 | } |
---|
| 178 | } |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | #if defined(DEBUG) and DEBUG_Two_Level_Branch_Predictor and (DEBUG >= DEBUG_TRACE) |
---|
[119] | 182 | |
---|
| 183 | # if 0 |
---|
[111] | 184 | { |
---|
| 185 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * Dump Two_Level_Branch_Predictor"); |
---|
| 186 | |
---|
| 187 | if (_param->_have_bht) |
---|
| 188 | { |
---|
| 189 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * Dump BHT"); |
---|
| 190 | |
---|
| 191 | uint32_t limit = 4; |
---|
| 192 | |
---|
| 193 | for (uint32_t i=0; i<_param->_bht_nb_shifter; i+=limit) |
---|
| 194 | { |
---|
| 195 | std::string str = ""; |
---|
| 196 | |
---|
| 197 | for (uint32_t j=0; j<limit; j++) |
---|
| 198 | { |
---|
| 199 | uint32_t index = i+j; |
---|
| 200 | if (index >= _param->_bht_nb_shifter) |
---|
| 201 | break; |
---|
| 202 | else |
---|
[119] | 203 | { |
---|
| 204 | str+=toString("[%.4d] %.4x ",index,reg_BHT[index]); |
---|
| 205 | } |
---|
[111] | 206 | } |
---|
| 207 | |
---|
| 208 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," %s",str.c_str()); |
---|
| 209 | } |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | if (_param->_have_pht) |
---|
| 213 | { |
---|
| 214 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * Dump PHT"); |
---|
| 215 | |
---|
| 216 | uint32_t limit = 4; |
---|
| 217 | |
---|
| 218 | for (uint32_t num_bank=0; num_bank <_param->_pht_nb_bank; ++num_bank) |
---|
| 219 | { |
---|
[112] | 220 | if (_param->_pht_size_bank == 1) |
---|
[111] | 221 | { |
---|
[112] | 222 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," [%.4d][0000] %4x",num_bank,reg_PHT[num_bank][0]); |
---|
| 223 | } |
---|
| 224 | else |
---|
| 225 | { |
---|
| 226 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," [%.4d]",num_bank); |
---|
[111] | 227 | |
---|
[112] | 228 | for (uint32_t i=0; i<_param->_pht_size_bank; i+=limit) |
---|
[111] | 229 | { |
---|
[112] | 230 | std::string str = ""; |
---|
| 231 | |
---|
| 232 | for (uint32_t j=0; j<limit; j++) |
---|
| 233 | { |
---|
| 234 | uint32_t index = i+j; |
---|
| 235 | if (index >= _param->_pht_size_bank) |
---|
| 236 | break; |
---|
| 237 | else |
---|
| 238 | str+=toString("[%.4d] %.4x ",index,reg_PHT[num_bank][index]); |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," %s",str.c_str()); |
---|
[111] | 242 | } |
---|
| 243 | } |
---|
| 244 | } |
---|
| 245 | } |
---|
| 246 | } |
---|
[119] | 247 | # endif |
---|
[111] | 248 | #endif |
---|
| 249 | |
---|
[110] | 250 | #if defined(STATISTICS) or defined(VHDL_TESTBENCH) |
---|
| 251 | end_cycle (); |
---|
| 252 | #endif |
---|
| 253 | |
---|
| 254 | log_end(Two_Level_Branch_Predictor,FUNCTION); |
---|
| 255 | }; |
---|
| 256 | |
---|
| 257 | }; // end namespace two_level_branch_predictor |
---|
| 258 | }; // end namespace meta_predictor |
---|
| 259 | }; // end namespace direction |
---|
| 260 | }; // end namespace prediction_unit |
---|
| 261 | }; // end namespace front_end |
---|
| 262 | }; // end namespace multi_front_end |
---|
| 263 | }; // end namespace core |
---|
| 264 | |
---|
| 265 | }; // end namespace behavioural |
---|
| 266 | }; // end namespace morpheo |
---|
| 267 | #endif |
---|