1 | #ifdef SYSTEMC |
---|
2 | /* |
---|
3 | * $Id: Commit_unit_transition.cpp 136 2009-10-20 18:52:15Z rosiere $ |
---|
4 | * |
---|
5 | * [ Description ] |
---|
6 | * |
---|
7 | */ |
---|
8 | |
---|
9 | #include "Behavioural/Core/Multi_OOO_Engine/OOO_Engine/Commit_unit/include/Commit_unit.h" |
---|
10 | #include "Behavioural/include/Simulation.h" |
---|
11 | |
---|
12 | namespace morpheo { |
---|
13 | namespace behavioural { |
---|
14 | namespace core { |
---|
15 | namespace multi_ooo_engine { |
---|
16 | namespace ooo_engine { |
---|
17 | namespace commit_unit { |
---|
18 | |
---|
19 | #undef FUNCTION |
---|
20 | #define FUNCTION "Commit_unit::transition" |
---|
21 | void Commit_unit::transition (void) |
---|
22 | { |
---|
23 | log_begin(Commit_unit,FUNCTION); |
---|
24 | log_function(Commit_unit,FUNCTION,_name.c_str()); |
---|
25 | |
---|
26 | if (PORT_READ(in_NRESET) == 0) |
---|
27 | { |
---|
28 | // Clear all bank |
---|
29 | for (uint32_t i=0; i<_param->_nb_bank; ++i) |
---|
30 | { |
---|
31 | while(not _rob[i].empty()) |
---|
32 | { |
---|
33 | delete _rob[i].front(); |
---|
34 | _rob[i].pop_front(); |
---|
35 | } |
---|
36 | reg_BANK_PTR [i] = 0; |
---|
37 | } |
---|
38 | |
---|
39 | // Reset pointer |
---|
40 | reg_NUM_BANK_HEAD = 0; |
---|
41 | reg_NUM_BANK_TAIL = 0; |
---|
42 | reg_NUM_PTR_TAIL = 0; |
---|
43 | |
---|
44 | // Reset counter |
---|
45 | for (uint32_t i=0; i<_param->_nb_front_end; i++) |
---|
46 | for (uint32_t j=0; j<_param->_nb_context [i]; j++) |
---|
47 | { |
---|
48 | _nb_cycle_idle [i][j] = 0; |
---|
49 | |
---|
50 | reg_NB_INST_COMMIT_ALL [i][j] = 0; |
---|
51 | reg_NB_INST_COMMIT_MEM [i][j] = 0; |
---|
52 | |
---|
53 | reg_EVENT_STATE [i][j] = COMMIT_EVENT_STATE_NO_EVENT; |
---|
54 | // reg_EVENT_FLUSH [i][j] = false; |
---|
55 | // reg_EVENT_STOP [i][j] = false; |
---|
56 | reg_EVENT_NUM_BANK [i][j] = 0; // not necessary |
---|
57 | reg_EVENT_NUM_PTR [i][j] = 0; // not necessary |
---|
58 | //reg_EVENT_CAN_RESTART [i][j] = 0; // not necessary |
---|
59 | reg_EVENT_PACKET [i][j] = 0; // not necessary |
---|
60 | reg_EVENT_NB_INST [i][j] = 0; |
---|
61 | reg_EVENT_LAST [i][j] = false; |
---|
62 | reg_EVENT_LAST_NUM_BANK [i][j] = 0; // not necessary |
---|
63 | reg_EVENT_LAST_NUM_PTR [i][j] = 0; // not necessary |
---|
64 | |
---|
65 | reg_EVENT_NEXT_STOP [i][j] = false; |
---|
66 | reg_EVENT_NEXT_PACKET [i][j] = 0; // not necessary |
---|
67 | |
---|
68 | // reg_PC_PREVIOUS [i][j] = (0x100-4)>>2; |
---|
69 | reg_PC_CURRENT [i][j] = (0x100 )>>2; |
---|
70 | reg_PC_CURRENT_IS_DS [i][j] = 0; |
---|
71 | reg_PC_CURRENT_IS_DS_TAKE [i][j] = 0; |
---|
72 | reg_PC_NEXT [i][j] = (0x100+4)>>2; |
---|
73 | } |
---|
74 | |
---|
75 | // Reset priority algorithm |
---|
76 | _priority_insert->reset(); |
---|
77 | } |
---|
78 | else |
---|
79 | { |
---|
80 | // Increase number idle cycle |
---|
81 | for (uint32_t i=0; i<_param->_nb_front_end; i++) |
---|
82 | for (uint32_t j=0; j<_param->_nb_context [i]; j++) |
---|
83 | _nb_cycle_idle [i][j] ++; |
---|
84 | |
---|
85 | // Compute next priority |
---|
86 | _priority_insert->transition(); |
---|
87 | |
---|
88 | // =================================================================== |
---|
89 | // =====[ GARBAGE COLLECTOR ]========================================= |
---|
90 | // =================================================================== |
---|
91 | for (uint32_t i=0; i<_param->_nb_front_end; i++) |
---|
92 | for (uint32_t j=0; j<_param->_nb_context [i]; j++) |
---|
93 | { |
---|
94 | // Test if can_restart : (can_restart is to signal at the state than the decod_queue is empty) |
---|
95 | // * no previous can_restart (trap for one) |
---|
96 | // * and decod_queue is empty |
---|
97 | // * and have an event or have a futur event |
---|
98 | // if (not reg_EVENT_CAN_RESTART [i][j] and |
---|
99 | // (PORT_READ(in_NB_INST_DECOD_ALL [i][j]) == 0) and |
---|
100 | // (reg_EVENT_STOP [i][j] or (reg_EVENT_STATE [i][j] != COMMIT_EVENT_STATE_NO_EVENT))) |
---|
101 | // reg_EVENT_CAN_RESTART [i][j] = true; |
---|
102 | |
---|
103 | // Test event state |
---|
104 | switch (reg_EVENT_STATE [i][j]) |
---|
105 | { |
---|
106 | case COMMIT_EVENT_STATE_EVENT : |
---|
107 | { |
---|
108 | // Have an event, test if all composant have ack |
---|
109 | if (internal_RETIRE_EVENT_VAL [i][j] and in_RETIRE_EVENT_ACK [i][j]) |
---|
110 | { |
---|
111 | // A minor optimisation : test if wait_decod is previously empty. |
---|
112 | // if (not reg_EVENT_CAN_RESTART [i][j]) |
---|
113 | // reg_EVENT_STATE [i][j] = COMMIT_EVENT_STATE_WAIT_DECOD; |
---|
114 | // else |
---|
115 | reg_EVENT_STATE [i][j] = COMMIT_EVENT_STATE_WAIT_END; |
---|
116 | } |
---|
117 | |
---|
118 | break; |
---|
119 | } |
---|
120 | // case COMMIT_EVENT_STATE_WAIT_DECOD : |
---|
121 | // { |
---|
122 | // // Wait flush of decod_queue. |
---|
123 | // // Test if can restart now |
---|
124 | // if (reg_EVENT_CAN_RESTART [i][j]) |
---|
125 | // { |
---|
126 | // //reg_EVENT_FLUSH [i][j] = false; |
---|
127 | |
---|
128 | // // A minor optimisation : test if the last element is already retire |
---|
129 | // if (not reg_EVENT_LAST [i][j]) |
---|
130 | // reg_EVENT_STATE [i][j] = COMMIT_EVENT_STATE_WAIT_END; |
---|
131 | // else |
---|
132 | // reg_EVENT_STATE [i][j] = COMMIT_EVENT_STATE_END; |
---|
133 | // } |
---|
134 | // break; |
---|
135 | // } |
---|
136 | |
---|
137 | // case COMMIT_EVENT_STATE_WAIT_END : |
---|
138 | // { |
---|
139 | // // Wait the flush of Re Order Buffer. |
---|
140 | // // Test if the last element is retire |
---|
141 | // if (reg_EVENT_LAST [i][j]) |
---|
142 | // reg_EVENT_STATE [i][j] = COMMIT_EVENT_STATE_END ; |
---|
143 | |
---|
144 | // break; |
---|
145 | // } |
---|
146 | // case COMMIT_EVENT_STATE_END : |
---|
147 | // { |
---|
148 | // // Just one cycle |
---|
149 | |
---|
150 | // // flush of re order buffer is finish |
---|
151 | // reg_EVENT_LAST [i][j] = false; |
---|
152 | |
---|
153 | // if (not reg_EVENT_NEXT_STOP [i][j]) |
---|
154 | // reg_EVENT_STATE [i][j] = COMMIT_EVENT_STATE_NO_EVENT; |
---|
155 | // else |
---|
156 | // { |
---|
157 | // reg_EVENT_NEXT_STOP [i][j] = false; |
---|
158 | // reg_EVENT_PACKET [i][j] = reg_EVENT_NEXT_PACKET [i][j]; |
---|
159 | // reg_EVENT_STATE [i][j] = COMMIT_EVENT_STATE_NOT_YET_EVENT; |
---|
160 | // // reg_EVENT_STOP [i][j] = true; |
---|
161 | // reg_EVENT_LAST_NUM_BANK [i][j] = ((reg_NUM_BANK_TAIL==0)?_param->_nb_bank:reg_NUM_BANK_TAIL)-1; |
---|
162 | // reg_EVENT_LAST_NUM_PTR [i][j] = reg_NUM_PTR_TAIL; |
---|
163 | // } |
---|
164 | |
---|
165 | // break; |
---|
166 | // } |
---|
167 | |
---|
168 | |
---|
169 | case COMMIT_EVENT_STATE_WAIT_END : |
---|
170 | { |
---|
171 | // Wait the flush of Re Order Buffer. |
---|
172 | // Test if the last element is retire |
---|
173 | if (reg_EVENT_LAST [i][j]) |
---|
174 | { |
---|
175 | // flush of re order buffer is finish |
---|
176 | reg_EVENT_LAST [i][j] = false; |
---|
177 | |
---|
178 | if (not reg_EVENT_NEXT_STOP [i][j]) |
---|
179 | reg_EVENT_STATE [i][j] = COMMIT_EVENT_STATE_NO_EVENT; |
---|
180 | else |
---|
181 | { |
---|
182 | reg_EVENT_STATE [i][j] = COMMIT_EVENT_STATE_NOT_YET_EVENT; |
---|
183 | |
---|
184 | reg_EVENT_NEXT_STOP [i][j] = false; |
---|
185 | reg_EVENT_PACKET [i][j] = reg_EVENT_NEXT_PACKET [i][j]; |
---|
186 | reg_EVENT_NB_INST [i][j] = reg_NB_INST_COMMIT_ALL [i][j]; |
---|
187 | //reg_EVENT_STOP [i][j] = true; |
---|
188 | reg_EVENT_LAST_NUM_BANK [i][j] = ((reg_NUM_BANK_TAIL==0)?_param->_nb_bank:reg_NUM_BANK_TAIL)-1; |
---|
189 | reg_EVENT_LAST_NUM_PTR [i][j] = reg_NUM_PTR_TAIL; |
---|
190 | } |
---|
191 | } |
---|
192 | break; |
---|
193 | } |
---|
194 | |
---|
195 | //case COMMIT_EVENT_STATE_NO_EVENT : |
---|
196 | //case COMMIT_EVENT_STATE_NOT_YET_EVENT : |
---|
197 | default : break; |
---|
198 | } |
---|
199 | } |
---|
200 | |
---|
201 | // =================================================================== |
---|
202 | // =====[ INSERT ]==================================================== |
---|
203 | // =================================================================== |
---|
204 | { |
---|
205 | // for (uint32_t i=0; i<_param->_nb_rename_unit; i++) |
---|
206 | // for (uint32_t j=0; j<_param->_nb_inst_insert[i]; j++) |
---|
207 | // log_printf(TRACE,Commit_unit,FUNCTION," * INSERT_VAL [%d][%d] : %d",i,j,PORT_READ(in_INSERT_VAL [i][j])); |
---|
208 | |
---|
209 | // variable to count instruction insert |
---|
210 | uint32_t nb_insert = 0; |
---|
211 | |
---|
212 | for (uint32_t i=0; i<_param->_nb_bank; i++) |
---|
213 | { |
---|
214 | // compute first bank number |
---|
215 | uint32_t num_bank = (reg_NUM_BANK_TAIL+i)%_param->_nb_bank; |
---|
216 | |
---|
217 | if (internal_BANK_INSERT_VAL [num_bank]) |
---|
218 | { |
---|
219 | // get rename unit source and instruction. |
---|
220 | uint32_t x = internal_BANK_INSERT_NUM_RENAME_UNIT [num_bank]; |
---|
221 | uint32_t y = internal_BANK_INSERT_NUM_INST [num_bank]; |
---|
222 | |
---|
223 | // Test if an instruction is valid |
---|
224 | // (all in_order insert combinatory is in rename_unit ) |
---|
225 | if (PORT_READ(in_INSERT_VAL [x][y])) |
---|
226 | { |
---|
227 | log_printf(TRACE,Commit_unit,FUNCTION," * INSERT [%d][%d]",x,y); |
---|
228 | |
---|
229 | // get information |
---|
230 | Tcontext_t front_end_id = (_param->_have_port_front_end_id)?PORT_READ(in_INSERT_FRONT_END_ID [x][y]):0; |
---|
231 | Tcontext_t context_id = (_param->_have_port_context_id )?PORT_READ(in_INSERT_CONTEXT_ID [x][y]):0; |
---|
232 | Ttype_t type = PORT_READ(in_INSERT_TYPE [x][y]); |
---|
233 | Toperation_t operation = PORT_READ(in_INSERT_OPERATION [x][y]); |
---|
234 | bool is_store = is_operation_memory_store(operation); |
---|
235 | |
---|
236 | Texception_t exception = PORT_READ(in_INSERT_EXCEPTION [x][y]); |
---|
237 | Tcontrol_t no_execute = PORT_READ(in_INSERT_NO_EXECUTE [x][y]); |
---|
238 | |
---|
239 | log_printf(TRACE,Commit_unit,FUNCTION," * front_end_id : %d",front_end_id); |
---|
240 | log_printf(TRACE,Commit_unit,FUNCTION," * context_id : %d",context_id); |
---|
241 | log_printf(TRACE,Commit_unit,FUNCTION," * type : %s",toString(type).c_str()); |
---|
242 | log_printf(TRACE,Commit_unit,FUNCTION," * operation : %d",operation ); |
---|
243 | log_printf(TRACE,Commit_unit,FUNCTION," * exception : %d",exception ); |
---|
244 | |
---|
245 | // Create new entry and write information |
---|
246 | entry_t * entry = new entry_t; |
---|
247 | uint32_t ptr = reg_BANK_PTR [num_bank]; |
---|
248 | |
---|
249 | entry->ptr = ptr; |
---|
250 | entry->front_end_id = front_end_id; |
---|
251 | entry->context_id = context_id ; |
---|
252 | entry->rename_unit_id = x; |
---|
253 | entry->depth = (_param->_have_port_depth)?PORT_READ(in_INSERT_DEPTH [x][y]):0; |
---|
254 | entry->type = type; |
---|
255 | entry->operation = operation; |
---|
256 | entry->is_delay_slot = PORT_READ(in_INSERT_IS_DELAY_SLOT [x][y]); |
---|
257 | // entry->address = PORT_READ(in_INSERT_ADDRESS [x][y]); |
---|
258 | entry->exception = exception; |
---|
259 | entry->exception_use = PORT_READ(in_INSERT_EXCEPTION_USE [x][y]); |
---|
260 | entry->use_store_queue = (type == TYPE_MEMORY) and ( is_store) and (not no_execute); |
---|
261 | entry->use_load_queue = (type == TYPE_MEMORY) and (not is_store) and (not no_execute); |
---|
262 | entry->store_queue_ptr_write = PORT_READ(in_INSERT_STORE_QUEUE_PTR_WRITE [x][y]); |
---|
263 | entry->load_queue_ptr_write = (_param->_have_port_load_queue_ptr)?PORT_READ(in_INSERT_LOAD_QUEUE_PTR_WRITE [x][y]):0; |
---|
264 | #ifdef DEBUG |
---|
265 | entry->read_ra = PORT_READ(in_INSERT_READ_RA [x][y]); |
---|
266 | entry->num_reg_ra_log = PORT_READ(in_INSERT_NUM_REG_RA_LOG [x][y]); |
---|
267 | entry->num_reg_ra_phy = PORT_READ(in_INSERT_NUM_REG_RA_PHY [x][y]); |
---|
268 | entry->read_rb = PORT_READ(in_INSERT_READ_RB [x][y]); |
---|
269 | entry->num_reg_rb_log = PORT_READ(in_INSERT_NUM_REG_RB_LOG [x][y]); |
---|
270 | entry->num_reg_rb_phy = PORT_READ(in_INSERT_NUM_REG_RB_PHY [x][y]); |
---|
271 | entry->read_rc = PORT_READ(in_INSERT_READ_RC [x][y]); |
---|
272 | entry->num_reg_rc_log = PORT_READ(in_INSERT_NUM_REG_RC_LOG [x][y]); |
---|
273 | entry->num_reg_rc_phy = PORT_READ(in_INSERT_NUM_REG_RC_PHY [x][y]); |
---|
274 | #endif |
---|
275 | entry->write_rd = PORT_READ(in_INSERT_WRITE_RD [x][y]); |
---|
276 | entry->num_reg_rd_log = PORT_READ(in_INSERT_NUM_REG_RD_LOG [x][y]); |
---|
277 | entry->num_reg_rd_phy_old = PORT_READ(in_INSERT_NUM_REG_RD_PHY_OLD [x][y]); |
---|
278 | entry->num_reg_rd_phy_new = PORT_READ(in_INSERT_NUM_REG_RD_PHY_NEW [x][y]); |
---|
279 | entry->write_re = PORT_READ(in_INSERT_WRITE_RE [x][y]); |
---|
280 | entry->num_reg_re_log = PORT_READ(in_INSERT_NUM_REG_RE_LOG [x][y]); |
---|
281 | entry->num_reg_re_phy_old = PORT_READ(in_INSERT_NUM_REG_RE_PHY_OLD [x][y]); |
---|
282 | entry->num_reg_re_phy_new = PORT_READ(in_INSERT_NUM_REG_RE_PHY_NEW [x][y]); |
---|
283 | |
---|
284 | entry->flags = 0; // not necessary |
---|
285 | entry->no_sequence = type == TYPE_BRANCH; |
---|
286 | // entry->speculative = true; |
---|
287 | #ifdef DEBUG |
---|
288 | entry->address = PORT_READ(in_INSERT_ADDRESS [x][y]); |
---|
289 | #else |
---|
290 | entry->address = 0; // not necessary |
---|
291 | #endif |
---|
292 | entry->address_next = PORT_READ(in_INSERT_ADDRESS_NEXT [x][y]); |
---|
293 | #ifdef DEBUG |
---|
294 | entry->cycle_rob_in = simulation_cycle(); |
---|
295 | entry->cycle_commit = simulation_cycle(); |
---|
296 | #endif |
---|
297 | |
---|
298 | // Test if exception : |
---|
299 | // * yes : no execute instruction, wait ROB Head |
---|
300 | // * no : test if no_execute (== instruction is flushed) |
---|
301 | // else test type |
---|
302 | // * BRANCH : l.j -> branch is ended |
---|
303 | // other -> wait the execution end of branchment |
---|
304 | // * MEMORY : store -> wait store is at head of ROB |
---|
305 | // other -> wait end of instruction |
---|
306 | // * OTHER |
---|
307 | |
---|
308 | { |
---|
309 | if (exception == EXCEPTION_NONE) |
---|
310 | { |
---|
311 | // no_execute : l.j, l.nop, l.rfe |
---|
312 | |
---|
313 | log_printf(TRACE,Commit_unit,FUNCTION," * no_execute : %d",no_execute); |
---|
314 | |
---|
315 | switch (type) |
---|
316 | { |
---|
317 | case TYPE_BRANCH : {entry->state=(no_execute==1)?ROB_BRANCH_COMPLETE:ROB_BRANCH_WAIT_END ; break;} |
---|
318 | case TYPE_MEMORY : {entry->state=(no_execute==1)?ROB_END_OK_SPECULATIVE:(entry->state=(is_store ==1)?ROB_STORE_WAIT_END_OK:ROB_OTHER_WAIT_END); break;} |
---|
319 | default : {entry->state=(no_execute==1)?ROB_END_OK_SPECULATIVE:ROB_OTHER_WAIT_END; break;} |
---|
320 | } |
---|
321 | } |
---|
322 | else |
---|
323 | { |
---|
324 | // Have an exception : wait head of ROB |
---|
325 | // in_INSERT_NO_EXECUTE [x][y] : l.sys, l.trap |
---|
326 | |
---|
327 | entry->state = ROB_END_EXCEPTION_WAIT_HEAD; |
---|
328 | } |
---|
329 | } |
---|
330 | |
---|
331 | #ifdef STATISTICS |
---|
332 | if (usage_is_set(_usage,USE_STATISTICS)) |
---|
333 | (*_stat_nb_inst_insert [x]) ++; |
---|
334 | #endif |
---|
335 | |
---|
336 | // Push entry in rob |
---|
337 | _rob[num_bank].push_back(entry); |
---|
338 | |
---|
339 | // Update counter and pointer |
---|
340 | reg_NB_INST_COMMIT_ALL [front_end_id][context_id] ++; |
---|
341 | if (type == TYPE_MEMORY) |
---|
342 | reg_NB_INST_COMMIT_MEM [front_end_id][context_id] ++; |
---|
343 | |
---|
344 | |
---|
345 | // flush = present event or future event. |
---|
346 | // * present event = don't can restart |
---|
347 | |
---|
348 | // bool flush = reg_EVENT_FLUSH [front_end_id][context_id]; |
---|
349 | |
---|
350 | // bool flush = (((reg_EVENT_STATE [front_end_id][context_id] == COMMIT_EVENT_STATE_EVENT) or |
---|
351 | // (reg_EVENT_STATE [front_end_id][context_id] == COMMIT_EVENT_STATE_WAIT_DECOD)) or |
---|
352 | // (reg_EVENT_STOP [front_end_id][context_id])); |
---|
353 | |
---|
354 | // New instruction from decod_queue. Flush if : |
---|
355 | // * future event (instruction don't need execute because they are a previous event (miss load/branch or exception)) |
---|
356 | // * or present_event |
---|
357 | // * and not can_restart (previous empty decod queue), because between the event_stop (branch_complete) and the state event (miss in head), many cycle is occured. |
---|
358 | // bool flush = ((// present event |
---|
359 | // ((reg_EVENT_STATE [front_end_id][context_id] == COMMIT_EVENT_STATE_EVENT) or |
---|
360 | // (reg_EVENT_STATE [front_end_id][context_id] == COMMIT_EVENT_STATE_WAIT_DECOD) |
---|
361 | // ) or |
---|
362 | // futur event |
---|
363 | // reg_EVENT_STOP [front_end_id][context_id]) |
---|
364 | // // can't restart |
---|
365 | // and not reg_EVENT_CAN_RESTART[front_end_id][context_id] |
---|
366 | // ); |
---|
367 | |
---|
368 | // if (flush) |
---|
369 | // { |
---|
370 | // // A new invalid instruction is push in rob -> new last instruction |
---|
371 | // reg_EVENT_LAST [front_end_id][context_id] = false; |
---|
372 | // reg_EVENT_LAST_NUM_BANK [front_end_id][context_id] = num_bank; |
---|
373 | // reg_EVENT_LAST_NUM_PTR [front_end_id][context_id] = ptr; |
---|
374 | // } |
---|
375 | |
---|
376 | // Update pointer |
---|
377 | reg_NUM_PTR_TAIL = ptr; |
---|
378 | reg_BANK_PTR [num_bank] = (reg_BANK_PTR [num_bank]+1)%_param->_size_bank; |
---|
379 | nb_insert ++; |
---|
380 | } |
---|
381 | } |
---|
382 | } |
---|
383 | // Update pointer |
---|
384 | reg_NUM_BANK_TAIL = (reg_NUM_BANK_TAIL+nb_insert)%_param->_nb_bank; |
---|
385 | } |
---|
386 | |
---|
387 | // =================================================================== |
---|
388 | // =====[ COMMIT ]==================================================== |
---|
389 | // =================================================================== |
---|
390 | |
---|
391 | #ifdef STATISTICS |
---|
392 | if (usage_is_set(_usage,USE_STATISTICS)) |
---|
393 | (*_stat_nb_inst_commit_conflit_access) += internal_BANK_COMMIT_CONFLIT_ACCESS; |
---|
394 | #endif |
---|
395 | |
---|
396 | // For each commit instruction ... |
---|
397 | for (uint32_t i=0; i<_param->_nb_bank; i++) |
---|
398 | for (uint32_t j=0; j<_param->_nb_bank_access_commit; j++) |
---|
399 | // ... test if an instruction have finish this execution |
---|
400 | if (internal_BANK_COMMIT_VAL [i][j]) |
---|
401 | { |
---|
402 | // An instruction is executed -> Change state of this instruction |
---|
403 | |
---|
404 | // Get information |
---|
405 | uint32_t x = internal_BANK_COMMIT_NUM_INST [i][j]; |
---|
406 | |
---|
407 | // Test if instruction is valid and is enable |
---|
408 | // (can be disable if this instruction is reexecute) |
---|
409 | if (PORT_READ(in_COMMIT_VAL [x]) and PORT_READ(in_COMMIT_WEN [x])) |
---|
410 | { |
---|
411 | log_printf(TRACE,Commit_unit,FUNCTION," * COMMIT [%d]",x); |
---|
412 | |
---|
413 | #ifdef STATISTICS |
---|
414 | if (usage_is_set(_usage,USE_STATISTICS)) |
---|
415 | (*_stat_nb_inst_commit) ++; |
---|
416 | #endif |
---|
417 | |
---|
418 | log_printf(TRACE,Commit_unit,FUNCTION," * num_bank : %d",i); |
---|
419 | |
---|
420 | // find the good entry !!! |
---|
421 | entry_t * entry = internal_BANK_COMMIT_ENTRY [i][j]; |
---|
422 | |
---|
423 | log_printf(TRACE,Commit_unit,FUNCTION," * ptr : %d",entry->ptr); |
---|
424 | |
---|
425 | //Toperation_t operation = PORT_READ(in_COMMIT_OPERATION [x]); |
---|
426 | Ttype_t type = entry->type; |
---|
427 | Tcontrol_t no_sequence = PORT_READ(in_COMMIT_NO_SEQUENCE [x]); |
---|
428 | // Tcontrol_t cancel = PORT_READ(in_COMMIT_CANCEL [x]); |
---|
429 | |
---|
430 | #if 0 |
---|
431 | if ((type == TYPE_MEMORY) and no_sequence) |
---|
432 | continue; |
---|
433 | #endif |
---|
434 | |
---|
435 | Texception_t exception = PORT_READ(in_COMMIT_EXCEPTION [x]); |
---|
436 | |
---|
437 | rob_state_t state = entry->state; |
---|
438 | Tcontext_t front_end_id = entry->front_end_id; |
---|
439 | Tcontext_t context_id = entry->context_id; |
---|
440 | |
---|
441 | // change state : test exception_use |
---|
442 | |
---|
443 | bool have_exception = false; |
---|
444 | bool have_miss_speculation = false; |
---|
445 | |
---|
446 | // Test if have an exception ... |
---|
447 | if (exception != EXCEPTION_NONE) |
---|
448 | { |
---|
449 | // Test if the instruction is a load and is a miss speculation |
---|
450 | // (load is commit, but they have an dependence with a previous store -> need restart pipeline) |
---|
451 | |
---|
452 | have_miss_speculation = (exception == EXCEPTION_MEMORY_MISS_SPECULATION); |
---|
453 | |
---|
454 | // * Test if the exception generated can be trap by this exception |
---|
455 | switch (entry->exception_use) |
---|
456 | { |
---|
457 | // Have overflow exception if bit overflow enable is set. |
---|
458 | case EXCEPTION_USE_RANGE : {have_exception = ((exception == EXCEPTION_RANGE) and PORT_READ(in_SPR_READ_SR_OVE[front_end_id][context_id])); break;} |
---|
459 | case EXCEPTION_USE_MEMORY_WITH_ALIGNMENT : {have_exception = ((exception == EXCEPTION_BUS_ERROR) or |
---|
460 | (exception == EXCEPTION_DATA_TLB ) or |
---|
461 | (exception == EXCEPTION_DATA_PAGE) or |
---|
462 | (exception == EXCEPTION_ALIGNMENT)); break;}; |
---|
463 | case EXCEPTION_USE_MEMORY_WITHOUT_ALIGNMENT : {have_exception = ((exception == EXCEPTION_BUS_ERROR) or |
---|
464 | (exception == EXCEPTION_DATA_TLB ) or |
---|
465 | (exception == EXCEPTION_DATA_PAGE)); break;}; |
---|
466 | case EXCEPTION_USE_CUSTOM_0 : {have_exception = (exception == EXCEPTION_CUSTOM_0); break;}; |
---|
467 | case EXCEPTION_USE_CUSTOM_1 : {have_exception = (exception == EXCEPTION_CUSTOM_1); break;}; |
---|
468 | case EXCEPTION_USE_CUSTOM_2 : {have_exception = (exception == EXCEPTION_CUSTOM_2); break;}; |
---|
469 | case EXCEPTION_USE_CUSTOM_3 : {have_exception = (exception == EXCEPTION_CUSTOM_3); break;}; |
---|
470 | case EXCEPTION_USE_CUSTOM_4 : {have_exception = (exception == EXCEPTION_CUSTOM_4); break;}; |
---|
471 | case EXCEPTION_USE_CUSTOM_5 : {have_exception = (exception == EXCEPTION_CUSTOM_5); break;}; |
---|
472 | case EXCEPTION_USE_CUSTOM_6 : {have_exception = (exception == EXCEPTION_CUSTOM_6); break;}; |
---|
473 | // Case already manage (decod stage -> in insert in ROB) |
---|
474 | case EXCEPTION_USE_TRAP : {have_exception = false; exception = EXCEPTION_NONE; break;}; |
---|
475 | case EXCEPTION_USE_NONE : {have_exception = false; exception = EXCEPTION_NONE; break;}; |
---|
476 | case EXCEPTION_USE_ILLEGAL_INSTRUCTION : {have_exception = false; exception = EXCEPTION_NONE; break;}; |
---|
477 | case EXCEPTION_USE_SYSCALL : {have_exception = false; exception = EXCEPTION_NONE; break;}; |
---|
478 | default : |
---|
479 | { |
---|
480 | throw ERRORMORPHEO(FUNCTION,_("Commit : invalid exception_use.\n")); |
---|
481 | break; |
---|
482 | } |
---|
483 | } |
---|
484 | } |
---|
485 | |
---|
486 | log_printf(TRACE,Commit_unit,FUNCTION," * have_exception : %d",have_exception ); |
---|
487 | log_printf(TRACE,Commit_unit,FUNCTION," * have_miss_speculation : %d",have_miss_speculation); |
---|
488 | |
---|
489 | |
---|
490 | // Next state depends of previous state |
---|
491 | switch (state) |
---|
492 | { |
---|
493 | // Branch : if no exception, the branchement can be completed |
---|
494 | case ROB_BRANCH_WAIT_END : |
---|
495 | { |
---|
496 | if (not have_exception) |
---|
497 | state = ROB_BRANCH_COMPLETE; |
---|
498 | else |
---|
499 | state = ROB_END_EXCEPTION_WAIT_HEAD; |
---|
500 | break; |
---|
501 | } |
---|
502 | // Previous event -> set state as execute |
---|
503 | case ROB_STORE_KO_WAIT_END : |
---|
504 | case ROB_EVENT_WAIT_END : |
---|
505 | { |
---|
506 | state = ROB_END_KO_SPECULATIVE; |
---|
507 | break; |
---|
508 | } |
---|
509 | // No previous event - Load and other instruction |
---|
510 | case ROB_STORE_OK_WAIT_END : |
---|
511 | case ROB_OTHER_WAIT_END : |
---|
512 | { |
---|
513 | if (not have_exception) |
---|
514 | { |
---|
515 | if (not have_miss_speculation) |
---|
516 | state = ROB_END_OK_SPECULATIVE; |
---|
517 | else |
---|
518 | state = ROB_END_LOAD_MISS_SPECULATIVE; |
---|
519 | } |
---|
520 | else |
---|
521 | state = ROB_END_EXCEPTION_WAIT_HEAD; |
---|
522 | break; |
---|
523 | } |
---|
524 | case ROB_STORE_WAIT_END_OK : |
---|
525 | { |
---|
526 | if (not have_exception) |
---|
527 | state = ROB_STORE_OK; |
---|
528 | else |
---|
529 | state = ROB_STORE_EVENT; |
---|
530 | break; |
---|
531 | } |
---|
532 | case ROB_STORE_WAIT_END_KO : |
---|
533 | { |
---|
534 | // if (not have_exception) |
---|
535 | state = ROB_STORE_KO; |
---|
536 | // else |
---|
537 | // state = ROB_END_EXCEPTION_WAIT_HEAD; |
---|
538 | break; |
---|
539 | } |
---|
540 | |
---|
541 | |
---|
542 | default : |
---|
543 | { |
---|
544 | throw ERRORMORPHEO(FUNCTION,toString(_("Commit [%d] : Bank [%d][%d], invalid state value (%s).\n"),x,i,j,toString(state).c_str())); |
---|
545 | break; |
---|
546 | } |
---|
547 | } |
---|
548 | |
---|
549 | // Commit an instruction ... |
---|
550 | // Test if have an event (miss_speculation or exception) |
---|
551 | |
---|
552 | if (have_exception or have_miss_speculation) |
---|
553 | { |
---|
554 | // Two case : |
---|
555 | // if no previous manage event -> generate an event |
---|
556 | // if previous manage event -> next generate an event |
---|
557 | |
---|
558 | // bool flush = reg_EVENT_FLUSH [front_end_id][context_id]; |
---|
559 | bool flush = ((reg_EVENT_STATE [front_end_id][context_id] == COMMIT_EVENT_STATE_EVENT) or |
---|
560 | // (reg_EVENT_STATE [front_end_id][context_id] == COMMIT_EVENT_STATE_WAIT_DECOD) or |
---|
561 | (reg_EVENT_STATE [front_end_id][context_id] == COMMIT_EVENT_STATE_WAIT_END)// or |
---|
562 | // (reg_EVENT_STATE [front_end_id][context_id] == COMMIT_EVENT_STATE_END) |
---|
563 | ); |
---|
564 | |
---|
565 | uint32_t packet = ((entry->ptr << _param->_shift_num_slot) | i); |
---|
566 | uint32_t _top = ((_rob[ reg_NUM_BANK_HEAD].front()->ptr << _param->_shift_num_slot) | reg_NUM_BANK_HEAD); |
---|
567 | |
---|
568 | log_printf(TRACE,Commit_unit,FUNCTION," * flush : %d",flush); |
---|
569 | log_printf(TRACE,Commit_unit,FUNCTION," * packet : %d",packet); |
---|
570 | |
---|
571 | if (not flush) |
---|
572 | { |
---|
573 | bool can = true; |
---|
574 | // test have a previous event detected (event_stop = 1) |
---|
575 | // if yes, test if the actual event if "before (in order)" that the previous event |
---|
576 | if (reg_EVENT_STATE [front_end_id][context_id] == COMMIT_EVENT_STATE_NOT_YET_EVENT) |
---|
577 | { |
---|
578 | // Compare packet_id (by construction instruction is insert in order by increase packet_id) |
---|
579 | |
---|
580 | uint32_t _old = reg_EVENT_PACKET [front_end_id][context_id]; |
---|
581 | uint32_t _new = packet; |
---|
582 | if (_old < _top) _old = _old+_param->_size_queue; |
---|
583 | if (_new < _top) _new = _new+_param->_size_queue; |
---|
584 | if (_new < _old) reg_EVENT_PACKET [front_end_id][context_id] = packet; |
---|
585 | else can = false; |
---|
586 | } |
---|
587 | else |
---|
588 | reg_EVENT_PACKET [front_end_id][context_id] = packet; |
---|
589 | |
---|
590 | if (can) |
---|
591 | { |
---|
592 | // have an error, stop issue instruction |
---|
593 | reg_EVENT_STATE [front_end_id][context_id] = COMMIT_EVENT_STATE_NOT_YET_EVENT; |
---|
594 | |
---|
595 | reg_EVENT_NB_INST [front_end_id][context_id] = reg_NB_INST_COMMIT_ALL [front_end_id][context_id]; |
---|
596 | |
---|
597 | //reg_EVENT_STOP [front_end_id][context_id] = true; |
---|
598 | |
---|
599 | reg_EVENT_LAST_NUM_BANK [front_end_id][context_id] = ((reg_NUM_BANK_TAIL==0)?_param->_nb_bank:reg_NUM_BANK_TAIL)-1; |
---|
600 | reg_EVENT_LAST_NUM_PTR [front_end_id][context_id] = reg_NUM_PTR_TAIL; |
---|
601 | } |
---|
602 | } |
---|
603 | else |
---|
604 | { |
---|
605 | bool find = true; |
---|
606 | |
---|
607 | log_printf(TRACE,Commit_unit,FUNCTION," * reg_EVENT_NEXT_STOP : %d",reg_EVENT_NEXT_STOP [front_end_id][context_id]); |
---|
608 | log_printf(TRACE,Commit_unit,FUNCTION," * reg_EVENT_NEXT_PACKET : %d",reg_EVENT_NEXT_PACKET[front_end_id][context_id]); |
---|
609 | |
---|
610 | // already manage an event. |
---|
611 | if (reg_EVENT_NEXT_STOP [front_end_id][context_id]) |
---|
612 | { |
---|
613 | // after last ? |
---|
614 | uint32_t _old = reg_EVENT_NEXT_PACKET [front_end_id][context_id]; |
---|
615 | uint32_t _new = packet; |
---|
616 | |
---|
617 | log_printf(TRACE,Commit_unit,FUNCTION," * _top : %d",_top ); |
---|
618 | log_printf(TRACE,Commit_unit,FUNCTION," * _old (before) : %d",_old ); |
---|
619 | log_printf(TRACE,Commit_unit,FUNCTION," * _new (before) : %d",_new ); |
---|
620 | |
---|
621 | if (_old < _top) _old = _old+_param->_size_queue; |
---|
622 | if (_new < _top) _new = _new+_param->_size_queue; |
---|
623 | if (_new > _old) reg_EVENT_NEXT_PACKET [front_end_id][context_id] = packet; |
---|
624 | else find = false; |
---|
625 | |
---|
626 | log_printf(TRACE,Commit_unit,FUNCTION," * _old (after) : %d",_old ); |
---|
627 | log_printf(TRACE,Commit_unit,FUNCTION," * _new (after) : %d",_new ); |
---|
628 | } |
---|
629 | else |
---|
630 | { |
---|
631 | // after last ? |
---|
632 | uint32_t _old = ((reg_EVENT_LAST_NUM_PTR [front_end_id][context_id] << _param->_shift_num_slot) | reg_EVENT_LAST_NUM_BANK [front_end_id][context_id]); |
---|
633 | uint32_t _new = packet; |
---|
634 | |
---|
635 | log_printf(TRACE,Commit_unit,FUNCTION," * _top : %d",_top ); |
---|
636 | log_printf(TRACE,Commit_unit,FUNCTION," * _old (before) : %d",_old ); |
---|
637 | log_printf(TRACE,Commit_unit,FUNCTION," * _new (before) : %d",_new ); |
---|
638 | |
---|
639 | if (_old < _top) _old = _old+_param->_size_queue; |
---|
640 | if (_new < _top) _new = _new+_param->_size_queue; |
---|
641 | if (_new > _old) reg_EVENT_NEXT_PACKET [front_end_id][context_id] = packet; |
---|
642 | else find = false; |
---|
643 | |
---|
644 | log_printf(TRACE,Commit_unit,FUNCTION," * _old (after) : %d",_old ); |
---|
645 | log_printf(TRACE,Commit_unit,FUNCTION," * _new (after) : %d",_new ); |
---|
646 | } |
---|
647 | |
---|
648 | log_printf(TRACE,Commit_unit,FUNCTION," * find : %d",find); |
---|
649 | |
---|
650 | if (find) |
---|
651 | reg_EVENT_NEXT_STOP [front_end_id][context_id] = true; // in all case : need stop |
---|
652 | } |
---|
653 | } |
---|
654 | |
---|
655 | // Update Re Order Buffer |
---|
656 | entry->state = state; |
---|
657 | entry->exception = exception; |
---|
658 | entry->flags = PORT_READ(in_COMMIT_FLAGS [x]); |
---|
659 | entry->no_sequence = no_sequence; |
---|
660 | // jalr, jr : address_dest is in register |
---|
661 | if (( type == TYPE_BRANCH) and |
---|
662 | (entry->operation == OPERATION_BRANCH_L_JALR) and |
---|
663 | (entry->read_rb)) |
---|
664 | entry->address_next = PORT_READ(in_COMMIT_ADDRESS [x]); |
---|
665 | |
---|
666 | #ifdef DEBUG |
---|
667 | entry->load_data = PORT_READ(in_COMMIT_ADDRESS [x]); |
---|
668 | entry->cycle_commit = simulation_cycle(); |
---|
669 | #endif |
---|
670 | } |
---|
671 | } |
---|
672 | |
---|
673 | // =================================================================== |
---|
674 | // =====[ RETIRE ]==================================================== |
---|
675 | // =================================================================== |
---|
676 | for (uint32_t i=0; i<_param->_nb_bank; i++) |
---|
677 | { |
---|
678 | // Compute bank number |
---|
679 | uint32_t num_bank = (internal_BANK_RETIRE_HEAD+i)%_param->_nb_bank; |
---|
680 | |
---|
681 | // Test if have an request |
---|
682 | if (internal_BANK_RETIRE_VAL [num_bank]) |
---|
683 | { |
---|
684 | // Take num instruction |
---|
685 | uint32_t x = internal_BANK_RETIRE_NUM_RENAME_UNIT [num_bank]; |
---|
686 | uint32_t y = internal_BANK_RETIRE_NUM_INST [num_bank]; |
---|
687 | |
---|
688 | log_printf(TRACE,Commit_unit,FUNCTION," * RETIRE [%d][%d]",x,y); |
---|
689 | log_printf(TRACE,Commit_unit,FUNCTION," * num_bank : %d",num_bank ); |
---|
690 | |
---|
691 | #ifdef DEBUG_TEST |
---|
692 | if (not PORT_READ(in_RETIRE_ACK [x][y])) |
---|
693 | throw ERRORMORPHEO(FUNCTION,_("Retire : retire_ack must be set.\n")); |
---|
694 | #endif |
---|
695 | |
---|
696 | |
---|
697 | #ifdef STATISTICS |
---|
698 | if (usage_is_set(_usage,USE_STATISTICS)) |
---|
699 | (*_stat_nb_inst_retire [x]) ++; |
---|
700 | |
---|
701 | #endif |
---|
702 | |
---|
703 | // Read information |
---|
704 | entry_t * entry = _rob [num_bank].front(); |
---|
705 | |
---|
706 | entry->state_old = entry->state; |
---|
707 | entry->state = ROB_END; |
---|
708 | } |
---|
709 | } |
---|
710 | |
---|
711 | for (uint32_t i=0; i<_param->_nb_bank; i++) |
---|
712 | { |
---|
713 | // Compute bank number |
---|
714 | bool can_continue = false; |
---|
715 | uint32_t num_bank = reg_NUM_BANK_HEAD; |
---|
716 | |
---|
717 | if (not _rob [num_bank].empty ()) |
---|
718 | { |
---|
719 | entry_t * entry = _rob [num_bank].front(); |
---|
720 | |
---|
721 | if (entry->state == ROB_END) |
---|
722 | { |
---|
723 | log_printf(TRACE,Commit_unit,FUNCTION," * RETIRE_ROB [%d]",num_bank); |
---|
724 | |
---|
725 | can_continue = true; |
---|
726 | |
---|
727 | Tcontext_t front_end_id = entry->front_end_id; |
---|
728 | Tcontext_t context_id = entry->context_id ; |
---|
729 | uint32_t num_thread = _param->_translate_num_context_to_num_thread [front_end_id][context_id]; |
---|
730 | rob_state_t state = entry->state_old; |
---|
731 | Ttype_t type = entry->type ; |
---|
732 | bool retire_ok = false; |
---|
733 | uint32_t packet_id = ((entry->ptr << _param->_shift_num_slot) | num_bank); |
---|
734 | |
---|
735 | log_printf(TRACE,Commit_unit,FUNCTION," * front_end_id : %d",front_end_id ); |
---|
736 | log_printf(TRACE,Commit_unit,FUNCTION," * context_id : %d",context_id ); |
---|
737 | log_printf(TRACE,Commit_unit,FUNCTION," * rob_ptr : %d",packet_id ); |
---|
738 | log_printf(TRACE,Commit_unit,FUNCTION," * num_thread : %d",num_thread ); |
---|
739 | log_printf(TRACE,Commit_unit,FUNCTION," * type : %s",toString(type).c_str()); |
---|
740 | log_printf(TRACE,Commit_unit,FUNCTION," * state : %s",toString(state).c_str()); |
---|
741 | |
---|
742 | // Test if the instruction is valid |
---|
743 | // (BRANCH_MISS = instruction branch is valid, but have make an invalid prediction) |
---|
744 | // (LOAD_MISS = instruction load is valid, but have make an invalid result) |
---|
745 | if ((state == ROB_END_OK ) or |
---|
746 | // (state == ROB_END_KO ) or |
---|
747 | (state == ROB_END_BRANCH_MISS) or |
---|
748 | (state == ROB_END_LOAD_MISS )// or |
---|
749 | // (state == ROB_END_MISS ) or |
---|
750 | // (state == ROB_END_EXCEPTION ) |
---|
751 | ) |
---|
752 | { |
---|
753 | log_printf(TRACE,Commit_unit,FUNCTION," * retire_ok"); |
---|
754 | |
---|
755 | retire_ok = true; |
---|
756 | |
---|
757 | // Update PC information |
---|
758 | // reg_PC_PREVIOUS [front_end_id][context_id] = reg_PC_CURRENT [front_end_id][context_id]; |
---|
759 | reg_PC_CURRENT [front_end_id][context_id] = reg_PC_NEXT [front_end_id][context_id]; |
---|
760 | reg_PC_CURRENT_IS_DS [front_end_id][context_id] = type == TYPE_BRANCH; |
---|
761 | reg_PC_CURRENT_IS_DS_TAKE [front_end_id][context_id] = entry->no_sequence; |
---|
762 | reg_PC_NEXT [front_end_id][context_id] = (entry->no_sequence)?(entry->address_next):(reg_PC_CURRENT [front_end_id][context_id]+1); |
---|
763 | } |
---|
764 | |
---|
765 | // Test if have an event |
---|
766 | if ((state == ROB_END_BRANCH_MISS) or |
---|
767 | (state == ROB_END_LOAD_MISS)) |
---|
768 | { |
---|
769 | reg_EVENT_STATE [front_end_id][context_id] = COMMIT_EVENT_STATE_EVENT; |
---|
770 | // reg_EVENT_STOP [front_end_id][context_id] = false; // instruction flow can continue |
---|
771 | reg_EVENT_LAST [front_end_id][context_id] = false; |
---|
772 | // it the head ! |
---|
773 | reg_EVENT_PACKET [front_end_id][context_id] = packet_id; |
---|
774 | |
---|
775 | // // If event is an load_miss, many instruction can be inserted. |
---|
776 | // // -> new last instruction |
---|
777 | // if (state == ROB_END_LOAD_MISS) |
---|
778 | // { |
---|
779 | // // reg_EVENT_CAN_RESTART [front_end_id][context_id] = false; |
---|
780 | |
---|
781 | // reg_EVENT_LAST_NUM_BANK [front_end_id][context_id] = ((reg_NUM_BANK_TAIL==0)?_param->_nb_bank:reg_NUM_BANK_TAIL)-1; |
---|
782 | // reg_EVENT_LAST_NUM_PTR [front_end_id][context_id] = reg_NUM_PTR_TAIL; |
---|
783 | // } |
---|
784 | } |
---|
785 | |
---|
786 | // Test if this instruction is the last instruction of an event |
---|
787 | // * need event |
---|
788 | // * packet id = last packet id |
---|
789 | // for (uint32_t x=0; x<_param->_nb_front_end; x++) |
---|
790 | // for (uint32_t y=0; y<_param->_nb_context [x]; y++) |
---|
791 | // if (((reg_EVENT_STATE [x][y] != COMMIT_EVENT_STATE_NO_EVENT ) and |
---|
792 | // (reg_EVENT_STATE [x][y] != COMMIT_EVENT_STATE_NOT_YET_EVENT)) and |
---|
793 | // (reg_EVENT_LAST_NUM_BANK [x][y] == num_bank ) and |
---|
794 | // (reg_EVENT_LAST_NUM_PTR [x][y] == entry->ptr )) |
---|
795 | // reg_EVENT_LAST [x][y] = true; |
---|
796 | |
---|
797 | |
---|
798 | if (reg_EVENT_NB_INST [front_end_id][context_id] > 0) |
---|
799 | { |
---|
800 | reg_EVENT_NB_INST [front_end_id][context_id] --; |
---|
801 | if (reg_EVENT_NB_INST [front_end_id][context_id] == 0) |
---|
802 | reg_EVENT_LAST [front_end_id][context_id] = true; |
---|
803 | } |
---|
804 | |
---|
805 | // Update nb_inst |
---|
806 | reg_NB_INST_COMMIT_ALL [front_end_id][context_id] --; |
---|
807 | if (type == TYPE_MEMORY) |
---|
808 | reg_NB_INST_COMMIT_MEM [front_end_id][context_id] --; |
---|
809 | |
---|
810 | // Update pointer |
---|
811 | reg_NUM_BANK_HEAD = (num_bank+1)%_param->_nb_bank; |
---|
812 | |
---|
813 | // Reset watch dog timer because have transaction on retire interface |
---|
814 | _nb_cycle_idle [front_end_id][context_id] = 0; |
---|
815 | |
---|
816 | // Increase stop condition |
---|
817 | if (retire_ok) |
---|
818 | _simulation_nb_instruction_commited [num_thread] ++; |
---|
819 | |
---|
820 | #ifdef STATISTICS |
---|
821 | if (usage_is_set(_usage,USE_STATISTICS)) |
---|
822 | { |
---|
823 | if (retire_ok) |
---|
824 | { |
---|
825 | (*_stat_nb_inst_retire_ok [num_thread]) ++; |
---|
826 | (*_stat_nb_inst_type [type] ) ++; |
---|
827 | } |
---|
828 | else |
---|
829 | (*_stat_nb_inst_retire_ko [num_thread]) ++; |
---|
830 | } |
---|
831 | #endif |
---|
832 | |
---|
833 | #if defined(DEBUG) and defined(DEBUG_Commit_unit) and (DEBUG_Commit_unit == true) |
---|
834 | if (log_file_generate) |
---|
835 | { |
---|
836 | // log file |
---|
837 | instruction_log_file [num_thread] |
---|
838 | << "[" << simulation_cycle() << "] " |
---|
839 | << std::hex |
---|
840 | << (entry->address<<2) << " (" << (entry->address) << ") " |
---|
841 | << std::dec |
---|
842 | << "[" << entry->cycle_rob_in << ", " << entry->cycle_commit << "] " |
---|
843 | << "{" << ((retire_ok)?"OK":"KO") << "} "; |
---|
844 | |
---|
845 | if ((type == TYPE_MEMORY) and is_operation_memory_load(entry->operation)) |
---|
846 | instruction_log_file [num_thread] << std::hex << entry->load_data << std::dec; |
---|
847 | |
---|
848 | instruction_log_file [num_thread] << std::endl; |
---|
849 | } |
---|
850 | #endif |
---|
851 | |
---|
852 | // Remove entry |
---|
853 | delete entry; |
---|
854 | _rob [num_bank].pop_front(); |
---|
855 | } |
---|
856 | } |
---|
857 | |
---|
858 | if (not can_continue) |
---|
859 | break; // stop scan |
---|
860 | } |
---|
861 | |
---|
862 | // =================================================================== |
---|
863 | // =====[ REEXECUTE ]================================================= |
---|
864 | // =================================================================== |
---|
865 | // Test if have an reexecute instruction (an store in head of rob) |
---|
866 | for (uint32_t i=0; i<_param->_nb_inst_reexecute; ++i) |
---|
867 | if (internal_REEXECUTE_VAL [i] and PORT_READ(in_REEXECUTE_ACK [i])) |
---|
868 | { |
---|
869 | log_printf(TRACE,Commit_unit,FUNCTION," * REEXECUTE [%d]",i); |
---|
870 | |
---|
871 | uint32_t num_bank = internal_REEXECUTE_NUM_BANK [i]; |
---|
872 | |
---|
873 | entry_t * entry = _rob [num_bank].front(); |
---|
874 | rob_state_t state = entry->state; |
---|
875 | |
---|
876 | // Change state |
---|
877 | switch (state) |
---|
878 | { |
---|
879 | case ROB_STORE_OK : {state = ROB_STORE_OK_WAIT_END; break; } |
---|
880 | case ROB_STORE_KO : {state = ROB_STORE_KO_WAIT_END; break; } |
---|
881 | case ROB_STORE_EVENT : {state = ROB_EVENT_WAIT_END; break; } |
---|
882 | default : {throw ERRORMORPHEO(FUNCTION,_("Reexecute : invalid state value.\n"));} |
---|
883 | } |
---|
884 | |
---|
885 | entry->state = state; |
---|
886 | } |
---|
887 | |
---|
888 | // =================================================================== |
---|
889 | // =====[ BRANCH_COMPLETE ]=========================================== |
---|
890 | // =================================================================== |
---|
891 | for (uint32_t i=0; i<_param->_nb_inst_branch_complete; i++) |
---|
892 | // Test if the prediction_unit have accept the branch complete transaction |
---|
893 | if (internal_BRANCH_COMPLETE_VAL [i] and PORT_READ(in_BRANCH_COMPLETE_ACK [i])) |
---|
894 | { |
---|
895 | log_printf(TRACE,Commit_unit,FUNCTION," * BRANCH_COMPLETE [%d]",i); |
---|
896 | |
---|
897 | // Read information |
---|
898 | uint32_t num_bank = internal_BRANCH_COMPLETE_NUM_BANK [i]; |
---|
899 | |
---|
900 | entry_t * entry = _rob [num_bank].front(); |
---|
901 | |
---|
902 | #ifdef DEBUG_TEST |
---|
903 | rob_state_t state = entry->state; |
---|
904 | if (state != ROB_BRANCH_COMPLETE) |
---|
905 | throw ERRORMORPHEO(FUNCTION,_("Branch_complete : Invalid state value.\n")); |
---|
906 | #endif |
---|
907 | Tcontrol_t miss = PORT_READ(in_BRANCH_COMPLETE_MISS_PREDICTION [i]); |
---|
908 | |
---|
909 | log_printf(TRACE,Commit_unit,FUNCTION," * miss_prediction : %d",miss); |
---|
910 | |
---|
911 | entry->state = (miss)?ROB_END_BRANCH_MISS_SPECULATIVE:ROB_END_OK_SPECULATIVE; |
---|
912 | |
---|
913 | // bool flush = reg_EVENT_FLUSH [entry->front_end_id][entry->context_id]; |
---|
914 | |
---|
915 | // Branch_complete can be execute if |
---|
916 | // * no present event |
---|
917 | // * futur event and most not speculative that the event |
---|
918 | |
---|
919 | // Also, test if in this cycle, they have not an most recently event !!! |
---|
920 | if (miss) |
---|
921 | { |
---|
922 | bool can = true; |
---|
923 | uint32_t packet = ((entry->ptr << _param->_shift_num_slot) | num_bank); |
---|
924 | |
---|
925 | // test if this packet is before previous event |
---|
926 | if (reg_EVENT_STATE [entry->front_end_id][entry->context_id] == COMMIT_EVENT_STATE_NOT_YET_EVENT) |
---|
927 | { |
---|
928 | uint32_t _top = ((_rob[ reg_NUM_BANK_HEAD].front()->ptr << _param->_shift_num_slot) | reg_NUM_BANK_HEAD); |
---|
929 | uint32_t _old = reg_EVENT_PACKET [entry->front_end_id][entry->context_id]; |
---|
930 | uint32_t _new = packet; |
---|
931 | if (_old < _top) _old = _old+_param->_size_queue; |
---|
932 | if (_new < _top) _new = _new+_param->_size_queue; |
---|
933 | if (_new < _old) reg_EVENT_PACKET [entry->front_end_id][entry->context_id] = packet; |
---|
934 | else can = false; |
---|
935 | } |
---|
936 | else |
---|
937 | reg_EVENT_PACKET [entry->front_end_id][entry->context_id] = packet; |
---|
938 | |
---|
939 | if (can) |
---|
940 | { |
---|
941 | // In all case, stop instruction flow |
---|
942 | reg_EVENT_STATE [entry->front_end_id][entry->context_id] = COMMIT_EVENT_STATE_NOT_YET_EVENT; |
---|
943 | reg_EVENT_NB_INST [entry->front_end_id][entry->context_id] = reg_NB_INST_COMMIT_ALL [entry->front_end_id][entry->context_id]; |
---|
944 | |
---|
945 | // reg_EVENT_STOP [entry->front_end_id][entry->context_id] = true; |
---|
946 | |
---|
947 | // reg_EVENT_CAN_RESTART [entry->front_end_id][entry->context_id] = false; |
---|
948 | |
---|
949 | reg_EVENT_LAST_NUM_BANK [entry->front_end_id][entry->context_id] = ((reg_NUM_BANK_TAIL==0)?_param->_nb_bank:reg_NUM_BANK_TAIL)-1; |
---|
950 | reg_EVENT_LAST_NUM_PTR [entry->front_end_id][entry->context_id] = reg_NUM_PTR_TAIL; |
---|
951 | } |
---|
952 | } |
---|
953 | } |
---|
954 | |
---|
955 | // =================================================================== |
---|
956 | // =====[ UPDATE ]==================================================== |
---|
957 | // =================================================================== |
---|
958 | // Update when exception or load_miss |
---|
959 | if (internal_UPDATE_VAL and PORT_READ(in_UPDATE_ACK)) |
---|
960 | { |
---|
961 | log_printf(TRACE,Commit_unit,FUNCTION," * UPDATE"); |
---|
962 | |
---|
963 | // Change state |
---|
964 | entry_t * entry = _rob [internal_UPDATE_NUM_BANK].front(); |
---|
965 | |
---|
966 | switch (entry->state) |
---|
967 | { |
---|
968 | // case ROB_END_EXCEPTION_UPDATE : |
---|
969 | // { |
---|
970 | // entry->state = ROB_END_KO; |
---|
971 | // throw ERRORMORPHEO(FUNCTION,_("Moore : exception is not yet supported (Coming Soon).\n")); |
---|
972 | // break; |
---|
973 | // } |
---|
974 | case ROB_END_LOAD_MISS_UPDATE : |
---|
975 | { |
---|
976 | log_printf(TRACE,Commit_unit,FUNCTION," * ROB_END_LOAD_MISS_UPDATE"); |
---|
977 | |
---|
978 | entry->state = ROB_END_LOAD_MISS; |
---|
979 | break; |
---|
980 | } |
---|
981 | default : |
---|
982 | { |
---|
983 | throw ERRORMORPHEO(FUNCTION,_("Update : invalid state.\n")); |
---|
984 | break; |
---|
985 | } |
---|
986 | } |
---|
987 | } |
---|
988 | |
---|
989 | // =================================================================== |
---|
990 | // =====[ EVENT ]===================================================== |
---|
991 | // =================================================================== |
---|
992 | // for (uint32_t i=0; i < _param->_nb_front_end; ++i) |
---|
993 | // for (uint32_t j=0; j < _param->_nb_context[i]; ++j) |
---|
994 | // if (PORT_READ(in_EVENT_VAL [i][j]) and internal_EVENT_ACK [i][j]) |
---|
995 | // { |
---|
996 | // log_printf(TRACE,Commit_unit,FUNCTION," * EVENT [%d][%d]",i,j); |
---|
997 | |
---|
998 | // reg_PC_CURRENT [i][j] = PORT_READ(in_EVENT_ADDRESS [i][j]); |
---|
999 | // reg_PC_CURRENT_IS_DS [i][j] = PORT_READ(in_EVENT_IS_DS_TAKE [i][j]); // ?? |
---|
1000 | // reg_PC_CURRENT_IS_DS_TAKE [i][j] = PORT_READ(in_EVENT_IS_DS_TAKE [i][j]); |
---|
1001 | // reg_PC_NEXT [i][j] = PORT_READ(in_EVENT_ADDRESS_NEXT [i][j]); |
---|
1002 | // // PORT_READ(in_EVENT_ADDRESS_NEXT_VAL [i][j]); |
---|
1003 | // } |
---|
1004 | |
---|
1005 | // =================================================================== |
---|
1006 | // =====[ DEPTH - HEAD ]============================================== |
---|
1007 | // =================================================================== |
---|
1008 | |
---|
1009 | { |
---|
1010 | bool can_continue [_param->_nb_front_end][_param->_max_nb_context]; |
---|
1011 | uint32_t event_nb_inst [_param->_nb_front_end][_param->_max_nb_context]; |
---|
1012 | bool is_speculative [_param->_nb_front_end][_param->_max_nb_context]; |
---|
1013 | for (uint32_t i=0; i<_param->_nb_front_end; i++) |
---|
1014 | for (uint32_t j=0; j<_param->_nb_context [i]; j++) |
---|
1015 | { |
---|
1016 | event_nb_inst [i][j] = 0; |
---|
1017 | is_speculative[i][j] = false; |
---|
1018 | can_continue [i][j] = (((reg_EVENT_NB_INST [i][j] == 0) or |
---|
1019 | ( event_nb_inst [i][j] < reg_EVENT_NB_INST [i][j])) and |
---|
1020 | not reg_EVENT_LAST [i][j]); |
---|
1021 | } |
---|
1022 | |
---|
1023 | // Read all instruction of all top bank |
---|
1024 | for (uint32_t i=0; i<_param->_nb_bank; i++) |
---|
1025 | { |
---|
1026 | uint32_t num_bank = (reg_NUM_BANK_HEAD+i)%_param->_nb_bank; |
---|
1027 | |
---|
1028 | // Test if have an instruction |
---|
1029 | if (not _rob[num_bank].empty()) |
---|
1030 | { |
---|
1031 | // Scan all instruction in windows and test if instruction is speculative |
---|
1032 | entry_t * entry = _rob [num_bank].front(); |
---|
1033 | |
---|
1034 | uint32_t num_packet = ((entry->ptr << _param->_shift_num_slot) | num_bank); |
---|
1035 | Tcontext_t front_end_id = entry->front_end_id; |
---|
1036 | Tcontext_t context_id = entry->context_id ; |
---|
1037 | |
---|
1038 | log_printf(TRACE,Commit_unit,FUNCTION," * HEAD [%d] - %d",num_bank,num_packet); |
---|
1039 | log_printf(TRACE,Commit_unit,FUNCTION," * front_end_id : %d",front_end_id); |
---|
1040 | log_printf(TRACE,Commit_unit,FUNCTION," * context_id : %d",context_id); |
---|
1041 | log_printf(TRACE,Commit_unit,FUNCTION," * EVENT_LAST : %d",reg_EVENT_LAST [front_end_id][context_id]); |
---|
1042 | log_printf(TRACE,Commit_unit,FUNCTION," * EVENT_NB_INST : %d",reg_EVENT_NB_INST [front_end_id][context_id]); |
---|
1043 | log_printf(TRACE,Commit_unit,FUNCTION," * event_nb_inst : %d", event_nb_inst [front_end_id][context_id]); |
---|
1044 | |
---|
1045 | // scan while last event instruction is not retire |
---|
1046 | if (can_continue [front_end_id][context_id]) |
---|
1047 | { |
---|
1048 | // Read information |
---|
1049 | rob_state_t state = entry->state; |
---|
1050 | Tdepth_t depth = entry->depth; |
---|
1051 | |
---|
1052 | Tdepth_t depth_min = (_param->_have_port_depth)?PORT_READ(in_DEPTH_MIN[front_end_id][context_id]):0; |
---|
1053 | Tdepth_t depth_max = (_param->_have_port_depth)?PORT_READ(in_DEPTH_MAX[front_end_id][context_id]):0; |
---|
1054 | Tcontrol_t depth_full = PORT_READ(in_DEPTH_FULL [front_end_id][context_id]); |
---|
1055 | |
---|
1056 | // is a valid instruction ? |
---|
1057 | // If DEPTH_CURRENT : |
---|
1058 | // equal at DEPTH_MIN -> not speculative |
---|
1059 | // not include ]DEPTH_MIN:DEPTH_MAX] -> previous branch miss |
---|
1060 | // include ]DEPTH_MIN:DEPTH_MAX] -> speculative |
---|
1061 | |
---|
1062 | // All case |
---|
1063 | // ....... min ...X... max ....... OK |
---|
1064 | // ....... min ....... max ...X... KO |
---|
1065 | // ...X... min ....... max ....... KO |
---|
1066 | // ....... max ....... min ...X... OK |
---|
1067 | // ...X... max ....... min ....... OK |
---|
1068 | // ....... max ...X... min ....... KO |
---|
1069 | |
---|
1070 | bool flush = ((reg_EVENT_STATE [front_end_id][context_id] == COMMIT_EVENT_STATE_EVENT) or |
---|
1071 | // (reg_EVENT_STATE [front_end_id][context_id] == COMMIT_EVENT_STATE_WAIT_DECOD) or |
---|
1072 | (reg_EVENT_STATE [front_end_id][context_id] == COMMIT_EVENT_STATE_WAIT_END)); |
---|
1073 | bool speculative = is_speculative [front_end_id][context_id]; |
---|
1074 | |
---|
1075 | // bool speculative = entry->speculative and not (depth == depth_min); |
---|
1076 | // Tcontrol_t is_valid = ((not speculative or |
---|
1077 | // (speculative and (depth_full or // all is valid |
---|
1078 | // ((depth_min <= depth_max)? // test if depth is overflow |
---|
1079 | // ((depth >= depth_min) and (depth <=depth_max)): |
---|
1080 | // ((depth >= depth_min) or (depth <=depth_max)))))) |
---|
1081 | // and not flush); // no event |
---|
1082 | |
---|
1083 | Tcontrol_t is_valid = not flush; |
---|
1084 | |
---|
1085 | |
---|
1086 | //Tcontrol_t is_valid = ((depth == depth_min) and not flush); |
---|
1087 | |
---|
1088 | |
---|
1089 | log_printf(TRACE,Commit_unit,FUNCTION," * is_valid : %d ((depth == depth_min) and not flush)",is_valid); |
---|
1090 | log_printf(TRACE,Commit_unit,FUNCTION," * depth : %d",depth ); |
---|
1091 | log_printf(TRACE,Commit_unit,FUNCTION," * depth_min : %d",depth_min); |
---|
1092 | log_printf(TRACE,Commit_unit,FUNCTION," * depth_max : %d",depth_max); |
---|
1093 | log_printf(TRACE,Commit_unit,FUNCTION," * depth_full : %d",depth_full); |
---|
1094 | log_printf(TRACE,Commit_unit,FUNCTION," * speculative : %d",speculative); |
---|
1095 | log_printf(TRACE,Commit_unit,FUNCTION," * flush : %d",flush); |
---|
1096 | log_printf(TRACE,Commit_unit,FUNCTION," * state (before) : %s",toString(state).c_str()); |
---|
1097 | |
---|
1098 | // //------------------------------------------------------ |
---|
1099 | // // Event ? |
---|
1100 | // //------------------------------------------------------ |
---|
1101 | |
---|
1102 | // if ((reg_EVENT_STATE [front_end_id][context_id] == COMMIT_EVENT_STATE_NOT_YET_EVENT) and |
---|
1103 | // (reg_EVENT_PACKET [front_end_id][context_id] == num_packet)) |
---|
1104 | // { |
---|
1105 | // switch (state) |
---|
1106 | // { |
---|
1107 | // case ROB_END_BRANCH_MISS_SPECULATIVE : {state = ROB_END_BRANCH_MISS ; break;} |
---|
1108 | // case ROB_END_LOAD_MISS_SPECULATIVE : {state = ROB_END_LOAD_MISS_UPDATE ; break;} |
---|
1109 | // case ROB_END_BRANCH_MISS : |
---|
1110 | // case ROB_END_LOAD_MISS : |
---|
1111 | // case ROB_END : |
---|
1112 | // {break;} |
---|
1113 | // default : |
---|
1114 | // { |
---|
1115 | // throw ERRORMORPHEO(FUNCTION,toString(_("Head [%d] : invalid state (%s)"),num_packet,toString(state).c_str())); |
---|
1116 | // break; |
---|
1117 | // } |
---|
1118 | // } |
---|
1119 | // } |
---|
1120 | |
---|
1121 | //------------------------------------------------------ |
---|
1122 | // test if instruction is miss speculative |
---|
1123 | //------------------------------------------------------ |
---|
1124 | if (not is_valid) |
---|
1125 | { |
---|
1126 | // Change state |
---|
1127 | switch (state) |
---|
1128 | { |
---|
1129 | case ROB_BRANCH_WAIT_END : {state = ROB_EVENT_WAIT_END; break;} |
---|
1130 | case ROB_BRANCH_COMPLETE : {state = ROB_END_MISS ; break;} |
---|
1131 | case ROB_END_BRANCH_MISS : |
---|
1132 | case ROB_END_BRANCH_MISS_SPECULATIVE : {state = ROB_END_MISS ; break;} |
---|
1133 | case ROB_END_LOAD_MISS : |
---|
1134 | case ROB_END_LOAD_MISS_UPDATE : |
---|
1135 | case ROB_END_LOAD_MISS_SPECULATIVE : {state = ROB_END_MISS ; break;} |
---|
1136 | case ROB_STORE_OK : {state = ROB_STORE_KO ; break;} |
---|
1137 | case ROB_STORE_WAIT_END_OK : {state = ROB_STORE_WAIT_END_KO; break;} |
---|
1138 | case ROB_STORE_OK_WAIT_END : {state = ROB_STORE_KO_WAIT_END; break;} |
---|
1139 | case ROB_OTHER_WAIT_END : {state = ROB_EVENT_WAIT_END; break;} |
---|
1140 | case ROB_END_OK : |
---|
1141 | case ROB_END_OK_SPECULATIVE : {state = ROB_END_MISS ; break;} |
---|
1142 | case ROB_END_KO : |
---|
1143 | case ROB_END_KO_SPECULATIVE : {state = ROB_END_MISS ; break;} |
---|
1144 | case ROB_END_EXCEPTION_UPDATE : |
---|
1145 | case ROB_END_EXCEPTION : |
---|
1146 | case ROB_END_EXCEPTION_WAIT_HEAD : {state = ROB_END_MISS ; break;} |
---|
1147 | |
---|
1148 | // don't change state -> wait |
---|
1149 | case ROB_STORE_WAIT_END_KO : {break;} |
---|
1150 | case ROB_STORE_KO : {break;} |
---|
1151 | case ROB_STORE_KO_WAIT_END : {break;} |
---|
1152 | case ROB_STORE_EVENT : {break;} |
---|
1153 | case ROB_EVENT_WAIT_END : {break;} |
---|
1154 | case ROB_END_MISS : {break;} |
---|
1155 | case ROB_END : {break;} |
---|
1156 | |
---|
1157 | // can't have miss speculation -> invalid state |
---|
1158 | default : |
---|
1159 | { |
---|
1160 | throw ERRORMORPHEO(FUNCTION,toString(_("Miss Speculation : Invalide state : %s.\n"),toString(state).c_str())); |
---|
1161 | break; |
---|
1162 | } |
---|
1163 | } |
---|
1164 | } |
---|
1165 | |
---|
1166 | //------------------------------------------------------ |
---|
1167 | // test if instruction is branch not finish |
---|
1168 | //------------------------------------------------------ |
---|
1169 | switch (state) |
---|
1170 | { |
---|
1171 | case ROB_BRANCH_WAIT_END : |
---|
1172 | case ROB_BRANCH_COMPLETE : |
---|
1173 | { |
---|
1174 | is_speculative [front_end_id][context_id] = true; |
---|
1175 | break; |
---|
1176 | } |
---|
1177 | default : break; |
---|
1178 | } |
---|
1179 | |
---|
1180 | //------------------------------------------------------ |
---|
1181 | // test if instruction is not speculative |
---|
1182 | //------------------------------------------------------ |
---|
1183 | // entry->speculative = speculative; |
---|
1184 | // if (entry->depth == depth_min) |
---|
1185 | // test if instruction is speculative (depth != depth_min) |
---|
1186 | if (not speculative) |
---|
1187 | { |
---|
1188 | switch (state) |
---|
1189 | { |
---|
1190 | case ROB_END_OK_SPECULATIVE : {state = ROB_END_OK ; break;} |
---|
1191 | case ROB_END_KO_SPECULATIVE : {state = ROB_END_KO ; break;} |
---|
1192 | case ROB_END_BRANCH_MISS_SPECULATIVE : {state = ROB_END_BRANCH_MISS ; break;} |
---|
1193 | case ROB_END_LOAD_MISS_SPECULATIVE : {state = ROB_END_LOAD_MISS_UPDATE ; break;} |
---|
1194 | default : {break;} // else, no change |
---|
1195 | } |
---|
1196 | } |
---|
1197 | |
---|
1198 | //------------------------------------------------------ |
---|
1199 | // test if instruction wait head and is the top of rob |
---|
1200 | //------------------------------------------------------ |
---|
1201 | // TODO : retire OOO |
---|
1202 | if (i == 0) |
---|
1203 | { |
---|
1204 | switch (state) |
---|
1205 | { |
---|
1206 | // case ROB_STORE_WAIT_HEAD_OK : {state = ROB_STORE_HEAD_OK; break;} |
---|
1207 | case ROB_END_EXCEPTION_WAIT_HEAD : {state = ROB_END_EXCEPTION_UPDATE; break;} |
---|
1208 | default : {break;} // else, no change |
---|
1209 | } |
---|
1210 | } |
---|
1211 | |
---|
1212 | // Write new state |
---|
1213 | entry->state = state; |
---|
1214 | |
---|
1215 | log_printf(TRACE,Commit_unit,FUNCTION," * state (after ) : %s",toString(state).c_str()); |
---|
1216 | |
---|
1217 | // log_printf(TRACE,Commit_unit,FUNCTION," * Stop Scan !!!"); |
---|
1218 | |
---|
1219 | event_nb_inst [front_end_id][context_id] ++; |
---|
1220 | |
---|
1221 | // stop if : |
---|
1222 | // * begin event |
---|
1223 | // * end event |
---|
1224 | if (((reg_EVENT_STATE [front_end_id][context_id] == COMMIT_EVENT_STATE_NOT_YET_EVENT) and |
---|
1225 | (reg_EVENT_PACKET[front_end_id][context_id] == num_packet)) or |
---|
1226 | ((reg_EVENT_NB_INST [front_end_id][context_id] > 0) and |
---|
1227 | ( event_nb_inst [front_end_id][context_id] >= reg_EVENT_NB_INST [front_end_id][context_id]))) |
---|
1228 | can_continue [front_end_id][context_id] = false; |
---|
1229 | } |
---|
1230 | } |
---|
1231 | } |
---|
1232 | } |
---|
1233 | |
---|
1234 | |
---|
1235 | |
---|
1236 | #ifdef STATISTICS |
---|
1237 | if (usage_is_set(_usage,USE_STATISTICS)) |
---|
1238 | { |
---|
1239 | for (uint32_t i=0; i<_param->_nb_bank; i++) |
---|
1240 | *(_stat_bank_nb_inst [i]) += _rob[i].size(); |
---|
1241 | |
---|
1242 | for (uint32_t i=0; i<_param->_nb_front_end; i++) |
---|
1243 | for (uint32_t j=0; j<_param->_nb_context [i]; j++) |
---|
1244 | { |
---|
1245 | uint32_t num_thread = _param->_translate_num_context_to_num_thread [i][j]; |
---|
1246 | |
---|
1247 | switch (reg_EVENT_STATE [i][j]) |
---|
1248 | { |
---|
1249 | case COMMIT_EVENT_STATE_NO_EVENT : (*_stat_nb_cycle_state_no_event [num_thread])++; break; |
---|
1250 | case COMMIT_EVENT_STATE_NOT_YET_EVENT : (*_stat_nb_cycle_state_not_yet_event [num_thread])++; break; |
---|
1251 | case COMMIT_EVENT_STATE_EVENT : (*_stat_nb_cycle_state_event [num_thread])++; break; |
---|
1252 | case COMMIT_EVENT_STATE_WAIT_END : (*_stat_nb_cycle_state_wait_end [num_thread])++; break; |
---|
1253 | } |
---|
1254 | } |
---|
1255 | } |
---|
1256 | #endif |
---|
1257 | } |
---|
1258 | |
---|
1259 | // =================================================================== |
---|
1260 | // =====[ OTHER ]===================================================== |
---|
1261 | // =================================================================== |
---|
1262 | |
---|
1263 | #if (DEBUG >= DEBUG_TRACE) and (DEBUG_Commit_unit == true) |
---|
1264 | { |
---|
1265 | log_printf(TRACE,Commit_unit,FUNCTION," * Dump ROB (Re-Order-Buffer)"); |
---|
1266 | log_printf(TRACE,Commit_unit,FUNCTION," * num_bank_head : %d",reg_NUM_BANK_HEAD); |
---|
1267 | log_printf(TRACE,Commit_unit,FUNCTION," * num_bank_tail : %d",reg_NUM_BANK_TAIL); |
---|
1268 | log_printf(TRACE,Commit_unit,FUNCTION," * num_ptr_tail : %d",reg_NUM_PTR_TAIL ); |
---|
1269 | |
---|
1270 | for (uint32_t i=0; i<_param->_nb_front_end; i++) |
---|
1271 | for (uint32_t j=0; j<_param->_nb_context [i]; j++) |
---|
1272 | { |
---|
1273 | log_printf(TRACE,Commit_unit,FUNCTION," * [%d][%d] - %d",i,j,_param->_translate_num_context_to_num_thread [i][j]); |
---|
1274 | log_printf(TRACE,Commit_unit,FUNCTION," * EVENT_STATE : %s - %s",toString(reg_EVENT_STATE [i][j]).c_str(),toString(commit_event_state_to_event_state(reg_EVENT_STATE [i][j])).c_str()); |
---|
1275 | // log_printf(TRACE,Commit_unit,FUNCTION," * EVENT_FLUSH : %d",reg_EVENT_FLUSH [i][j]); |
---|
1276 | // log_printf(TRACE,Commit_unit,FUNCTION," * EVENT_STOP : %d",reg_EVENT_STOP [i][j]); |
---|
1277 | // log_printf(TRACE,Commit_unit,FUNCTION," * EVENT : %d (bank %d, ptr %d)",((reg_EVENT_NUM_PTR [i][j] << _param->_shift_num_slot) | reg_EVENT_NUM_BANK [i][j]), reg_EVENT_NUM_BANK [i][j],reg_EVENT_NUM_PTR [i][j]); |
---|
1278 | // log_printf(TRACE,Commit_unit,FUNCTION," * EVENT_CAN_RESTART : %d",reg_EVENT_CAN_RESTART [i][j]); |
---|
1279 | log_printf(TRACE,Commit_unit,FUNCTION," * EVENT_LAST : %d - packet %d - ptr %d (bank %d, ptr %d)",reg_EVENT_LAST [i][j],reg_EVENT_PACKET[i][j],((reg_EVENT_LAST_NUM_PTR [i][j] << _param->_shift_num_slot) | reg_EVENT_LAST_NUM_BANK [i][j]), reg_EVENT_LAST_NUM_BANK [i][j],reg_EVENT_LAST_NUM_PTR [i][j]); |
---|
1280 | log_printf(TRACE,Commit_unit,FUNCTION," * EVENT_NEXT : stop : %d - packet : %d",reg_EVENT_NEXT_STOP [i][j],reg_EVENT_NEXT_PACKET[i][j]); |
---|
1281 | log_printf(TRACE,Commit_unit,FUNCTION," * NB_INST_ALL : all : %d - mem : %d - event : %d",reg_NB_INST_COMMIT_ALL[i][j], reg_NB_INST_COMMIT_MEM[i][j],reg_EVENT_NB_INST[i][j]); |
---|
1282 | log_printf(TRACE,Commit_unit,FUNCTION," * PC : %.8x (%.8x) - %d %d - %.8x (%.8x)",reg_PC_CURRENT [i][j],reg_PC_CURRENT [i][j]<<2, reg_PC_CURRENT_IS_DS [i][j], reg_PC_CURRENT_IS_DS_TAKE [i][j],reg_PC_NEXT [i][j],reg_PC_NEXT [i][j]<<2); |
---|
1283 | } |
---|
1284 | |
---|
1285 | std::list<entry_t*>::iterator iter [_param->_nb_bank]; |
---|
1286 | for (uint32_t i=0; i<_param->_nb_bank; i++) |
---|
1287 | { |
---|
1288 | uint32_t num_bank = (reg_NUM_BANK_HEAD+i)%_param->_nb_bank; |
---|
1289 | // log_printf(TRACE,Commit_unit,FUNCTION," * Bank [%d] size : %d, ptr : %d",num_bank,(int)_rob[num_bank].size(), reg_BANK_PTR [i]); |
---|
1290 | |
---|
1291 | iter [num_bank] = _rob[num_bank].begin(); |
---|
1292 | } |
---|
1293 | |
---|
1294 | bool all_empty = false; |
---|
1295 | uint32_t nb_write_rd = 0; |
---|
1296 | uint32_t nb_write_re = 0; |
---|
1297 | |
---|
1298 | while (not all_empty) |
---|
1299 | { |
---|
1300 | all_empty = true; |
---|
1301 | |
---|
1302 | for (uint32_t i=0; i<_param->_nb_bank; i++) |
---|
1303 | { |
---|
1304 | uint32_t num_bank = (reg_NUM_BANK_HEAD+i)%_param->_nb_bank; |
---|
1305 | |
---|
1306 | std::list<entry_t*>::iterator it = iter[num_bank]; |
---|
1307 | if (it != _rob[num_bank].end()) |
---|
1308 | { |
---|
1309 | all_empty = false; |
---|
1310 | |
---|
1311 | nb_write_rd += ((*it)->write_rd)?1:0; |
---|
1312 | nb_write_re += ((*it)->write_re)?1:0; |
---|
1313 | |
---|
1314 | log_printf(TRACE,Commit_unit,FUNCTION," [%.4d][%.4d] %.4d %.4d %.4d %.4d, %.3d %.3d, %.1d, %.1d %.4d, %.1d %.4d, %s", |
---|
1315 | num_bank , |
---|
1316 | (*it)->ptr , |
---|
1317 | (*it)->front_end_id , |
---|
1318 | (*it)->context_id , |
---|
1319 | (*it)->rename_unit_id , |
---|
1320 | (*it)->depth , |
---|
1321 | (*it)->type , |
---|
1322 | (*it)->operation , |
---|
1323 | (*it)->is_delay_slot , |
---|
1324 | (*it)->use_store_queue , |
---|
1325 | (*it)->store_queue_ptr_write , |
---|
1326 | (*it)->use_load_queue , |
---|
1327 | (*it)->load_queue_ptr_write , |
---|
1328 | toString((*it)->state).c_str() ); |
---|
1329 | log_printf(TRACE,Commit_unit,FUNCTION," (%.4d) %.1d %.2d %.6d, %.1d %.2d %.6d, %.1d %.1d %.6d, %.1d %.2d %.6d %.6d, %.1d %.1d %.6d %.6d ", |
---|
1330 | (((*it)->ptr << _param->_shift_num_slot) | num_bank), |
---|
1331 | (*it)->read_ra , |
---|
1332 | (*it)->num_reg_ra_log , |
---|
1333 | (*it)->num_reg_ra_phy , |
---|
1334 | (*it)->read_rb , |
---|
1335 | (*it)->num_reg_rb_log , |
---|
1336 | (*it)->num_reg_rb_phy , |
---|
1337 | (*it)->read_rc , |
---|
1338 | (*it)->num_reg_rc_log , |
---|
1339 | (*it)->num_reg_rc_phy , |
---|
1340 | (*it)->write_rd , |
---|
1341 | (*it)->num_reg_rd_log , |
---|
1342 | (*it)->num_reg_rd_phy_old , |
---|
1343 | (*it)->num_reg_rd_phy_new , |
---|
1344 | (*it)->write_re , |
---|
1345 | (*it)->num_reg_re_log , |
---|
1346 | (*it)->num_reg_re_phy_old , |
---|
1347 | (*it)->num_reg_re_phy_new ); |
---|
1348 | |
---|
1349 | log_printf(TRACE,Commit_unit,FUNCTION," %.2d %.2d %.1d %.1d - %.8x (%.8x) %.8x (%.8x)", |
---|
1350 | (*it)->exception_use , |
---|
1351 | (*it)->exception , |
---|
1352 | (*it)->flags , |
---|
1353 | (*it)->no_sequence , |
---|
1354 | // (*it)->speculative , |
---|
1355 | (*it)->address , |
---|
1356 | (*it)->address<<2 , |
---|
1357 | (*it)->address_next , |
---|
1358 | (*it)->address_next<<2 |
---|
1359 | ); |
---|
1360 | |
---|
1361 | iter [num_bank] ++; |
---|
1362 | } |
---|
1363 | } |
---|
1364 | } |
---|
1365 | |
---|
1366 | log_printf(TRACE,Commit_unit,FUNCTION," * nb_write_rd : %d",nb_write_rd); |
---|
1367 | log_printf(TRACE,Commit_unit,FUNCTION," * nb_write_re : %d",nb_write_re); |
---|
1368 | } |
---|
1369 | #endif |
---|
1370 | |
---|
1371 | #ifdef DEBUG_TEST |
---|
1372 | { |
---|
1373 | uint32_t x=reg_NUM_BANK_HEAD; |
---|
1374 | if (not _rob[x].empty()) |
---|
1375 | { |
---|
1376 | entry_t * entry = _rob [x].front(); |
---|
1377 | |
---|
1378 | if (false |
---|
1379 | // or (entry->state == ROB_EMPTY ) |
---|
1380 | // or (entry->state == ROB_BRANCH_WAIT_END ) |
---|
1381 | // or (entry->state == ROB_BRANCH_COMPLETE ) |
---|
1382 | // or (entry->state == ROB_STORE_WAIT_HEAD_OK ) |
---|
1383 | // //or (entry->state == ROB_STORE_WAIT_HEAD_KO ) |
---|
1384 | // or (entry->state == ROB_STORE_HEAD_OK ) |
---|
1385 | // or (entry->state == ROB_STORE_HEAD_KO ) |
---|
1386 | // or (entry->state == ROB_OTHER_WAIT_END ) |
---|
1387 | // or (entry->state == ROB_EVENT_WAIT_END ) |
---|
1388 | // or (entry->state == ROB_END_OK_SPECULATIVE ) |
---|
1389 | or (entry->state == ROB_END_OK ) |
---|
1390 | // or (entry->state == ROB_END_KO_SPECULATIVE ) |
---|
1391 | // or (entry->state == ROB_END_KO ) |
---|
1392 | // or (entry->state == ROB_END_BRANCH_MISS_SPECULATIVE) |
---|
1393 | or (entry->state == ROB_END_BRANCH_MISS ) |
---|
1394 | // or (entry->state == ROB_END_LOAD_MISS_SPECULATIVE ) |
---|
1395 | // or (entry->state == ROB_END_LOAD_MISS_UPDATE ) |
---|
1396 | or (entry->state == ROB_END_LOAD_MISS ) |
---|
1397 | // or (entry->state == ROB_END_MISS ) |
---|
1398 | // or (entry->state == ROB_END_EXCEPTION_WAIT_HEAD ) |
---|
1399 | // or (entry->state == ROB_END_EXCEPTION_UPDATE ) |
---|
1400 | // or (entry->state == ROB_END_EXCEPTION ) |
---|
1401 | ) |
---|
1402 | if (entry->address != reg_PC_CURRENT[entry->front_end_id][entry->context_id]) |
---|
1403 | throw ERRORMORPHEO(FUNCTION,toString(_("Rob top address (0x%x) is different of reg_PC_CURRENT[%d][%d] (0x%x).\n"), |
---|
1404 | entry->address, |
---|
1405 | entry->front_end_id, |
---|
1406 | entry->context_id, |
---|
1407 | reg_PC_CURRENT[entry->front_end_id][entry->context_id])); |
---|
1408 | } |
---|
1409 | } |
---|
1410 | { |
---|
1411 | uint32_t NB_INST [_param->_nb_front_end][_param->_max_nb_context]; |
---|
1412 | for (uint32_t i=0; i<_param->_nb_front_end; i++) |
---|
1413 | for (uint32_t j=0; j<_param->_nb_context [i]; j++) |
---|
1414 | NB_INST [i][j] = 0; //reg_EVENT_NB_INST [i][j]; |
---|
1415 | |
---|
1416 | for (uint32_t i=0; i<_param->_nb_bank; ++i) |
---|
1417 | for (std::list<entry_t*>::iterator it=_rob[i].begin(); |
---|
1418 | it!=_rob [i].end(); |
---|
1419 | ++it) |
---|
1420 | NB_INST [(*it)->front_end_id][(*it)->context_id] ++; |
---|
1421 | |
---|
1422 | for (uint32_t i=0; i<_param->_nb_front_end; i++) |
---|
1423 | for (uint32_t j=0; j<_param->_nb_context [i]; j++) |
---|
1424 | if (NB_INST [i][j] != reg_NB_INST_COMMIT_ALL [i][j]) |
---|
1425 | throw ERRORMORPHEO(FUNCTION,toString(_("Context [%d][%d] have not the good nb_inst (%d in rob, %d in register).\n"),i,j,NB_INST[i][j], reg_NB_INST_COMMIT_ALL [i][j])); |
---|
1426 | } |
---|
1427 | #endif |
---|
1428 | |
---|
1429 | #if defined(STATISTICS) or defined(VHDL_TESTBENCH) |
---|
1430 | end_cycle (); |
---|
1431 | #endif |
---|
1432 | |
---|
1433 | // Stop Condition |
---|
1434 | for (uint32_t i=0; i<_param->_nb_front_end; i++) |
---|
1435 | for (uint32_t j=0; j<_param->_nb_context [i]; j++) |
---|
1436 | if (_nb_cycle_idle [i][j] >= debug_idle_cycle) |
---|
1437 | throw ERRORMORPHEO(FUNCTION,toString(_("Thread [%d] is idle since %.0f cycles.\n"),_param->_translate_num_context_to_num_thread[i][j],_nb_cycle_idle [i][j])); |
---|
1438 | |
---|
1439 | log_end(Commit_unit,FUNCTION); |
---|
1440 | }; |
---|
1441 | |
---|
1442 | }; // end namespace commit_unit |
---|
1443 | }; // end namespace ooo_engine |
---|
1444 | }; // end namespace multi_ooo_engine |
---|
1445 | }; // end namespace core |
---|
1446 | |
---|
1447 | }; // end namespace behavioural |
---|
1448 | }; // end namespace morpheo |
---|
1449 | #endif |
---|