Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_OOO_Engine/OOO_Engine/Commit_unit/src/Commit_unit_transition.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_OOO_Engine/OOO_Engine/Commit_unit/src/Commit_unit_transition.cpp	(revision 98)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_OOO_Engine/OOO_Engine/Commit_unit/src/Commit_unit_transition.cpp	(revision 100)
@@ -26,4 +26,5 @@
     if (PORT_READ(in_NRESET) == 0)
       {
+        // Clear all bank 
         for (uint32_t i=0; i<_param->_nb_bank; i++)
 	  {
@@ -32,7 +33,9 @@
 	  }
 
+        // Reset pointer
 	reg_NUM_BANK_HEAD = 0;
 	reg_NUM_BANK_TAIL = 0;
 
+        // Reset counter
 	for (uint32_t i=0; i<_param->_nb_front_end; i++)
 	  for (uint32_t j=0; j<_param->_nb_context [i]; j++)
@@ -40,12 +43,29 @@
 	      reg_NB_INST_COMMIT_ALL [i][j] = 0;
 	      reg_NB_INST_COMMIT_MEM [i][j] = 0;
+
+              reg_EVENT_STATE        [i][j] = EVENT_STATE_NO_EVENT;
 	    }
 
+        // Reset priority algorithm
 	_priority_insert->reset();
       }
     else
       {
-	// next priority
+	// Compute next priority
 	_priority_insert->transition();
+
+	// ===================================================================
+	// =====[ GARBAGE COLLECTOR ]=========================================
+	// ===================================================================
+	for (uint32_t i=0; i<_param->_nb_front_end; i++)
+	  for (uint32_t j=0; j<_param->_nb_context [i]; j++)
+            switch (reg_EVENT_STATE [i][j])
+              {
+              case EVENT_STATE_EVENT    : reg_EVENT_STATE [i][j] = EVENT_STATE_WAITEND ; break;
+              case EVENT_STATE_END      : reg_EVENT_STATE [i][j] = EVENT_STATE_NO_EVENT; break;
+//            case EVENT_STATE_NO_EVENT : 
+//            case EVENT_STATE_WAITEND  : 
+              default : break;
+              }
 
 	// ===================================================================
@@ -55,4 +75,5 @@
 	  if (internal_BANK_INSERT_VAL [i])
 	    {
+              // get rename unit source and instruction.
 	      uint32_t x = internal_BANK_INSERT_NUM_RENAME_UNIT [i];
 	      uint32_t y = internal_BANK_INSERT_NUM_INST        [i];
@@ -67,8 +88,11 @@
 #endif
 
+                  // get information
 		  Tcontext_t   front_end_id = (_param->_have_port_front_end_id)?PORT_READ(in_INSERT_FRONT_END_ID [x][y]):0;
 		  Tcontext_t   context_id   = (_param->_have_port_context_id  )?PORT_READ(in_INSERT_CONTEXT_ID   [x][y]):0;
 		  Ttype_t      type         = PORT_READ(in_INSERT_TYPE         [x][y]);
                   Toperation_t operation    = PORT_READ(in_INSERT_OPERATION    [x][y]);
+                  bool         is_store     = is_operation_memory_store(operation);
+
 		  Texception_t exception    = PORT_READ(in_INSERT_EXCEPTION    [x][y]);
 
@@ -78,5 +102,6 @@
 		  log_printf(TRACE,Commit_unit,FUNCTION,"    * operation      : %d",operation );
 		  log_printf(TRACE,Commit_unit,FUNCTION,"    * exception      : %d",exception );
-
+                  
+                  // Create new entry.
 		  entry_t * entry = new entry_t;
 
@@ -92,6 +117,6 @@
 		  entry->exception               = exception;
 		  entry->exception_use           = PORT_READ(in_INSERT_EXCEPTION_USE         [x][y]);
-		  entry->use_store_queue         = (type == TYPE_MEMORY) and (    is_operation_memory_store(operation));
-		  entry->use_load_queue          = (type == TYPE_MEMORY) and (not is_operation_memory_store(operation));
+		  entry->use_store_queue         = (type == TYPE_MEMORY) and (    is_store);
+		  entry->use_load_queue          = (type == TYPE_MEMORY) and (not is_store);
 		  entry->store_queue_ptr_write   = PORT_READ(in_INSERT_STORE_QUEUE_PTR_WRITE [x][y]);
 		  entry->load_queue_ptr_write    = (_param->_have_port_load_queue_ptr)?PORT_READ(in_INSERT_LOAD_QUEUE_PTR_WRITE [x][y]):0;
@@ -114,4 +139,12 @@
 		  entry->num_reg_re_phy_new      = PORT_READ(in_INSERT_NUM_REG_RE_PHY_NEW    [x][y]);
 
+                  // Test if exception :
+                  //  * yes : no execute instruction, wait ROB Head
+                  //  * no  : test type
+                  //            * BRANCH : l.j   -> branch is ended
+                  //                       other -> wait the execution end of branchment
+                  //            * MEMORY : store -> wait store is at head of ROB
+                  //                       other -> wait end of instruction
+                  //            * OTHER
 		  if (exception == EXCEPTION_NONE)
 		    {
@@ -124,5 +157,5 @@
 			{
 			case TYPE_BRANCH : {entry->state=(no_execute==1)?ROB_BRANCH_COMPLETE:ROB_BRANCH_WAIT_END; break;}
-			case TYPE_MEMORY : {entry->state=ROB_STORE_WAIT_HEAD_OK; break;}
+			case TYPE_MEMORY : {entry->state=(is_store  ==1)?ROB_STORE_WAIT_HEAD_OK:ROB_OTHER_WAIT_END; break;}
 			default          : {entry->state=(no_execute==1)?ROB_END_OK_SPECULATIVE:ROB_OTHER_WAIT_END; break;}
 			}
@@ -130,4 +163,6 @@
 		  else
 		    {
+                      // Have an exception : wait head of ROB
+
                       // in_INSERT_NO_EXECUTE [x][y] : l.sys, l.trap
 
@@ -135,7 +170,8 @@
 		    }
 
+                  // Push in rob
 		  _rob[i].push_back(entry);
 
-		  // Update nb_inst
+		  // Update counter and pointer
 		  reg_NB_INST_COMMIT_ALL [front_end_id][context_id] ++;
 		  if (type == TYPE_MEMORY)
@@ -160,4 +196,6 @@
 	    if (internal_BANK_COMMIT_VAL [i][j])
 	      {
+                // An instruction is executed. Change state of this instruction
+
 		uint32_t x = internal_BANK_COMMIT_NUM_INST [i][j];
 
@@ -171,93 +209,73 @@
 #endif
 
-// 		    Tpacket_t packet_id = (_param->_have_port_rob_ptr  )?(PORT_READ(in_COMMIT_PACKET_ID [x])&_param->_mask_size_bank):0;
-		    
 		    log_printf(TRACE,Commit_unit,FUNCTION,"    * num_bank   : %d",i);
-// 		    log_printf(TRACE,Commit_unit,FUNCTION,"    * packet_id  : %d",(_param->_have_port_rob_ptr  )?(PORT_READ(in_COMMIT_PACKET_ID [x])):0);
-// 		    log_printf(TRACE,Commit_unit,FUNCTION,"    * num_entry  : %d",packet_id);
-		    
-		    // test pandex with ptr_write.
-// 		    Tpacket_t index     = (packet_id<reg_BANK_PTR [i])?(reg_BANK_PTR [i]-packet_id):(_param->_size_bank+reg_BANK_PTR [i]-packet_id);
 
 		    // find the good entry !!!
-		    entry_t *       entry       = internal_BANK_COMMIT_ENTRY [i][j];
-
-		  //Toperation_t    operation   = PORT_READ(in_COMMIT_OPERATION   [x]);
-		  //Ttype_t         type        = PORT_READ(in_COMMIT_TYPE        [x]);
-		    Texception_t    exception   = PORT_READ(in_COMMIT_EXCEPTION   [x]);
-
-		    rob_state_t state        = entry->state;
-		    Tcontext_t  front_end_id = entry->front_end_id;
-		    Tcontext_t  context_id   = entry->context_id;
-
-		    // change state
+		    entry_t *       entry        = internal_BANK_COMMIT_ENTRY [i][j];
+                                                 
+		  //Toperation_t    operation    = PORT_READ(in_COMMIT_OPERATION   [x]);
+		  //Ttype_t         type         = PORT_READ(in_COMMIT_TYPE        [x]);
+		    Texception_t    exception    = PORT_READ(in_COMMIT_EXCEPTION   [x]);
+
+		    rob_state_t     state        = entry->state;
+		    Tcontext_t      front_end_id = entry->front_end_id;
+		    Tcontext_t      context_id   = entry->context_id;
+
+		    // change state : test exception_use
 		    //  * test if exception : exception and mask
 		    
-		    bool have_exception = false;
-		    
+		    bool have_exception        = false;
+                    bool have_miss_speculation = false;
+
 		    if (exception != EXCEPTION_NONE)
-		      switch (entry->exception_use)
-			{
-			case  EXCEPTION_USE_RANGE                    : {have_exception = ((exception == EXCEPTION_RANGE) and PORT_READ(in_SPR_READ_SR_OVE[front_end_id][context_id])); break;}
-			case  EXCEPTION_USE_MEMORY_WITH_ALIGNMENT    : {have_exception = ((exception == EXCEPTION_BUS_ERROR) or
-											  (exception == EXCEPTION_DATA_TLB ) or
-											  (exception == EXCEPTION_DATA_PAGE) or
-											  (exception == EXCEPTION_ALIGNMENT)); break;};
-			case  EXCEPTION_USE_MEMORY_WITHOUT_ALIGNMENT : {have_exception = ((exception == EXCEPTION_BUS_ERROR) or
-											  (exception == EXCEPTION_DATA_TLB ) or
-											  (exception == EXCEPTION_DATA_PAGE)); break;};
-			case  EXCEPTION_USE_CUSTOM_0                 : {have_exception = (exception == EXCEPTION_CUSTOM_0); break;}; 
-			case  EXCEPTION_USE_CUSTOM_1                 : {have_exception = (exception == EXCEPTION_CUSTOM_1); break;}; 
-			case  EXCEPTION_USE_CUSTOM_2                 : {have_exception = (exception == EXCEPTION_CUSTOM_2); break;}; 
-			case  EXCEPTION_USE_CUSTOM_3                 : {have_exception = (exception == EXCEPTION_CUSTOM_3); break;}; 
-			case  EXCEPTION_USE_CUSTOM_4                 : {have_exception = (exception == EXCEPTION_CUSTOM_4); break;}; 
-			case  EXCEPTION_USE_CUSTOM_5                 : {have_exception = (exception == EXCEPTION_CUSTOM_5); break;}; 
-			case  EXCEPTION_USE_CUSTOM_6                 : {have_exception = (exception == EXCEPTION_CUSTOM_6); break;}; 
-			case  EXCEPTION_USE_TRAP                     : {have_exception = false; break;};
-			case  EXCEPTION_USE_NONE                     : {have_exception = false; break;}; 
-			case  EXCEPTION_USE_ILLEGAL_INSTRUCTION      : {have_exception = false; break;};
-			case  EXCEPTION_USE_SYSCALL                  : {have_exception = false; break;};
-			default :
-			  {
-			    throw ERRORMORPHEO(FUNCTION,_("Commit : invalid exception_use.\n"));
-			    break;
-			  }
-			}
-
-		    if (not have_exception)
-		      {
-			switch (state)
-			  {
-			  case ROB_OTHER_WAIT_END  : {state = ROB_END_OK_SPECULATIVE; break;}
-			  case ROB_BRANCH_WAIT_END : {state = ROB_BRANCH_COMPLETE   ; break;}
-			  case ROB_MISS_WAIT_END   : {state = ROB_END_KO_SPECULATIVE; break;}
-			  default :
-			    {
-			      throw ERRORMORPHEO(FUNCTION,toString(_("Commit : invalid state value (%s).\n"),toString(state).c_str()));
-			      break;
-			    }
-			  }
-			// can have an exception, but this instruction is not sensible a this exception
-			exception = EXCEPTION_NONE; 
-		      }
-		    else
-		      {
-#ifdef DEBUG_TEST
-			if ((entry->type == TYPE_MEMORY) and (exception == EXCEPTION_MEMORY_LOAD_SPECULATIVE))
-			  throw ERRORMORPHEO(FUNCTION,_("Commit : invalid exception.\n"));
-#endif 
-
-			switch (state)
-			  {
-			  case ROB_OTHER_WAIT_END  : 
-			  case ROB_BRANCH_WAIT_END : {state = ROB_END_EXCEPTION_WAIT_HEAD; break;}
-			  case ROB_MISS_WAIT_END   : {state = ROB_END_KO_SPECULATIVE     ; break;}
-			  default :
-			    {
-			      throw ERRORMORPHEO(FUNCTION,_("Commit : invalid state value.\n"));
-			      break;
-			    }
-			  }
-		      }
+                      {
+                        // Test if the instruction is a load and is a miss speculation (load is commit, but they have an dependence with a previous store)
+                        have_miss_speculation  = (exception == EXCEPTION_MEMORY_MISS_SPECULATION);
+
+                        switch (entry->exception_use)
+                          {
+                            // Have overflow exception if bit overflow enable is set.
+                          case  EXCEPTION_USE_RANGE                    : {have_exception = ((exception == EXCEPTION_RANGE) and PORT_READ(in_SPR_READ_SR_OVE[front_end_id][context_id])); break;}
+                          case  EXCEPTION_USE_MEMORY_WITH_ALIGNMENT    : {have_exception = ((exception == EXCEPTION_BUS_ERROR) or
+                                                                                            (exception == EXCEPTION_DATA_TLB ) or
+                                                                                            (exception == EXCEPTION_DATA_PAGE) or
+                                                                                            (exception == EXCEPTION_ALIGNMENT)); break;};
+                          case  EXCEPTION_USE_MEMORY_WITHOUT_ALIGNMENT : {have_exception = ((exception == EXCEPTION_BUS_ERROR) or
+                                                                                            (exception == EXCEPTION_DATA_TLB ) or
+                                                                                            (exception == EXCEPTION_DATA_PAGE)); break;};
+                          case  EXCEPTION_USE_CUSTOM_0                 : {have_exception = (exception == EXCEPTION_CUSTOM_0); break;}; 
+                          case  EXCEPTION_USE_CUSTOM_1                 : {have_exception = (exception == EXCEPTION_CUSTOM_1); break;}; 
+                          case  EXCEPTION_USE_CUSTOM_2                 : {have_exception = (exception == EXCEPTION_CUSTOM_2); break;}; 
+                          case  EXCEPTION_USE_CUSTOM_3                 : {have_exception = (exception == EXCEPTION_CUSTOM_3); break;}; 
+                          case  EXCEPTION_USE_CUSTOM_4                 : {have_exception = (exception == EXCEPTION_CUSTOM_4); break;}; 
+                          case  EXCEPTION_USE_CUSTOM_5                 : {have_exception = (exception == EXCEPTION_CUSTOM_5); break;}; 
+                          case  EXCEPTION_USE_CUSTOM_6                 : {have_exception = (exception == EXCEPTION_CUSTOM_6); break;}; 
+                            // Case already manage (decod stage -> in insert in ROB)
+                          case  EXCEPTION_USE_TRAP                     : {have_exception = false; exception = EXCEPTION_NONE; break;};
+                          case  EXCEPTION_USE_NONE                     : {have_exception = false; exception = EXCEPTION_NONE; break;}; 
+                          case  EXCEPTION_USE_ILLEGAL_INSTRUCTION      : {have_exception = false; exception = EXCEPTION_NONE; break;};
+                          case  EXCEPTION_USE_SYSCALL                  : {have_exception = false; exception = EXCEPTION_NONE; break;};
+                          default :
+                            {
+                              throw ERRORMORPHEO(FUNCTION,_("Commit : invalid exception_use.\n"));
+                              break;
+                            }
+                          }
+                      }
+                   
+                    switch (state)
+                      {
+                        // Branch ...
+                      case ROB_BRANCH_WAIT_END : {state = (have_exception)?ROB_END_EXCEPTION_WAIT_HEAD:ROB_BRANCH_COMPLETE; break;}
+                        // Store KO
+                      case ROB_MISS_WAIT_END   : {state = ROB_END_KO_SPECULATIVE; break;}
+                        // Store OK, Load and other instruction
+                      case ROB_OTHER_WAIT_END  : {state = (have_exception)?ROB_END_EXCEPTION_WAIT_HEAD:((have_miss_speculation)?ROB_END_MISS:ROB_END_OK_SPECULATIVE); break;}
+                      default :
+                        {
+                          throw ERRORMORPHEO(FUNCTION,toString(_("Commit : invalid state value (%s).\n"),toString(state).c_str()));
+                          break;
+                        }
+                      }
 
 		    // update Re Order Buffer
@@ -287,9 +305,9 @@
 
 	      entry_t *  entry        =  _rob [i].front();
+              rob_state_t state = entry->state;
+              
 #ifdef STATISTICS
               if (usage_is_set(_usage,USE_STATISTICS))
                 {
-                  rob_state_t state = entry->state;
-                  
                   if (state == ROB_END_OK)
                     (*_stat_nb_inst_retire_ok [x]) ++;
@@ -302,4 +320,11 @@
 	      Tcontext_t context_id   = entry->context_id  ;
 	      Ttype_t    type         = entry->type        ;
+
+              if (state == ROB_END_BRANCH_MISS)
+                {
+                  reg_EVENT_STATE [front_end_id][context_id] = EVENT_STATE_EVENT;
+
+                  // !!!!!!!!!!! Compute address
+                }
 	      
 	      // Update nb_inst
@@ -307,5 +332,8 @@
 	      if (type == TYPE_MEMORY)
 		reg_NB_INST_COMMIT_MEM [front_end_id][context_id] --;
-	      
+
+              if (reg_NB_INST_COMMIT_ALL [front_end_id][context_id] == 0)
+                reg_EVENT_STATE [front_end_id][context_id] = EVENT_STATE_END;
+
 	      reg_NUM_BANK_HEAD = (reg_NUM_BANK_HEAD+1)%_param->_nb_bank;
 	      
@@ -350,10 +378,21 @@
 #endif
 
-	      entry->state = ROB_END_OK_SPECULATIVE;
+              entry->state = (PORT_READ(in_BRANCH_COMPLETE_MISS_PREDICTION [i]))?ROB_END_OK_SPECULATIVE:ROB_END_BRANCH_MISS_SPECULATIVE;
+//               entry->state = ROB_END_OK_SPECULATIVE;
 	    }
 
 	// ===================================================================
+	// =====[ UPDATE ]====================================================
+	// ===================================================================
+        {
+          // Not yet implemented
+        }
+
+	// ===================================================================
 	// =====[ EVENT ]=====================================================
 	// ===================================================================
+        {
+          // Not yet implemented
+        }
 
 	// ===================================================================
@@ -400,24 +439,26 @@
 		  switch (state)
 		    {
-		    case ROB_BRANCH_WAIT_END           : {state = ROB_MISS_WAIT_END; break;}
-		    case ROB_BRANCH_COMPLETE           : {state = ROB_END_MISS     ; break;}
-		    case ROB_STORE_WAIT_HEAD_OK        : {state = ROB_STORE_HEAD_KO; break;}
-		  //case ROB_STORE_WAIT_HEAD_KO        : {state = ; break;}
-		    case ROB_OTHER_WAIT_END            : {state = ROB_MISS_WAIT_END; break;}
-		    case ROB_END_OK_SPECULATIVE        : {state = ROB_END_MISS     ; break;}
-		    case ROB_END_KO_SPECULATIVE        : {state = ROB_END_MISS     ; break;}
-		    case ROB_END_EXCEPTION_WAIT_HEAD   : {state = ROB_END_MISS     ; break;}
-		      
-		      // don't change
-		    case ROB_STORE_HEAD_KO             : {break;}
-		    case ROB_MISS_WAIT_END             : {break;}
-		    case ROB_END_MISS                  : {break;}
-		      
-		      // can't have miss speculation
-		    case ROB_STORE_HEAD_OK             :
-		    case ROB_END_OK                    :
-		    case ROB_END_KO                    :
-		    case ROB_END_EXCEPTION             :
-		    default                            : 
+		    case ROB_BRANCH_WAIT_END             : {state = ROB_MISS_WAIT_END; break;}
+		    case ROB_BRANCH_COMPLETE             : {state = ROB_END_MISS     ; break;}
+                    case ROB_END_BRANCH_MISS_SPECULATIVE : {state = ROB_END_MISS     ; break;}
+		    case ROB_STORE_WAIT_HEAD_OK          : {state = ROB_STORE_HEAD_KO; break;}
+		  //case ROB_STORE_WAIT_HEAD_KO          : {state = ; break;}
+		    case ROB_OTHER_WAIT_END              : {state = ROB_MISS_WAIT_END; break;}
+		    case ROB_END_OK_SPECULATIVE          : {state = ROB_END_MISS     ; break;}
+		    case ROB_END_KO_SPECULATIVE          : {state = ROB_END_MISS     ; break;}
+		    case ROB_END_EXCEPTION_WAIT_HEAD     : {state = ROB_END_MISS     ; break;}
+		                                         
+		      // don't change                    
+		    case ROB_STORE_HEAD_KO               : {break;}
+		    case ROB_MISS_WAIT_END               : {break;}
+		    case ROB_END_MISS                    : {break;}
+		                                         
+		      // can't have miss speculation     
+		    case ROB_STORE_HEAD_OK               :
+		    case ROB_END_OK                      :
+		    case ROB_END_KO                      :
+                    case ROB_END_BRANCH_MISS             :
+		    case ROB_END_EXCEPTION               :
+		    default                              : 
 		      {
 			throw ERRORMORPHEO(FUNCTION,_("Miss Speculation : Invalide state.\n"));
@@ -434,6 +475,7 @@
 		  switch (state)
 		    {
-		    case ROB_END_OK_SPECULATIVE        : {state = ROB_END_OK                 ; break;}
-		    case ROB_END_KO_SPECULATIVE        : {state = ROB_END_KO                 ; break;}
+		    case ROB_END_OK_SPECULATIVE          : {state = ROB_END_OK                 ; break;}
+		    case ROB_END_KO_SPECULATIVE          : {state = ROB_END_KO                 ; break;}
+		    case ROB_END_BRANCH_MISS_SPECULATIVE : {state = ROB_END_BRANCH_MISS        ; break;}
 		    default : {break;}
 		  }
@@ -519,11 +561,10 @@
                        (*it)->num_reg_re_phy_new      );
             
-            log_printf(TRACE,Commit_unit,FUNCTION,"             %.2d %.2d %.1d %.1d %.8x %s",
+            log_printf(TRACE,Commit_unit,FUNCTION,"             %.2d %.2d %.1d %.1d %.8x",
                        (*it)->exception     ,
                        (*it)->exception_use ,
                        (*it)->flags         ,
                        (*it)->no_sequence   ,
-                       (*it)->data_commit   ,
-                       toString((*it)->event_state).c_str()
+                       (*it)->data_commit   
                        );
 
