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