Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_transition.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_transition.cpp	(revision 108)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_transition.cpp	(revision 109)
@@ -234,4 +234,5 @@
                       reg_EVENT_STATE [context] = EVENT_STATE_MISS_FLUSH_UFPT;
                     }
+                  reg_EVENT_SOURCE          [context] = EVENT_SOURCE_UFPT;
 
                   // Flush UPFT
@@ -506,7 +507,7 @@
 
 	      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * BRANCH_COMPLETE[%d] - Accepted",i);
-	      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * context    : %d",context);
-	      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * depth      : %d",depth);
-	      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * miss       : %d",miss);
+	      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * context        : %d",context);
+	      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * depth          : %d",depth);
+	      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * miss           : %d",miss);
 	      
               if (miss)
@@ -517,70 +518,98 @@
                   
                   // Flush UPT
-                  uint32_t top        = reg_UPT_TOP [context];
-                  uint32_t new_update = ((top==0)?_param->_size_upt_queue[context]:top)-1; 
-
-                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * top        : %d",top);
-                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * new_update : %d",new_update);
-
-                  for (uint32_t j=(depth+1)%_param->_size_upt_queue[context];
-                                j!=top; 
-                                j=(j+1)%_param->_size_upt_queue[context])
-                    reg_UPDATE_PREDICTION_TABLE [context][j]._state = UPDATE_PREDICTION_STATE_EVENT;
+                  uint32_t      top            = reg_UPT_TOP [context];
+                  uint32_t      new_update     = ((top==0)?_param->_size_upt_queue[context]:top)-1; 
+
+                  Taddress_t    address_src    = reg_UPDATE_PREDICTION_TABLE [context][depth]._address_src;
+                  event_state_t event_state    = reg_EVENT_STATE [context];
+                  bool          previous_event = ((event_state == EVENT_STATE_MISS_FLUSH_UFPT_AND_UPT ) or
+                                                  (event_state == EVENT_STATE_MISS_FLUSH_UPT          ) or
+                                                  (event_state == EVENT_STATE_EVENT_FLUSH_UFPT_AND_UPT) or
+                                                  (event_state == EVENT_STATE_EVENT_FLUSH_UPT         ) or
+                                                  ((event_state == EVENT_STATE_UPDATE_CONTEXT          ) and
+                                                   (reg_EVENT_SOURCE [context] == EVENT_SOURCE_UPT)));
+//                bool          update_ras     = (new_update != depth);
+
+                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * top            : %d",top);
+                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * new_update     : %d",new_update);
+//                log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * update_ras     : %d",update_ras);
+                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * previous_event : %d",previous_event);
+
+                  if (reg_UPDATE_PREDICTION_TABLE [context][depth]._state == UPDATE_PREDICTION_STATE_WAIT_END)
+                    {
+                      for (uint32_t j=(depth+1)%_param->_size_upt_queue[context];
+                           j!=top; 
+                           j=(j+1)%_param->_size_upt_queue[context])
+                        reg_UPDATE_PREDICTION_TABLE [context][j]._state = UPDATE_PREDICTION_STATE_EVENT;
+                      
                   
-                  
-//                reg_UPT_BOTTOM    [context];
-                  reg_UPT_TOP       [context] = depth;
-                  reg_UPT_TOP_EVENT [context] = top;
-
-                  if (reg_UPT_BOTTOM [context] == reg_UPT_TOP [context])
-                    reg_UPT_EMPTY [context] = true;
-
+//                    reg_UPT_BOTTOM    [context];
+                      reg_UPT_TOP       [context] = depth;
+//                    reg_UPT_TOP_EVENT [context] = top;
+
+                      if (not previous_event)
+                        {
+                          reg_UPT_TOP_EVENT [context] = top;
+                          reg_UPT_UPDATE    [context] = new_update;
+                        }
+                      else
+                        {
+                          // Have event. Top index this slot
+                          
+                          switch (reg_UPDATE_PREDICTION_TABLE [context][top]._state)
+                            {
+                            case UPDATE_PREDICTION_STATE_END_KO : 
+                              {
+                                // Have already update predictor
+                                reg_UPDATE_PREDICTION_TABLE [context][top]._state = UPDATE_PREDICTION_STATE_END;
+                                break;
+                              }
+                            case UPDATE_PREDICTION_STATE_KO :
+                              {
+                                // Doesn't have update predictor
+                                reg_UPDATE_PREDICTION_TABLE [context][top]._state = UPDATE_PREDICTION_STATE_EVENT;
+                                break;
+                              }
+                            default :
+                              {
 #ifdef DEBUG_TEST
-                  if (reg_UPDATE_PREDICTION_TABLE [context][depth]._state != UPDATE_PREDICTION_STATE_WAIT_END)
-                    throw ERRORMORPHEO(FUNCTION,_("Branch complete : invalid upt state."));
-#endif
-                  
-                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UPT  [%d][%d].state <- UPDATE_PREDICTION_STATE_KO (branch_complete, ifetch hit)",context,depth);
-                  reg_UPDATE_PREDICTION_TABLE [context][depth]._state = UPDATE_PREDICTION_STATE_KO;
-                  
-                  Taddress_t    address_src         = reg_UPDATE_PREDICTION_TABLE [context][depth]._address_src;
-                  event_state_t event_state         = reg_EVENT_STATE [context];
-                  bool          previous_update_ras = ((event_state == EVENT_STATE_MISS_FLUSH_UFPT_AND_UPT ) or
-                                                       (event_state == EVENT_STATE_MISS_FLUSH_UPT          ) or
-                                                       (event_state == EVENT_STATE_EVENT_FLUSH_UFPT_AND_UPT) or
-                                                       (event_state == EVENT_STATE_EVENT_FLUSH_UPT));
-//                   bool          update_ras          = (new_update != depth);
-
-//                   log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * update_ras : %d",update_ras);
-                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * previous_update_ras : %d",previous_update_ras);
-
-                  if (reg_UFPT_NB_NEED_UPDATE [context] > 0)
-                    {
-                      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * EVENT [%d] <- EVENT_STATE_MISS_FLUSH_UFPT_AND_UPT (branch_complete - miss)",context);
-                      reg_EVENT_STATE [context] = EVENT_STATE_MISS_FLUSH_UFPT_AND_UPT;
+                                throw ERRORMORPHEO(FUNCTION,_("Branch complete : invalid upt state."));
+#endif
+                              }
+                            }
+                        }
+                      
+                      if (reg_UPT_BOTTOM [context] == reg_UPT_TOP [context])
+                        reg_UPT_EMPTY [context] = true;
+                      
+                      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UPT  [%d][%d].state <- UPDATE_PREDICTION_STATE_KO (branch_complete, ifetch hit)",context,depth);
+                      reg_UPDATE_PREDICTION_TABLE [context][depth]._state = UPDATE_PREDICTION_STATE_KO;
+                      
+                      if (reg_UFPT_NB_NEED_UPDATE [context] > 0)
+                        {
+                          log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * EVENT [%d] <- EVENT_STATE_MISS_FLUSH_UFPT_AND_UPT (branch_complete - miss)",context);
+                          reg_EVENT_STATE [context] = EVENT_STATE_MISS_FLUSH_UFPT_AND_UPT;
+                        }
+                      else
+                        {
+//                        if (not previous_update_ras)
+                          {
+                            // have ras prediction ?
+                            log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * EVENT [%d] <- EVENT_STATE_MISS_FLUSH_UPT (branch_complete - miss)",context);
+                            
+                            reg_EVENT_STATE [context] = EVENT_STATE_MISS_FLUSH_UPT;
+                            
+                          }
+                        }
+                      reg_EVENT_SOURCE          [context] = EVENT_SOURCE_UPT;
+                      
+                      // else no update
+                      
+                      reg_EVENT_DEPTH           [context] = depth;
+                      reg_EVENT_ADDRESS_SRC     [context] = address_src; // delay_slot is compute in Context_State
+                      reg_EVENT_ADDRESS_DEST_VAL[context] = good_take;
+                      reg_EVENT_ADDRESS_DEST    [context] = good_addr;
                     }
-                  else
-                    {
-//                       if (not previous_update_ras)
-                        {
-                          // have ras prediction ?
-                          log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * EVENT [%d] <- EVENT_STATE_MISS_FLUSH_UPT (branch_complete - miss)",context);
-
-                          reg_EVENT_STATE [context] = EVENT_STATE_MISS_FLUSH_UPT;
-             
-                        }
-                    }
-
-                  if (not previous_update_ras)
-                    {
-                      reg_UPT_UPDATE [context]  = new_update;
-                    }
-                  // else no update
-
-                  reg_EVENT_DEPTH           [context] = depth;
-                  reg_EVENT_ADDRESS_SRC     [context] = address_src; // delay_slot is compute in Context_State
-                  reg_EVENT_ADDRESS_DEST_VAL[context] = good_take;
-                  reg_EVENT_ADDRESS_DEST    [context] = good_addr;
-		}
+                }
 	      else
 		{
@@ -901,4 +930,5 @@
         log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_EVENT_UPT_PTR         : %d"  ,reg_EVENT_UPT_PTR         [i]);
         log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_EVENT_STATE           : %s"  ,toString(reg_EVENT_STATE [i]).c_str());
+        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_EVENT_SOURCE          : %s"  ,toString(reg_EVENT_SOURCE[i]).c_str());
         log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_EVENT_DEPTH           : %d"  ,reg_EVENT_DEPTH           [i]);
         log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_EVENT_ADDRESS_SRC     : %.8x (%.8x)",reg_EVENT_ADDRESS_SRC     [i],reg_EVENT_ADDRESS_SRC     [i]<<2);
