[78] | 1 | #ifdef SYSTEMC |
---|
| 2 | /* |
---|
| 3 | * $Id: Decod_genMealy.cpp 123 2009-06-08 20:43:30Z rosiere $ |
---|
| 4 | * |
---|
| 5 | * [ Description ] |
---|
| 6 | * |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #include "Behavioural/Core/Multi_Front_end/Front_end/Decod_unit/Decod/include/Decod.h" |
---|
| 10 | |
---|
| 11 | namespace morpheo { |
---|
| 12 | namespace behavioural { |
---|
| 13 | namespace core { |
---|
| 14 | namespace multi_front_end { |
---|
| 15 | namespace front_end { |
---|
| 16 | namespace decod_unit { |
---|
| 17 | namespace decod { |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | #undef FUNCTION |
---|
| 21 | #define FUNCTION "Decod::genMealy" |
---|
| 22 | void Decod::genMealy (void) |
---|
| 23 | { |
---|
[88] | 24 | log_begin(Decod,FUNCTION); |
---|
| 25 | log_function(Decod,FUNCTION,_name.c_str()); |
---|
[78] | 26 | |
---|
[123] | 27 | if (PORT_READ(in_NRESET)) |
---|
| 28 | { |
---|
[78] | 29 | //----------------------------------- |
---|
| 30 | // Initialization |
---|
| 31 | //----------------------------------- |
---|
[86] | 32 | Tcontrol_t context_event_val = false; |
---|
[78] | 33 | Tcontrol_t ifetch_ack [_param->_nb_context][_param->_max_nb_inst_fetch]; |
---|
| 34 | for (uint32_t i=0; i<_param->_nb_context; i++) |
---|
| 35 | for (uint32_t j=0; j<_param->_nb_inst_fetch[i]; j++) |
---|
| 36 | ifetch_ack [i][j] = false; |
---|
| 37 | |
---|
| 38 | Tcontrol_t predict_val [_param->_nb_inst_decod]; |
---|
| 39 | Tcontrol_t decod_val [_param->_nb_inst_decod]; |
---|
| 40 | for (uint32_t i=0; i<_param->_nb_inst_decod; i++) |
---|
| 41 | { |
---|
| 42 | decod_val [i] = false; |
---|
[88] | 43 | predict_val [i] = false; |
---|
[78] | 44 | } |
---|
| 45 | |
---|
| 46 | Tcontrol_t can_continue [_param->_nb_context]; |
---|
[110] | 47 | Tcontrol_t have_decod_branch [_param->_nb_context]; |
---|
[78] | 48 | |
---|
| 49 | for (uint32_t i=0; i<_param->_nb_context; i++) |
---|
| 50 | { |
---|
| 51 | internal_CONTEXT_HAVE_TRANSACTION [i] = false; |
---|
| 52 | internal_CONTEXT_ADDRESS_PREVIOUS [i] = reg_CONTEXT_ADDRESS_PREVIOUS [i]; |
---|
| 53 | internal_CONTEXT_IS_DELAY_SLOT [i] = reg_CONTEXT_IS_DELAY_SLOT [i]; |
---|
[87] | 54 | |
---|
[78] | 55 | can_continue [i] = PORT_READ(in_CONTEXT_DECOD_ENABLE [i]); |
---|
[110] | 56 | have_decod_branch [i] = false; |
---|
[78] | 57 | } |
---|
| 58 | |
---|
| 59 | //----------------------------------- |
---|
| 60 | // Loop of decod |
---|
| 61 | //----------------------------------- |
---|
| 62 | // scan all decod "slot_out" |
---|
[88] | 63 | std::list<generic::priority::select_t> * select = _priority->select(); |
---|
| 64 | std::list<generic::priority::select_t>::iterator it=select->begin(); |
---|
[78] | 65 | for (uint32_t i=0; i<_param->_nb_inst_decod; i++) |
---|
| 66 | { |
---|
[119] | 67 | log_printf(TRACE,Decod,FUNCTION," * DECOD [%d]",i); |
---|
| 68 | |
---|
[88] | 69 | while ((it != select->end()) and // have a no scanned "slot_in" ? |
---|
[78] | 70 | (decod_val [i] == false) and // have not a previous selected entry? |
---|
| 71 | (context_event_val == false)) // Have not a context_event (spr_access, exception, ...) |
---|
| 72 | { |
---|
[107] | 73 | // predict_val [i] = false; |
---|
[78] | 74 | |
---|
[88] | 75 | Tcontext_t x = it->grp; |
---|
| 76 | uint32_t y = it->elt; |
---|
[78] | 77 | |
---|
[119] | 78 | log_printf(TRACE,Decod,FUNCTION," * IFETCH [%d][%d]",x,y); |
---|
| 79 | log_printf(TRACE,Decod,FUNCTION," * in_IFETCH_VAL : %d",PORT_READ(in_IFETCH_VAL [x][y])); |
---|
| 80 | log_printf(TRACE,Decod,FUNCTION," * can_continue : %d",can_continue [x] ); |
---|
| 81 | |
---|
[78] | 82 | // Test if this instruction is valid |
---|
| 83 | if ((PORT_READ(in_IFETCH_VAL [x][y]) == 1) and // entry is valid |
---|
| 84 | (can_continue [x] == 1)) // context can decod instruction (have not a previous event) |
---|
| 85 | { |
---|
[119] | 86 | log_printf(TRACE,Decod,FUNCTION," * decod_ack : %d",PORT_READ(in_DECOD_ACK [i])); |
---|
[78] | 87 | |
---|
| 88 | decod_val [i] = true; // fetch_val and decod_enable |
---|
| 89 | ifetch_ack [x][y] = PORT_READ(in_DECOD_ACK [i]); // fetch_val and decod_enable and decod_ack |
---|
| 90 | |
---|
[86] | 91 | Tgeneral_data_t addr = PORT_READ(in_IFETCH_ADDRESS [x])+y; |
---|
[78] | 92 | |
---|
| 93 | _decod_instruction->_instruction = PORT_READ(in_IFETCH_INSTRUCTION [x][y]); |
---|
| 94 | _decod_instruction->_context_id = x; |
---|
| 95 | _decod_instruction->_address_previous = internal_CONTEXT_ADDRESS_PREVIOUS [x]; |
---|
| 96 | _decod_instruction->_address = addr; //Compute the current address |
---|
[86] | 97 | _decod_instruction->_address_next = addr+1; |
---|
[78] | 98 | _decod_instruction->_is_delay_slot = internal_CONTEXT_IS_DELAY_SLOT [x]; |
---|
| 99 | |
---|
[88] | 100 | // Test IFetch exception |
---|
| 101 | Texception_t ifetch_exception = PORT_READ(in_IFETCH_EXCEPTION [x]); |
---|
[86] | 102 | |
---|
[88] | 103 | if (ifetch_exception == EXCEPTION_IFETCH_NONE) |
---|
| 104 | { |
---|
| 105 | // Decod ! |
---|
[119] | 106 | log_printf(TRACE,Decod,FUNCTION," * address : %.8x (%.8x)",addr,(addr<<2)); |
---|
| 107 | log_printf(TRACE,Decod,FUNCTION," * is_delay_slot : %d",internal_CONTEXT_IS_DELAY_SLOT [x]); |
---|
[88] | 108 | |
---|
| 109 | instruction_decod (_decod_instruction, _decod_param[x]); |
---|
[107] | 110 | |
---|
[119] | 111 | log_printf(TRACE,Decod,FUNCTION," * address_next : %.8x (%.8x)",_decod_instruction->_address_next,(_decod_instruction->_address_next<<2)); |
---|
[88] | 112 | } |
---|
| 113 | else |
---|
| 114 | { |
---|
| 115 | // No decod : nop |
---|
| 116 | instruction_l_nop (_decod_instruction, _decod_param[x]); |
---|
[78] | 117 | |
---|
[88] | 118 | _decod_instruction->_exception_use = EXCEPTION_USE_NONE; |
---|
| 119 | _decod_instruction->_exception = exception_ifetch_to_exception_decod(ifetch_exception); |
---|
| 120 | |
---|
| 121 | // INSTRUCTION_TLB |
---|
| 122 | // INSTRUCTION_PAGE |
---|
| 123 | // BUS_ERROR |
---|
| 124 | if (_decod_instruction->_is_delay_slot) |
---|
| 125 | _decod_instruction->_address_next = _decod_instruction->_address_previous; |
---|
| 126 | else |
---|
| 127 | _decod_instruction->_address_next = _decod_instruction->_address; |
---|
| 128 | |
---|
| 129 | _decod_instruction->_event_type = EVENT_TYPE_EXCEPTION; |
---|
| 130 | } |
---|
[78] | 131 | |
---|
[105] | 132 | Ttype_t type = _decod_instruction->_type; |
---|
[110] | 133 | // Depth current. If have decod a branch and i can continue : depth = depth_next |
---|
| 134 | Tdepth_t depth = (_param->_have_port_depth)?PORT_READ(in_CONTEXT_DEPTH [x]):0; |
---|
[88] | 135 | |
---|
[110] | 136 | if ((_param->_nb_branch_speculated[x] > 0) and have_decod_branch [x]) |
---|
| 137 | depth = (depth+1)%_param->_nb_branch_speculated[x]; |
---|
| 138 | |
---|
[78] | 139 | if (_param->_have_port_context_id) |
---|
| 140 | PORT_WRITE(out_DECOD_CONTEXT_ID [i], x); |
---|
| 141 | if (_param->_have_port_depth) |
---|
[88] | 142 | PORT_WRITE(out_DECOD_DEPTH [i], depth); |
---|
[78] | 143 | PORT_WRITE(out_DECOD_TYPE [i], type); |
---|
| 144 | PORT_WRITE(out_DECOD_OPERATION [i], _decod_instruction->_operation ); |
---|
[88] | 145 | PORT_WRITE(out_DECOD_NO_EXECUTE [i], _decod_instruction->_no_execute ); |
---|
[78] | 146 | PORT_WRITE(out_DECOD_IS_DELAY_SLOT [i], _decod_instruction->_is_delay_slot ); |
---|
[108] | 147 | #ifdef DEBUG |
---|
| 148 | PORT_WRITE(out_DECOD_ADDRESS [i], addr); |
---|
| 149 | #endif |
---|
[105] | 150 | // if ((type == TYPE_BRANCH) and |
---|
| 151 | // ((_decod_instruction->_branch_condition = BRANCH_CONDITION_FLAG_SET) or |
---|
| 152 | // (_decod_instruction->_branch_condition = BRANCH_CONDITION_FLAG_UNSET))) |
---|
| 153 | // PORT_WRITE(out_DECOD_ADDRESS_NEXT [i], _decod_instruction->_address+2); |
---|
| 154 | // else |
---|
| 155 | PORT_WRITE(out_DECOD_ADDRESS_NEXT [i], _decod_instruction->_address_next ); |
---|
[78] | 156 | PORT_WRITE(out_DECOD_HAS_IMMEDIAT [i], _decod_instruction->_has_immediat ); |
---|
| 157 | PORT_WRITE(out_DECOD_IMMEDIAT [i], _decod_instruction->_immediat ); |
---|
| 158 | PORT_WRITE(out_DECOD_READ_RA [i], _decod_instruction->_read_ra ); |
---|
| 159 | PORT_WRITE(out_DECOD_NUM_REG_RA [i], _decod_instruction->_num_reg_ra ); |
---|
| 160 | PORT_WRITE(out_DECOD_READ_RB [i], _decod_instruction->_read_rb ); |
---|
| 161 | PORT_WRITE(out_DECOD_NUM_REG_RB [i], _decod_instruction->_num_reg_rb ); |
---|
| 162 | PORT_WRITE(out_DECOD_READ_RC [i], _decod_instruction->_read_rc ); |
---|
| 163 | PORT_WRITE(out_DECOD_NUM_REG_RC [i], _decod_instruction->_num_reg_rc ); |
---|
[101] | 164 | PORT_WRITE(out_DECOD_WRITE_RD [i],(_decod_instruction->_num_reg_rd!=0)?_decod_instruction->_write_rd:0); |
---|
[78] | 165 | PORT_WRITE(out_DECOD_NUM_REG_RD [i], _decod_instruction->_num_reg_rd ); |
---|
| 166 | PORT_WRITE(out_DECOD_WRITE_RE [i], _decod_instruction->_write_re ); |
---|
| 167 | PORT_WRITE(out_DECOD_NUM_REG_RE [i], _decod_instruction->_num_reg_re ); |
---|
| 168 | PORT_WRITE(out_DECOD_EXCEPTION_USE [i], _decod_instruction->_exception_use ); |
---|
[88] | 169 | // PORT_WRITE(out_DECOD_EXCEPTION [i], _decod_instruction->_exception ); |
---|
[78] | 170 | |
---|
[101] | 171 | // Branch predictor can accept : the depth is valid |
---|
[119] | 172 | log_printf(TRACE,Decod,FUNCTION," * context_depth_val : %d",PORT_READ(in_CONTEXT_DEPTH_VAL [x])); |
---|
[101] | 173 | decod_val [i] &= PORT_READ(in_CONTEXT_DEPTH_VAL [x]); |
---|
| 174 | ifetch_ack [x][y] &= PORT_READ(in_CONTEXT_DEPTH_VAL [x]); |
---|
| 175 | |
---|
[78] | 176 | if (type == TYPE_BRANCH) |
---|
| 177 | { |
---|
[119] | 178 | log_printf(TRACE,Decod,FUNCTION," * Instruction is branch"); |
---|
| 179 | log_printf(TRACE,Decod,FUNCTION," * predict_val : %d",ifetch_ack [x][y]); |
---|
| 180 | log_printf(TRACE,Decod,FUNCTION," * predict_ack : %d",PORT_READ(in_PREDICT_ACK [i])); |
---|
| 181 | |
---|
| 182 | log_printf(TRACE,Decod,FUNCTION," * address src : %.8x (%.8x)",_decod_instruction->_address ,_decod_instruction->_address <<2); |
---|
| 183 | log_printf(TRACE,Decod,FUNCTION," * address dest : %.8x (%.8x)",_decod_instruction->_address_next,_decod_instruction->_address_next<<2); |
---|
[107] | 184 | |
---|
[110] | 185 | // test if have already decod an branch : one branch per context |
---|
| 186 | predict_val [i] = not have_decod_branch [x] and ifetch_ack [x][y] // and decod_val [i] |
---|
[78] | 187 | ; |
---|
[110] | 188 | decod_val [i] &= not have_decod_branch [x] and PORT_READ(in_PREDICT_ACK [i]);// predict_ack and fetch_val and decod_enable |
---|
| 189 | ifetch_ack [x][y] &= not have_decod_branch [x] and PORT_READ(in_PREDICT_ACK [i]);// predict_ack and fetch_val and decod_enable and decod_ack |
---|
[101] | 190 | |
---|
[78] | 191 | if (_param->_have_port_context_id) |
---|
| 192 | PORT_WRITE(out_PREDICT_CONTEXT_ID [i],x); |
---|
| 193 | PORT_WRITE(out_PREDICT_MATCH_INST_IFETCH_PTR [i],y == ((_param->_have_port_inst_ifetch_ptr)?PORT_READ(in_IFETCH_INST_IFETCH_PTR [x]):0)); |
---|
| 194 | PORT_WRITE(out_PREDICT_BRANCH_STATE [i],PORT_READ(in_IFETCH_BRANCH_STATE [x])); |
---|
[88] | 195 | if (_param->_have_port_depth) |
---|
| 196 | PORT_WRITE(out_PREDICT_BRANCH_UPDATE_PREDICTION_ID [i],PORT_READ(in_IFETCH_BRANCH_UPDATE_PREDICTION_ID [x])); |
---|
[78] | 197 | PORT_WRITE(out_PREDICT_BRANCH_CONDITION [i],_decod_instruction->_branch_condition ); |
---|
| 198 | // PORT_WRITE(out_PREDICT_BRANCH_STACK_WRITE [i],_decod_instruction->_branch_stack_write); |
---|
| 199 | PORT_WRITE(out_PREDICT_BRANCH_DIRECTION [i],_decod_instruction->_branch_direction ); |
---|
| 200 | PORT_WRITE(out_PREDICT_ADDRESS_SRC [i],_decod_instruction->_address ); |
---|
| 201 | PORT_WRITE(out_PREDICT_ADDRESS_DEST [i],_decod_instruction->_address_next ); |
---|
| 202 | |
---|
[110] | 203 | // can continue is set if direction is "not take" (also, continue is sequential order) |
---|
| 204 | |
---|
| 205 | // can_continue [x] = false; // one branch per context, the DS don't execute |
---|
[120] | 206 | can_continue [x]&= PORT_READ(in_PREDICT_CAN_CONTINUE [i]); // one branch per context, the DS don't execute |
---|
[110] | 207 | have_decod_branch [x] = true; |
---|
[120] | 208 | |
---|
| 209 | log_printf(TRACE,Decod,FUNCTION," * predict_can_continue : %d",PORT_READ(in_PREDICT_CAN_CONTINUE [i])); |
---|
| 210 | } |
---|
[78] | 211 | |
---|
| 212 | Tevent_type_t event_type = _decod_instruction->_event_type; |
---|
| 213 | if (event_type != EVENT_TYPE_NONE) |
---|
| 214 | { |
---|
[119] | 215 | log_printf(TRACE,Decod,FUNCTION," * Instruction make an EVENT (%s)",toString(event_type).c_str()); |
---|
| 216 | log_printf(TRACE,Decod,FUNCTION," * context_event_ack : %d",PORT_READ(in_CONTEXT_EVENT_ACK)); |
---|
| 217 | |
---|
[78] | 218 | // speculative jump at the exception handler |
---|
| 219 | // if type = TYPE_BRANCH, also event_type == EVENT_TYPE_NONE |
---|
| 220 | context_event_val = ifetch_ack [x][y] // and decod_val [i] |
---|
| 221 | ; |
---|
| 222 | decod_val [i] &= PORT_READ(in_CONTEXT_EVENT_ACK);// context_event_ack and fetch_val and decod_enable |
---|
| 223 | ifetch_ack [x][y] &= PORT_READ(in_CONTEXT_EVENT_ACK);// context_event_ack and fetch_val and decod_enable and decod_ack |
---|
| 224 | |
---|
| 225 | if (_param->_have_port_context_id) |
---|
| 226 | PORT_WRITE(out_CONTEXT_EVENT_CONTEXT_ID , x); |
---|
[88] | 227 | if (_param->_have_port_depth) |
---|
| 228 | PORT_WRITE(out_CONTEXT_EVENT_DEPTH , depth); |
---|
[78] | 229 | PORT_WRITE(out_CONTEXT_EVENT_TYPE , _decod_instruction->_event_type ); |
---|
| 230 | PORT_WRITE(out_CONTEXT_EVENT_IS_DELAY_SLOT, _decod_instruction->_is_delay_slot ); |
---|
| 231 | PORT_WRITE(out_CONTEXT_EVENT_ADDRESS , _decod_instruction->_address ); |
---|
| 232 | PORT_WRITE(out_CONTEXT_EVENT_ADDRESS_EPCR , _decod_instruction->_address_next ); |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | // fetch_ack = |
---|
| 236 | // ((event_type == EVENT_TYPE_NONE) or ((event_type != EVENT_TYPE_NONE) and context_event_ack)) and |
---|
| 237 | // ((type == TYPE_BRANCH ) or ((type != TYPE_BRANCH ) and predict_ack )) and |
---|
| 238 | // fetch_val and decod_ack and decod_enable and true (is decod_val) |
---|
| 239 | |
---|
| 240 | // To compute the "next previous" address |
---|
| 241 | Tcontrol_t have_transaction = ifetch_ack [x][y]; |
---|
| 242 | |
---|
| 243 | internal_CONTEXT_HAVE_TRANSACTION [x] |= have_transaction; |
---|
| 244 | if (have_transaction) |
---|
| 245 | { |
---|
| 246 | internal_CONTEXT_ADDRESS_PREVIOUS [x] = addr; |
---|
| 247 | internal_CONTEXT_IS_DELAY_SLOT [x] = (type == TYPE_BRANCH); // next is a delay slot if current have branch type |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | can_continue [x] &= have_transaction; // to have a in order decod !!! if a previous instruction can decod, also next instruction can't decod. |
---|
[120] | 251 | |
---|
| 252 | log_printf(TRACE,Decod,FUNCTION," * have_transaction : %d",have_transaction); |
---|
| 253 | |
---|
[78] | 254 | } |
---|
[87] | 255 | |
---|
[88] | 256 | log_printf(TRACE,Decod,FUNCTION," - num_(decod, context, fetch) : %d %d %d",i, x, y); |
---|
[119] | 257 | log_printf(TRACE,Decod,FUNCTION," - ifetch_ack : %d",ifetch_ack [x][y]); |
---|
| 258 | log_printf(TRACE,Decod,FUNCTION," - context_event_val : %d",context_event_val ); |
---|
| 259 | log_printf(TRACE,Decod,FUNCTION," - predict_val : %d",predict_val [i] ); |
---|
| 260 | log_printf(TRACE,Decod,FUNCTION," - decod_val : %d",decod_val [i] ); |
---|
[78] | 261 | |
---|
| 262 | it ++; |
---|
| 263 | } |
---|
| 264 | } |
---|
| 265 | //----------------------------------- |
---|
| 266 | // Write output |
---|
| 267 | //----------------------------------- |
---|
| 268 | |
---|
| 269 | for (uint32_t i=0; i<_param->_nb_context; i++) |
---|
| 270 | for (uint32_t j=0; j<_param->_nb_inst_fetch[i]; j++) |
---|
| 271 | PORT_WRITE(out_IFETCH_ACK [i][j], ifetch_ack [i][j]); |
---|
| 272 | |
---|
| 273 | PORT_WRITE(out_CONTEXT_EVENT_VAL, context_event_val); |
---|
| 274 | |
---|
| 275 | for (uint32_t i=0; i<_param->_nb_inst_decod; i++) |
---|
| 276 | { |
---|
| 277 | PORT_WRITE(out_PREDICT_VAL [i], predict_val [i]); |
---|
| 278 | PORT_WRITE(out_DECOD_VAL [i], decod_val [i]); |
---|
[88] | 279 | |
---|
| 280 | #ifdef STATISTICS |
---|
| 281 | internal_DECOD_VAL [i] = decod_val [i]; |
---|
| 282 | #endif |
---|
[78] | 283 | } |
---|
[123] | 284 | } |
---|
| 285 | else |
---|
| 286 | { |
---|
| 287 | for (uint32_t i=0; i<_param->_nb_context; i++) |
---|
| 288 | { |
---|
| 289 | internal_CONTEXT_HAVE_TRANSACTION [i] = false; |
---|
| 290 | // internal_CONTEXT_ADDRESS_PREVIOUS [i] = reg_CONTEXT_ADDRESS_PREVIOUS [i]; |
---|
| 291 | // internal_CONTEXT_IS_DELAY_SLOT [i] = reg_CONTEXT_IS_DELAY_SLOT [i]; |
---|
| 292 | for (uint32_t j=0; j<_param->_nb_inst_fetch[i]; j++) |
---|
| 293 | PORT_WRITE(out_IFETCH_ACK [i][j], 0); |
---|
| 294 | } |
---|
[78] | 295 | |
---|
[123] | 296 | PORT_WRITE(out_CONTEXT_EVENT_VAL, 0); |
---|
| 297 | |
---|
| 298 | for (uint32_t i=0; i<_param->_nb_inst_decod; i++) |
---|
| 299 | { |
---|
| 300 | PORT_WRITE(out_PREDICT_VAL [i], 0); |
---|
| 301 | PORT_WRITE(out_DECOD_VAL [i], 0); |
---|
| 302 | |
---|
| 303 | #ifdef STATISTICS |
---|
| 304 | internal_DECOD_VAL [i] = 0; |
---|
| 305 | #endif |
---|
| 306 | } |
---|
| 307 | } |
---|
| 308 | |
---|
[88] | 309 | log_end(Decod,FUNCTION); |
---|
[78] | 310 | }; |
---|
| 311 | |
---|
| 312 | }; // end namespace decod |
---|
| 313 | }; // end namespace decod_unit |
---|
| 314 | }; // end namespace front_end |
---|
| 315 | }; // end namespace multi_front_end |
---|
| 316 | }; // end namespace core |
---|
| 317 | |
---|
| 318 | }; // end namespace behavioural |
---|
| 319 | }; // end namespace morpheo |
---|
| 320 | #endif |
---|