[110] | 1 | #ifdef SYSTEMC |
---|
| 2 | /* |
---|
| 3 | * $Id: Two_Level_Branch_Predictor_transition.cpp 112 2009-03-18 22:36: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" |
---|
| 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); |
---|
[111] | 27 | log_function(Two_Level_Branch_Predictor,FUNCTION,_name.c_str()); |
---|
[110] | 28 | |
---|
[111] | 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); |
---|
[112] | 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); |
---|
[111] | 94 | |
---|
| 95 | // Update if |
---|
| 96 | // * update_on_prediction and miss |
---|
| 97 | // * not update_on_prediction |
---|
[112] | 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 | ) |
---|
[111] | 104 | { |
---|
[112] | 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; |
---|
[111] | 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); |
---|
[112] | 111 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * history_val : %d",direction); |
---|
[111] | 112 | |
---|
| 113 | Thistory_t pht_bht_history = 0; |
---|
| 114 | |
---|
| 115 | if (_param->_have_bht) |
---|
| 116 | { |
---|
[112] | 117 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht"); |
---|
| 118 | |
---|
[111] | 119 | Thistory_t bht_history = (history>>_param->_bht_history_rshift)&_param->_bht_history_mask; |
---|
| 120 | Thistory_t bht_num_reg = address & _param->_bht_address_mask; |
---|
| 121 | |
---|
[112] | 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); |
---|
[111] | 124 | |
---|
| 125 | // BHT : shift register |
---|
[112] | 126 | if (not history_val) |
---|
| 127 | bht_history = (direction)?_param->_bht_init_take:_param->_bht_init_ntake; |
---|
| 128 | else |
---|
| 129 | bht_history = ((bht_history<<1) | direction)&_param->_bht_history_mask ; |
---|
| 130 | |
---|
| 131 | pht_bht_history = bht_history; |
---|
| 132 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht_history (new): %x",bht_history); |
---|
[111] | 133 | reg_BHT [bht_num_reg] = bht_history; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | if (_param->_have_pht) |
---|
| 137 | { |
---|
[112] | 138 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht"); |
---|
| 139 | |
---|
[111] | 140 | Thistory_t pht_history = (history>>_param->_pht_history_rshift)&_param->_pht_history_mask; |
---|
| 141 | Thistory_t pht_num_reg = pht_bht_history xor ((address&_param->_pht_address_share_mask)<<_param->_pht_address_share_lshift); |
---|
| 142 | Thistory_t pht_num_bank= (address>>_param->_pht_address_bank_rshift)&_param->_pht_address_bank_mask; |
---|
| 143 | |
---|
[112] | 144 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * bht_history (old): %x",pht_bht_history); |
---|
| 145 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_history (old): %x",pht_history); |
---|
| 146 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_num_reg : %x",pht_num_reg); |
---|
| 147 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_num_bank : %x",pht_num_bank); |
---|
[111] | 148 | |
---|
| 149 | // PHT : saturation counter |
---|
[112] | 150 | if (not history_val) |
---|
| 151 | pht_history = (direction)?_param->_pht_init_take:_param->_pht_init_ntake; |
---|
| 152 | else |
---|
| 153 | pht_history = (direction==1)?((pht_history<_param->_pht_counter_max)?(pht_history+1):(pht_history)):((pht_history>0)?(pht_history-1):(pht_history)); |
---|
[111] | 154 | |
---|
[112] | 155 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * pht_history (new): %x",pht_history); |
---|
[111] | 156 | |
---|
| 157 | reg_PHT [pht_num_bank][pht_num_reg] = pht_history; |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | #if defined(DEBUG) and DEBUG_Two_Level_Branch_Predictor and (DEBUG >= DEBUG_TRACE) |
---|
[112] | 164 | if (1) |
---|
[111] | 165 | { |
---|
| 166 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * Dump Two_Level_Branch_Predictor"); |
---|
| 167 | |
---|
| 168 | if (_param->_have_bht) |
---|
| 169 | { |
---|
| 170 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * Dump BHT"); |
---|
| 171 | |
---|
| 172 | uint32_t limit = 4; |
---|
| 173 | |
---|
| 174 | for (uint32_t i=0; i<_param->_bht_nb_shifter; i+=limit) |
---|
| 175 | { |
---|
| 176 | std::string str = ""; |
---|
| 177 | |
---|
| 178 | for (uint32_t j=0; j<limit; j++) |
---|
| 179 | { |
---|
| 180 | uint32_t index = i+j; |
---|
| 181 | if (index >= _param->_bht_nb_shifter) |
---|
| 182 | break; |
---|
| 183 | else |
---|
| 184 | str+=toString("[%.4d] %.4x ",index,reg_BHT[index]); |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," %s",str.c_str()); |
---|
| 188 | } |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | if (_param->_have_pht) |
---|
| 192 | { |
---|
| 193 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," * Dump PHT"); |
---|
| 194 | |
---|
| 195 | uint32_t limit = 4; |
---|
| 196 | |
---|
| 197 | for (uint32_t num_bank=0; num_bank <_param->_pht_nb_bank; ++num_bank) |
---|
| 198 | { |
---|
[112] | 199 | if (_param->_pht_size_bank == 1) |
---|
[111] | 200 | { |
---|
[112] | 201 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," [%.4d][0000] %4x",num_bank,reg_PHT[num_bank][0]); |
---|
| 202 | } |
---|
| 203 | else |
---|
| 204 | { |
---|
| 205 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," [%.4d]",num_bank); |
---|
[111] | 206 | |
---|
[112] | 207 | for (uint32_t i=0; i<_param->_pht_size_bank; i+=limit) |
---|
[111] | 208 | { |
---|
[112] | 209 | std::string str = ""; |
---|
| 210 | |
---|
| 211 | for (uint32_t j=0; j<limit; j++) |
---|
| 212 | { |
---|
| 213 | uint32_t index = i+j; |
---|
| 214 | if (index >= _param->_pht_size_bank) |
---|
| 215 | break; |
---|
| 216 | else |
---|
| 217 | str+=toString("[%.4d] %.4x ",index,reg_PHT[num_bank][index]); |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION," %s",str.c_str()); |
---|
[111] | 221 | } |
---|
| 222 | } |
---|
| 223 | } |
---|
| 224 | } |
---|
| 225 | } |
---|
| 226 | #endif |
---|
| 227 | |
---|
[110] | 228 | #if defined(STATISTICS) or defined(VHDL_TESTBENCH) |
---|
| 229 | end_cycle (); |
---|
| 230 | #endif |
---|
| 231 | |
---|
| 232 | log_end(Two_Level_Branch_Predictor,FUNCTION); |
---|
| 233 | }; |
---|
| 234 | |
---|
| 235 | }; // end namespace two_level_branch_predictor |
---|
| 236 | }; // end namespace meta_predictor |
---|
| 237 | }; // end namespace direction |
---|
| 238 | }; // end namespace prediction_unit |
---|
| 239 | }; // end namespace front_end |
---|
| 240 | }; // end namespace multi_front_end |
---|
| 241 | }; // end namespace core |
---|
| 242 | |
---|
| 243 | }; // end namespace behavioural |
---|
| 244 | }; // end namespace morpheo |
---|
| 245 | #endif |
---|