[82] | 1 | #ifdef SYSTEMC |
---|
| 2 | /* |
---|
| 3 | * $Id$ |
---|
| 4 | * |
---|
| 5 | * [ Description ] |
---|
| 6 | * |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #include "Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Prediction_unit_Glue/include/Prediction_unit_Glue.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 prediction_unit_glue { |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | #undef FUNCTION |
---|
| 21 | #define FUNCTION "Prediction_unit_Glue::genMealy_decod" |
---|
| 22 | void Prediction_unit_Glue::genMealy_decod (void) |
---|
| 23 | { |
---|
[88] | 24 | log_begin(Prediction_unit_Glue,FUNCTION); |
---|
| 25 | log_function(Prediction_unit_Glue,FUNCTION,_name.c_str()); |
---|
[82] | 26 | |
---|
[98] | 27 | if (PORT_READ(in_NRESET)) |
---|
| 28 | { |
---|
[88] | 29 | // Init |
---|
[82] | 30 | uint32_t decod_unit = reg_DECOD_PRIORITY; |
---|
[88] | 31 | |
---|
[82] | 32 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * decod_unit : %d",decod_unit); |
---|
| 33 | |
---|
| 34 | Tcontrol_t ack [_param->_nb_inst_decod[decod_unit]]; |
---|
| 35 | |
---|
| 36 | for (uint32_t i=0;i<_param->_nb_inst_decod[decod_unit]; i++) |
---|
| 37 | ack [i] = true; |
---|
| 38 | |
---|
| 39 | Tcontrol_t btb_val [_param->_nb_inst_branch_decod]; |
---|
| 40 | Tcontrol_t ras_val [_param->_nb_inst_branch_decod]; |
---|
| 41 | Tcontrol_t upt_val [_param->_nb_inst_branch_decod]; |
---|
| 42 | |
---|
| 43 | for (uint32_t i=0; i<_param->_nb_inst_branch_decod; i++) |
---|
| 44 | { |
---|
| 45 | btb_val [i] = false; |
---|
| 46 | ras_val [i] = false; |
---|
| 47 | upt_val [i] = false; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | uint32_t port = 0; |
---|
| 51 | for (uint32_t i=0; i<_param->_nb_inst_decod[decod_unit]; i++) |
---|
[107] | 52 | { |
---|
| 53 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * DECOD [%d][%d]",decod_unit,i); |
---|
| 54 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * val : %d",PORT_READ(in_DECOD_VAL [decod_unit][i])); |
---|
| 55 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * port : %d",port); |
---|
| 56 | |
---|
[82] | 57 | // Test if decod_unit have detected a branch |
---|
| 58 | if ((port>=_param->_nb_inst_branch_decod) or |
---|
| 59 | (PORT_READ(in_DECOD_VAL [decod_unit][i]) == 0)) |
---|
[88] | 60 | { |
---|
[107] | 61 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * DECOD [%d][%d] : not valid",decod_unit,i); |
---|
[82] | 62 | ack [i] = false; |
---|
| 63 | } |
---|
| 64 | else |
---|
| 65 | { |
---|
[88] | 66 | Tcontext_t context = (_param->_have_port_context_id)?PORT_READ(in_DECOD_CONTEXT_ID [decod_unit][i]):0; |
---|
| 67 | Tbranch_state_t branch_state = PORT_READ(in_DECOD_BRANCH_STATE [decod_unit][i]); |
---|
| 68 | Tcontrol_t match_inst_ifetch_ptr = PORT_READ(in_DECOD_MATCH_INST_IFETCH_PTR [decod_unit][i]); |
---|
| 69 | Tprediction_ptr_t depth = (_param->_have_port_depth)?PORT_READ(in_DECOD_BRANCH_UPDATE_PREDICTION_ID [decod_unit][i]):0; |
---|
| 70 | Tcontrol_t use_btb = false; |
---|
| 71 | Tcontrol_t use_ras = false; |
---|
| 72 | Tcontrol_t use_upt = true ; // always update upt. |
---|
[82] | 73 | |
---|
[88] | 74 | // Ifetch stage made an miss if : |
---|
| 75 | // * branch is previously predict, but it's not the good |
---|
| 76 | Tcontrol_t miss_ifetch = ((branch_state != BRANCH_STATE_NONE) and (match_inst_ifetch_ptr == 0)); |
---|
| 77 | // Decod stage made an miss if : |
---|
| 78 | // * branch was not detected |
---|
| 79 | Tcontrol_t miss_decod = (branch_state == BRANCH_STATE_NONE); |
---|
[110] | 80 | Tcontrol_t can_continue = false; |
---|
[88] | 81 | |
---|
[107] | 82 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * DECOD [%d][%d] : valid",decod_unit,i); |
---|
[88] | 83 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * branch_state : %d",branch_state); |
---|
| 84 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * match_inst_ifetch_ptr : %d",match_inst_ifetch_ptr); |
---|
| 85 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * depth : [%d] %d",i,depth); |
---|
| 86 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * miss_ifetch : %d",miss_ifetch); |
---|
| 87 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * miss_decod : %d",miss_decod); |
---|
[82] | 88 | |
---|
| 89 | // Test if ifetch have detecte a branch is the packet |
---|
[88] | 90 | if (miss_ifetch or miss_decod) |
---|
[82] | 91 | { |
---|
[88] | 92 | Tbranch_condition_t condition = PORT_READ(in_DECOD_BRANCH_CONDITION [decod_unit][i]); |
---|
[110] | 93 | Tcontrol_t take; |
---|
[88] | 94 | Taddress_t address_src = PORT_READ(in_DECOD_ADDRESS_SRC [decod_unit][i]); |
---|
| 95 | Taddress_t address_dest = PORT_READ(in_DECOD_ADDRESS_DEST [decod_unit][i]); |
---|
[82] | 96 | Tcontrol_t is_accurate; |
---|
| 97 | |
---|
| 98 | // Miss speculation |
---|
| 99 | use_btb = true; |
---|
| 100 | |
---|
| 101 | switch (condition) |
---|
| 102 | { |
---|
| 103 | case BRANCH_CONDITION_NONE_WITH_WRITE_STACK : |
---|
| 104 | { |
---|
[88] | 105 | // l.jal |
---|
| 106 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * BRANCH_CONDITION_NONE_WITH_WRITE_STACK"); |
---|
[82] | 107 | |
---|
[110] | 108 | take = true ; |
---|
[88] | 109 | is_accurate = true ;//PORT_READ(in_DECOD_RAS_HIT [port]); |
---|
| 110 | use_ras = true ; |
---|
| 111 | |
---|
[82] | 112 | PORT_WRITE(out_DECOD_RAS_PUSH [port],1); |
---|
[88] | 113 | PORT_WRITE(out_DECOD_RAS_ADDRESS_PUSH [port],address_src+2); |
---|
[82] | 114 | |
---|
| 115 | break; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | case BRANCH_CONDITION_READ_REGISTER_WITH_WRITE_STACK : |
---|
| 119 | { |
---|
[88] | 120 | // l.jalr |
---|
| 121 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * BRANCH_CONDITION_READ_REGISTER_WITH_WRITE_STACK"); |
---|
| 122 | |
---|
[110] | 123 | take = true ; |
---|
[88] | 124 | is_accurate = false; // address unknow : in a register |
---|
[82] | 125 | use_ras = true; |
---|
| 126 | |
---|
| 127 | PORT_WRITE(out_DECOD_RAS_PUSH [port],1); |
---|
[88] | 128 | PORT_WRITE(out_DECOD_RAS_ADDRESS_PUSH [port],address_src+2); |
---|
[82] | 129 | |
---|
| 130 | break; |
---|
| 131 | } |
---|
| 132 | case BRANCH_CONDITION_READ_STACK : |
---|
| 133 | { |
---|
[88] | 134 | // l.jr with rb=r9 |
---|
| 135 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * BRANCH_CONDITION_READ_STACK"); |
---|
| 136 | |
---|
[110] | 137 | take = true ; |
---|
[82] | 138 | is_accurate = PORT_READ(in_DECOD_RAS_HIT [port]); |
---|
| 139 | use_ras = true; |
---|
| 140 | |
---|
[88] | 141 | PORT_WRITE(out_DECOD_RAS_PUSH [port],0); // POP |
---|
[82] | 142 | address_dest = PORT_READ(in_DECOD_RAS_ADDRESS_POP [port]); |
---|
| 143 | |
---|
| 144 | break; |
---|
| 145 | } |
---|
| 146 | case BRANCH_CONDITION_READ_REGISTER_WITHOUT_WRITE_STACK : |
---|
| 147 | { |
---|
[88] | 148 | // l.jr with rb!=r9 |
---|
| 149 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * BRANCH_CONDITION_READ_REGISTER_WITHOUT_WRITE_STACK"); |
---|
| 150 | |
---|
[82] | 151 | // * READ_REGISTER_WITHOUT_WRITE_STACK : Take but destination is unknow - don't continue |
---|
[110] | 152 | take = true ; |
---|
[88] | 153 | is_accurate = false; // address unknow : in a register |
---|
[82] | 154 | |
---|
| 155 | break; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | case BRANCH_CONDITION_FLAG_UNSET : |
---|
| 159 | case BRANCH_CONDITION_FLAG_SET : |
---|
| 160 | { |
---|
[88] | 161 | // l.bf, l.bnf |
---|
[82] | 162 | // * FLAG : static direction and destination is know |
---|
[88] | 163 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * BRANCH_CONDITION_FLAG"); |
---|
[82] | 164 | |
---|
[110] | 165 | take = PORT_READ(in_DECOD_BRANCH_DIRECTION [decod_unit][i]); |
---|
[88] | 166 | is_accurate = true; // address dest is know |
---|
| 167 | |
---|
[82] | 168 | break; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | case BRANCH_CONDITION_NONE_WITHOUT_WRITE_STACK : |
---|
| 172 | { |
---|
[88] | 173 | // l.j |
---|
| 174 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * BRANCH_CONDITION_NONE_WITHOUT_WRITE_STACK"); |
---|
[82] | 175 | |
---|
[110] | 176 | take = true; |
---|
[88] | 177 | is_accurate = true; |
---|
[82] | 178 | |
---|
| 179 | break; |
---|
| 180 | } |
---|
| 181 | } |
---|
| 182 | |
---|
[110] | 183 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * take : %d",take); |
---|
| 184 | |
---|
[82] | 185 | if (use_btb) |
---|
| 186 | { |
---|
| 187 | if (_param->_have_port_context_id) |
---|
| 188 | PORT_WRITE(out_DECOD_BTB_CONTEXT_ID [port],context); |
---|
| 189 | PORT_WRITE(out_DECOD_BTB_ADDRESS_SRC [port],address_src); |
---|
| 190 | PORT_WRITE(out_DECOD_BTB_ADDRESS_DEST [port],address_dest); |
---|
| 191 | PORT_WRITE(out_DECOD_BTB_CONDITION [port],condition); |
---|
[110] | 192 | PORT_WRITE(out_DECOD_BTB_LAST_TAKE [port],take); |
---|
[82] | 193 | PORT_WRITE(out_DECOD_BTB_MISS_PREDICTION [port],1); |
---|
| 194 | PORT_WRITE(out_DECOD_BTB_IS_ACCURATE [port],is_accurate); |
---|
| 195 | } |
---|
| 196 | if (use_ras) |
---|
| 197 | { |
---|
| 198 | miss_decod |= not PORT_READ(in_DECOD_RAS_HIT [port]); |
---|
| 199 | |
---|
| 200 | if (_param->_have_port_context_id) |
---|
| 201 | PORT_WRITE(out_DECOD_RAS_CONTEXT_ID [port],context); |
---|
| 202 | PORT_WRITE(out_DECOD_RAS_MISS_PREDICTION [port],1); |
---|
| 203 | } |
---|
| 204 | if (use_upt) |
---|
| 205 | { |
---|
[88] | 206 | PORT_WRITE(out_DECOD_UPT_BTB_ADDRESS_SRC [port],address_src); |
---|
| 207 | PORT_WRITE(out_DECOD_UPT_BTB_ADDRESS_DEST[port],address_dest); |
---|
| 208 | PORT_WRITE(out_DECOD_UPT_BTB_CONDITION [port],condition); |
---|
[110] | 209 | PORT_WRITE(out_DECOD_UPT_BTB_LAST_TAKE [port],take); |
---|
[88] | 210 | PORT_WRITE(out_DECOD_UPT_RAS_ADDRESS [port],PORT_READ(in_DECOD_RAS_ADDRESS_POP [port])); |
---|
| 211 | PORT_WRITE(out_DECOD_UPT_IS_ACCURATE [port],is_accurate); |
---|
[82] | 212 | } |
---|
[110] | 213 | |
---|
| 214 | can_continue = false; // need update upt |
---|
[82] | 215 | } |
---|
[110] | 216 | else |
---|
| 217 | { |
---|
| 218 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * hit"); |
---|
[82] | 219 | |
---|
[110] | 220 | if (branch_state == BRANCH_STATE_SPEC_NTAKE) |
---|
| 221 | can_continue = PORT_READ(in_DECOD_UPT_CAN_CONTINUE [port]); |
---|
| 222 | else |
---|
| 223 | // BRANCH_STATE_NONE -> miss |
---|
| 224 | // BRANCH_STATE_NSPEC_TAKE -> take |
---|
| 225 | // BRANCH_STATE_SPEC_TAKE -> take |
---|
| 226 | can_continue = false; |
---|
| 227 | |
---|
[88] | 228 | // miss_decod = false; |
---|
| 229 | // // Hit speculation |
---|
[110] | 230 | } |
---|
[82] | 231 | |
---|
| 232 | // in all case |
---|
[110] | 233 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * can_continue : %d",can_continue); |
---|
| 234 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * use_btb : %d",use_btb); |
---|
| 235 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * use_ras : %d",use_ras); |
---|
| 236 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * use_upt : %d",use_upt); |
---|
[82] | 237 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * btb_ack [%d] : %d",port,PORT_READ(in_DECOD_BTB_ACK [port])); |
---|
| 238 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * ras_ack [%d] : %d",port,PORT_READ(in_DECOD_RAS_ACK [port])); |
---|
| 239 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * upt_ack [%d] : %d",port,PORT_READ(in_DECOD_UPT_ACK [port])); |
---|
| 240 | |
---|
| 241 | btb_val [port] = (use_btb and |
---|
| 242 | (not use_ras or (use_ras and PORT_READ(in_DECOD_RAS_ACK [port]))) and |
---|
| 243 | (not use_upt or (use_upt and PORT_READ(in_DECOD_UPT_ACK [port])))); |
---|
| 244 | |
---|
| 245 | ras_val [port] = (use_ras and |
---|
| 246 | (not use_btb or (use_btb and PORT_READ(in_DECOD_BTB_ACK [port]))) and |
---|
| 247 | (not use_upt or (use_upt and PORT_READ(in_DECOD_UPT_ACK [port])))); |
---|
| 248 | |
---|
| 249 | upt_val [port] = (use_upt and |
---|
| 250 | (not use_btb or (use_btb and PORT_READ(in_DECOD_BTB_ACK [port]))) and |
---|
| 251 | (not use_ras or (use_ras and PORT_READ(in_DECOD_RAS_ACK [port])))); |
---|
| 252 | |
---|
| 253 | if (use_btb) |
---|
| 254 | ack [i] &= btb_val [port] and PORT_READ(in_DECOD_BTB_ACK [port]); |
---|
| 255 | if (use_ras) |
---|
| 256 | ack [i] &= ras_val [port] and PORT_READ(in_DECOD_RAS_ACK [port]); |
---|
| 257 | if (use_upt) |
---|
| 258 | ack [i] &= upt_val [port] and PORT_READ(in_DECOD_UPT_ACK [port]); |
---|
| 259 | |
---|
| 260 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * btb_val [%d] : %d",port,btb_val [port]); |
---|
| 261 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * ras_val [%d] : %d",port,ras_val [port]); |
---|
| 262 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * upt_val [%d] : %d",port,upt_val [port]); |
---|
| 263 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * ack [%d] : %d",i ,ack [i ]); |
---|
| 264 | |
---|
| 265 | if (_param->_have_port_context_id) |
---|
| 266 | PORT_WRITE(out_DECOD_UPT_CONTEXT_ID [port],context); |
---|
| 267 | PORT_WRITE(out_DECOD_UPT_MISS_IFETCH [port],miss_ifetch); |
---|
| 268 | PORT_WRITE(out_DECOD_UPT_MISS_DECOD [port],miss_decod ); |
---|
[88] | 269 | if (_param->_have_port_depth) |
---|
[82] | 270 | PORT_WRITE(out_DECOD_UPT_UPDATE_PREDICTION_ID [port],depth); |
---|
[110] | 271 | PORT_WRITE(out_DECOD_CAN_CONTINUE [decod_unit][i], can_continue); |
---|
| 272 | |
---|
[107] | 273 | port ++; // have find port |
---|
[82] | 274 | } |
---|
[107] | 275 | } |
---|
[82] | 276 | |
---|
[88] | 277 | // Write output |
---|
[82] | 278 | for (uint32_t i=0; i<_param->_nb_inst_branch_decod; i++) |
---|
| 279 | { |
---|
| 280 | PORT_WRITE(out_DECOD_BTB_VAL [i], btb_val [i]); |
---|
| 281 | PORT_WRITE(out_DECOD_RAS_VAL [i], ras_val [i]); |
---|
| 282 | PORT_WRITE(out_DECOD_UPT_VAL [i], upt_val [i]); |
---|
| 283 | } |
---|
| 284 | |
---|
| 285 | for (uint32_t i=0; i<_param->_nb_decod_unit; i++) |
---|
| 286 | for (uint32_t j=0; j<_param->_nb_inst_decod[i]; j++) |
---|
| 287 | if (i!= decod_unit) |
---|
| 288 | PORT_WRITE(out_DECOD_ACK [i][j], 0); |
---|
| 289 | else |
---|
| 290 | PORT_WRITE(out_DECOD_ACK [i][j], ack[j]); |
---|
[98] | 291 | } |
---|
[123] | 292 | else |
---|
| 293 | { |
---|
| 294 | // Reset |
---|
| 295 | for (uint32_t i=0; i<_param->_nb_inst_branch_decod; i++) |
---|
| 296 | { |
---|
| 297 | PORT_WRITE(out_DECOD_BTB_VAL [i], 0); |
---|
| 298 | PORT_WRITE(out_DECOD_RAS_VAL [i], 0); |
---|
| 299 | PORT_WRITE(out_DECOD_UPT_VAL [i], 0); |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | for (uint32_t i=0; i<_param->_nb_decod_unit; i++) |
---|
| 303 | for (uint32_t j=0; j<_param->_nb_inst_decod[i]; j++) |
---|
| 304 | PORT_WRITE(out_DECOD_ACK [i][j], 0); |
---|
| 305 | } |
---|
[88] | 306 | log_end(Prediction_unit_Glue,FUNCTION); |
---|
[82] | 307 | }; |
---|
| 308 | |
---|
| 309 | }; // end namespace prediction_unit_glue |
---|
| 310 | }; // end namespace prediction_unit |
---|
| 311 | }; // end namespace front_end |
---|
| 312 | }; // end namespace multi_front_end |
---|
| 313 | }; // end namespace core |
---|
| 314 | |
---|
| 315 | }; // end namespace behavioural |
---|
| 316 | }; // end namespace morpheo |
---|
| 317 | #endif |
---|