| 1 | #ifdef SYSTEMC |
|---|
| 2 | /* |
|---|
| 3 | * $Id: Ifetch_queue_transition.cpp 85 2008-05-14 13:09:48Z rosiere $ |
|---|
| 4 | * |
|---|
| 5 | * [ Description ] |
|---|
| 6 | * |
|---|
| 7 | */ |
|---|
| 8 | |
|---|
| 9 | #include "Behavioural/Core/Multi_Front_end/Front_end/Ifetch_unit/Ifetch_queue/include/Ifetch_queue.h" |
|---|
| 10 | |
|---|
| 11 | namespace morpheo { |
|---|
| 12 | namespace behavioural { |
|---|
| 13 | namespace core { |
|---|
| 14 | namespace multi_front_end { |
|---|
| 15 | namespace front_end { |
|---|
| 16 | namespace ifetch_unit { |
|---|
| 17 | namespace ifetch_queue { |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | #undef FUNCTION |
|---|
| 21 | #define FUNCTION "Ifetch_queue::transition" |
|---|
| 22 | void Ifetch_queue::transition (void) |
|---|
| 23 | { |
|---|
| 24 | log_printf(FUNC,Ifetch_queue,FUNCTION,"Begin"); |
|---|
| 25 | |
|---|
| 26 | if (PORT_READ(in_NRESET) == 0) |
|---|
| 27 | { |
|---|
| 28 | reg_PTR_READ = 0; |
|---|
| 29 | reg_PTR_WRITE = 0; |
|---|
| 30 | |
|---|
| 31 | for (uint32_t i=0; i<_param->_size_queue; i++) |
|---|
| 32 | _queue [i]->_state = IFETCH_QUEUE_STATE_EMPTY; |
|---|
| 33 | } |
|---|
| 34 | else |
|---|
| 35 | { |
|---|
| 36 | log_printf(NONE,Ifetch_queue,FUNCTION," * KANE address : 0x%x",PORT_READ(in_ADDRESS_INSTRUCTION_ADDRESS)); |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | // ========================================================== |
|---|
| 40 | // =====[ ADDRESS ]========================================== |
|---|
| 41 | // ========================================================== |
|---|
| 42 | if (PORT_READ(in_ADDRESS_VAL) and internal_ADDRESS_ACK) |
|---|
| 43 | { |
|---|
| 44 | // New slot in ifetch_queue is allocated |
|---|
| 45 | |
|---|
| 46 | _queue[reg_PTR_WRITE]->_state = IFETCH_QUEUE_STATE_WAIT_RSP; |
|---|
| 47 | |
|---|
| 48 | #ifdef STATISTICS |
|---|
| 49 | (*_sum_transaction_address) ++; |
|---|
| 50 | #endif |
|---|
| 51 | |
|---|
| 52 | for (uint32_t i=0; i<_param->_nb_instruction; i++) |
|---|
| 53 | { |
|---|
| 54 | Tcontrol_t enable = PORT_READ(in_ADDRESS_INSTRUCTION_ENABLE [i]); |
|---|
| 55 | #ifdef STATISTICS |
|---|
| 56 | (*_sum_inst_enable) += enable; |
|---|
| 57 | #endif |
|---|
| 58 | _queue[reg_PTR_WRITE]->_instruction_enable [i] = enable; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | _queue[reg_PTR_WRITE]->_address = PORT_READ(in_ADDRESS_INSTRUCTION_ADDRESS ); |
|---|
| 62 | _queue[reg_PTR_WRITE]->_inst_ifetch_ptr = (_param->_have_port_instruction_ptr)?PORT_READ(in_ADDRESS_INST_IFETCH_PTR ):0; |
|---|
| 63 | _queue[reg_PTR_WRITE]->_branch_state = PORT_READ(in_ADDRESS_BRANCH_STATE ); |
|---|
| 64 | _queue[reg_PTR_WRITE]->_branch_update_prediction_id = (_param->_have_port_branch_update_prediction_id)?PORT_READ(in_ADDRESS_BRANCH_UPDATE_PREDICTION_ID):0; |
|---|
| 65 | |
|---|
| 66 | reg_PTR_WRITE = (reg_PTR_WRITE+1)%_param->_size_queue; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | // ========================================================== |
|---|
| 70 | // =====[ DECOD ]============================================ |
|---|
| 71 | // ========================================================== |
|---|
| 72 | bool have_instruction_decod = false; |
|---|
| 73 | bool have_instruction_enable = false; |
|---|
| 74 | for (uint32_t i=0; i<_param->_nb_instruction; i++) |
|---|
| 75 | { |
|---|
| 76 | if (internal_DECOD_VAL [i] and PORT_READ(in_DECOD_ACK[i])) |
|---|
| 77 | { |
|---|
| 78 | have_instruction_decod = true; |
|---|
| 79 | _queue[reg_PTR_READ]->_instruction_enable [i] = false; |
|---|
| 80 | } |
|---|
| 81 | have_instruction_enable |= _queue[reg_PTR_READ]->_instruction_enable [i]; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | // Test if all is decoded |
|---|
| 85 | if (have_instruction_decod and not have_instruction_enable) |
|---|
| 86 | { |
|---|
| 87 | // all is decod |
|---|
| 88 | _queue[reg_PTR_READ]->_state = IFETCH_QUEUE_STATE_EMPTY; |
|---|
| 89 | reg_PTR_READ = (reg_PTR_READ+1)%_param->_size_queue; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | // ========================================================== |
|---|
| 93 | // =====[ ICACHE_RSP ]======================================= |
|---|
| 94 | // ========================================================== |
|---|
| 95 | if (PORT_READ(in_ICACHE_RSP_VAL) and internal_ICACHE_RSP_ACK) |
|---|
| 96 | { |
|---|
| 97 | Tpacket_t ptr = (_param->_have_port_queue_ptr)?PORT_READ(in_ICACHE_RSP_PACKET_ID):0; |
|---|
| 98 | |
|---|
| 99 | for (uint32_t i=0; i<_param->_nb_instruction; i++) |
|---|
| 100 | _queue[ptr]->_instruction [i] = PORT_READ(in_ICACHE_RSP_INSTRUCTION [i]); |
|---|
| 101 | |
|---|
| 102 | switch (PORT_READ(in_ICACHE_RSP_ERROR)) |
|---|
| 103 | { |
|---|
| 104 | case ICACHE_ERROR_NONE : _queue[ptr]->_exception = EXCEPTION_IFETCH_NONE ; break; |
|---|
| 105 | case ICACHE_ERROR_BUS_ERROR : _queue[ptr]->_exception = EXCEPTION_IFETCH_BUS_ERROR; break; |
|---|
| 106 | default : ERRORMORPHEO(FUNCTION,"icache_rsp_error : unknow value."); |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | switch (_queue[ptr]->_state) |
|---|
| 110 | { |
|---|
| 111 | case IFETCH_QUEUE_STATE_WAIT_RSP : _queue[ptr]->_state = IFETCH_QUEUE_STATE_HAVE_RSP; break; |
|---|
| 112 | case IFETCH_QUEUE_STATE_ERROR_WAIT_RSP : _queue[ptr]->_state = IFETCH_QUEUE_STATE_EMPTY ; break; |
|---|
| 113 | default : ERRORMORPHEO(FUNCTION,"icache_rsp : invalid ifetch_queue state."); |
|---|
| 114 | } |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | // ========================================================== |
|---|
| 118 | // =====[ EVENT_RESET ]====================================== |
|---|
| 119 | // ========================================================== |
|---|
| 120 | if (PORT_READ(in_EVENT_RESET_VAL) and internal_EVENT_RESET_ACK) |
|---|
| 121 | { |
|---|
| 122 | // Scan all entry of queue and test the status |
|---|
| 123 | for (uint32_t i=0; i<_param->_size_queue; i++) |
|---|
| 124 | switch (_queue[i]->_state) |
|---|
| 125 | { |
|---|
| 126 | case IFETCH_QUEUE_STATE_ERROR_WAIT_RSP : break; |
|---|
| 127 | case IFETCH_QUEUE_STATE_WAIT_RSP : _queue[i]->_state = IFETCH_QUEUE_STATE_ERROR_WAIT_RSP; break; |
|---|
| 128 | default : _queue[i]->_state = IFETCH_QUEUE_STATE_EMPTY ; break; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | // all entry is empty (or wait respons to flush) |
|---|
| 132 | // reset ptr |
|---|
| 133 | // 1) reg_PTR_READ = reg_PTR_WRITE = = 0 |
|---|
| 134 | // 2) reg_PTR_READ = reg_PTR_WRITE |
|---|
| 135 | // In method 1), the probalitie than the entry pointed by reg_PTR_WRITE is a slot with state "error_wait_rsp" is more importate that the method 2) |
|---|
| 136 | reg_PTR_READ = reg_PTR_WRITE; |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | #if DEBUG >= DEBUG_TRACE |
|---|
| 140 | log_printf(TRACE,Ifetch_queue,FUNCTION,"Dump ifetch_queue"); |
|---|
| 141 | log_printf(TRACE,Ifetch_queue,FUNCTION," * reg_PTR_WRITE : %d",reg_PTR_WRITE); |
|---|
| 142 | log_printf(TRACE,Ifetch_queue,FUNCTION," * reg_PTR_READ : %d",reg_PTR_READ ); |
|---|
| 143 | for (uint32_t i=0; i<_param->_size_queue; i++) |
|---|
| 144 | { |
|---|
| 145 | log_printf(TRACE,Ifetch_queue,FUNCTION," * [%d] %s %.8x %d - %d %d %d", i, toString(_queue [i]->_state).c_str(), _queue [i]->_address,_queue [i]->_inst_ifetch_ptr,_queue [i]->_branch_state,_queue [i]->_branch_update_prediction_id,_queue [i]->_exception); |
|---|
| 146 | |
|---|
| 147 | for (uint32_t j=0; j<_param->_nb_instruction; j++) |
|---|
| 148 | log_printf(TRACE,Ifetch_queue,FUNCTION," * %d %.8x", _queue [i]->_instruction_enable[j], _queue [i]->_instruction[j]); |
|---|
| 149 | } |
|---|
| 150 | #endif |
|---|
| 151 | |
|---|
| 152 | #ifdef STATISTICS |
|---|
| 153 | for (uint32_t i=0; i<_param->_size_queue; i++) |
|---|
| 154 | switch (_queue[i]->_state) |
|---|
| 155 | { |
|---|
| 156 | case IFETCH_QUEUE_STATE_EMPTY : break; |
|---|
| 157 | case IFETCH_QUEUE_STATE_WAIT_RSP : (*_sum_use_queue_wait_rsp ) ++; break; |
|---|
| 158 | case IFETCH_QUEUE_STATE_HAVE_RSP : (*_sum_use_queue_have_rsp ) ++; break; |
|---|
| 159 | case IFETCH_QUEUE_STATE_ERROR_WAIT_RSP : (*_sum_use_queue_error_wait_rsp) ++; break; |
|---|
| 160 | default : break; |
|---|
| 161 | } |
|---|
| 162 | #endif |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | #if defined(STATISTICS) or defined(VHDL_TESTBENCH) |
|---|
| 166 | end_cycle (); |
|---|
| 167 | #endif |
|---|
| 168 | |
|---|
| 169 | log_printf(FUNC,Ifetch_queue,FUNCTION,"End"); |
|---|
| 170 | }; |
|---|
| 171 | |
|---|
| 172 | }; // end namespace ifetch_queue |
|---|
| 173 | }; // end namespace ifetch_unit |
|---|
| 174 | }; // end namespace front_end |
|---|
| 175 | }; // end namespace multi_front_end |
|---|
| 176 | }; // end namespace core |
|---|
| 177 | |
|---|
| 178 | }; // end namespace behavioural |
|---|
| 179 | }; // end namespace morpheo |
|---|
| 180 | #endif |
|---|