Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Context_State/src/Context_State_transition.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Context_State/src/Context_State_transition.cpp	(revision 120)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Context_State/src/Context_State_transition.cpp	(revision 122)
@@ -16,4 +16,5 @@
 namespace context_state {
 
+#define MISS_FAST
 
 #define get_priority(x) \
@@ -53,6 +54,9 @@
 //             uint32_t x = _param->_link_context_to_decod_unit    [i];
 
-            Tcounter_t inst_all = PORT_READ(in_NB_INST_COMMIT_ALL[i]) + PORT_READ(in_NB_INST_DECOD_ALL [i]);
-//          Tcounter_t inst_mem = PORT_READ(in_NB_INST_COMMIT_MEM[i]) + PORT_READ(in_NB_INST_DECOD_ALL [i]);
+            Tcounter_t inst_commit_all = PORT_READ(in_NB_INST_COMMIT_ALL[i]);
+//          Tcounter_t inst_commit_mem = PORT_READ(in_NB_INST_COMMIT_MEM[i]);
+            Tcounter_t inst_decod_all  = PORT_READ(in_NB_INST_DECOD_ALL [i]);
+            Tcounter_t inst_all        = inst_commit_all + inst_decod_all;
+//          Tcounter_t inst_mem        = inst_commit_mem + inst_decod_all;
 
             context_state_t state = reg_STATE [i];
@@ -69,4 +73,5 @@
                   // Wait end of all instruction
                   if (inst_all == 0)
+//                if (inst_decod_all == 0)
                     state = CONTEXT_STATE_KO_EXCEP_ADDR;
                   break;
@@ -85,7 +90,14 @@
                 {
                   // Wait end of all instruction
-                  if (inst_all == 0)
+//                if (inst_all == 0)
+                  if (
+#ifdef  MISS_FAST
+                      inst_decod_all ==
+#else
+                      inst_all ==
+#endif
+                      0)
                     
-//                  state = CONTEXT_STATE_OK; // @@@ TODO : make MISS fast (miss decod)
+//                  state = CONTEXT_STATE_OK;
                     state = CONTEXT_STATE_KO_MISS_BRANCH_ADDR;
                   break;
@@ -94,5 +106,12 @@
                 {
                   // Wait end of all instruction
-                  if (inst_all == 0)
+//                if (inst_all == 0)
+                  if (
+#ifdef  MISS_FAST
+                      inst_decod_all ==
+#else
+                      inst_all ==
+#endif
+                      0)
                     state = CONTEXT_STATE_KO_MISS_LOAD_ADDR;
 
@@ -127,6 +146,12 @@
                 {
                   // Wait end of all instruction
-                  if (inst_all == 0)
-                    
+//                if (inst_all == 0)
+                  if (
+#ifdef  MISS_FAST
+                      inst_decod_all ==
+#else
+                      inst_all ==
+#endif
+                      0)
 //                  state = CONTEXT_STATE_OK; // @@@ TODO : make MISS fast (miss decod)
                     state = CONTEXT_STATE_KO_MISS_LOAD_AND_BRANCH_ADDR;
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/include/Parameters.h
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/include/Parameters.h	(revision 120)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/include/Parameters.h	(revision 122)
@@ -36,6 +36,8 @@
   public : uint32_t   _nb_thread                          ;
   public : uint32_t * _translate_num_context_to_num_thread;//[nb_context]                    
-  public : const bool _accurate_block_predict    ;
-  public : const bool _accurate_block_decod      ;
+  public : const bool _always_accurate_predict   ;
+  public : const bool _always_accurate_decod     ;
+  public : const bool _can_accurate_predict      ;
+  public : const bool _can_accurate_decod        ;
 
 //public : uint32_t   _size_context_id           ;
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/include/Types.h
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/include/Types.h	(revision 120)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/include/Types.h	(revision 122)
@@ -25,16 +25,35 @@
     } event_source_t;
 
-  typedef enum
-    {
-      EVENT_STATE_OK                      , // Can predict
-      EVENT_STATE_MISS_FLUSH_UFPT         , // in decod  stage, detect a miss  , continue to execute but flush ufpt
-      EVENT_STATE_MISS_FLUSH_UFPT_AND_UPT , // in commit stage, detect a miss  , stop context and flush ufpt and upt
-      EVENT_STATE_MISS_FLUSH_UPT          , // in commit stage, detect a miss  , context is stop and ufpt is flush, update RAS
-      EVENT_STATE_EVENT_FLUSH_UFPT        , // in commit stage, detect an event, continue to execute but flush ufpt
-      EVENT_STATE_EVENT_FLUSH_UFPT_AND_UPT, // in commit stage, detect an event, stop context and flush ufpt and upt
-      EVENT_STATE_EVENT_FLUSH_UPT         , // in commit stage, detect an event, context is stop and ufpt is flush, update RAS
-      EVENT_STATE_UPDATE_CONTEXT          , // prediction unit is update, send signal to context manager
-      EVENT_STATE_WAIT_END_EVENT            // prediction unit is ok, wait the end of event (send by Context State)
-    } event_state_t;
+//   typedef enum
+//     {
+//       EVENT_STATE_OK                      , // Can predict
+//       EVENT_STATE_MISS_FLUSH_UFPT         , // in decod  stage, detect a miss  , continue to execute but flush ufpt
+//       EVENT_STATE_MISS_FLUSH_UFPT_AND_UPT , // in commit stage, detect a miss  , stop context and flush ufpt and upt
+//       EVENT_STATE_MISS_FLUSH_UPT          , // in commit stage, detect a miss  , context is stop and ufpt is flush, update RAS
+//       EVENT_STATE_EVENT_FLUSH_UFPT        , // in commit stage, detect an event, continue to execute but flush ufpt
+//       EVENT_STATE_EVENT_FLUSH_UFPT_AND_UPT, // in commit stage, detect an event, stop context and flush ufpt and upt
+//       EVENT_STATE_EVENT_FLUSH_UPT         , // in commit stage, detect an event, context is stop and ufpt is flush, update RAS
+//       EVENT_STATE_UPDATE_CONTEXT          , // prediction unit is update, send signal to context manager
+//       EVENT_STATE_WAIT_END_EVENT            // prediction unit is ok, wait the end of event (send by Context State)
+//     } event_state_t;
+
+  typedef enum
+    {
+      UFPT_EVENT_STATE_OK                     , // Can predict
+      UFPT_EVENT_STATE_KO_FLUSH                 // Can't predict, flush ufpt
+    } ufpt_event_state_t;
+
+  typedef enum
+    {
+      UPT_EVENT_STATE_OK                              , // Can predict
+      UPT_EVENT_STATE_KO_MISS_WAIT_UFPT               , // in decod  stage, detect a miss  , continue to execute but flush ufpt
+      UPT_EVENT_STATE_KO_MISS_FLUSH_UPT               , // in commit stage, detect a miss  , context is stop and ufpt is flush, update RAS
+      UPT_EVENT_STATE_KO_EVENT_WAIT_UFPT              , // in commit stage, detect an event, continue to execute but flush ufpt
+      UPT_EVENT_STATE_KO_EVENT_FLUSH_UPT              , // in commit stage, detect an event, context is stop and ufpt is flush, update RAS
+      UPT_EVENT_STATE_KO_DECODE_UPDATE_CONTEXT        , // prediction unit is update, send signal to context manager
+      UPT_EVENT_STATE_KO_DECODE_WAIT_END_EVENT        , // prediction unit is ok, wait the end of event (send by Context State)
+      UPT_EVENT_STATE_KO_COMMIT_UPDATE_CONTEXT        , // prediction unit is update, send signal to context manager
+      UPT_EVENT_STATE_KO_COMMIT_WAIT_END_EVENT          // prediction unit is ok, wait the end of event (send by Context State)
+    } upt_event_state_t;
 
   typedef enum
@@ -138,22 +157,20 @@
   };
 
-
-  
-  template<> inline std::string toString<morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::event_state_t>(const morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::event_state_t& x)
-  {
-    switch (x)
-      {
-      case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::EVENT_STATE_OK                      : return "ok"                      ; break;
-      case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::EVENT_STATE_MISS_FLUSH_UFPT         : return "miss_flush_ufpt"         ; break;
-      case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::EVENT_STATE_MISS_FLUSH_UFPT_AND_UPT : return "miss_flush_ufpt_and_upt" ; break;
-      case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::EVENT_STATE_MISS_FLUSH_UPT          : return "miss_flush_upt"          ; break;
-      case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::EVENT_STATE_EVENT_FLUSH_UPT         : return "event_flush_upt"         ; break;
-      case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::EVENT_STATE_EVENT_FLUSH_UFPT        : return "event_flush_ufpt"        ; break;
-      case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::EVENT_STATE_EVENT_FLUSH_UFPT_AND_UPT: return "event_flush_ufpt_and_upt"; break;
-      case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::EVENT_STATE_UPDATE_CONTEXT          : return "update_context"          ; break;
-      case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::EVENT_STATE_WAIT_END_EVENT          : return "wait_end_event"          ; break;
-      default    : return ""; break; 
-      }
-  };
+//   template<> inline std::string toString<morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::event_state_t>(const morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::event_state_t& x)
+//   {
+//     switch (x)
+//       {
+//       case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::EVENT_STATE_OK                      : return "ok"                      ; break;
+//       case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::EVENT_STATE_MISS_FLUSH_UFPT         : return "miss_flush_ufpt"         ; break;
+//       case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::EVENT_STATE_MISS_FLUSH_UFPT_AND_UPT : return "miss_flush_ufpt_and_upt" ; break;
+//       case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::EVENT_STATE_MISS_FLUSH_UPT          : return "miss_flush_upt"          ; break;
+//       case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::EVENT_STATE_EVENT_FLUSH_UPT         : return "event_flush_upt"         ; break;
+//       case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::EVENT_STATE_EVENT_FLUSH_UFPT        : return "event_flush_ufpt"        ; break;
+//       case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::EVENT_STATE_EVENT_FLUSH_UFPT_AND_UPT: return "event_flush_ufpt_and_upt"; break;
+//       case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::EVENT_STATE_UPDATE_CONTEXT          : return "update_context"          ; break;
+//       case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::EVENT_STATE_WAIT_END_EVENT          : return "wait_end_event"          ; break;
+//       default    : return ""; break; 
+//       }
+//   };
 
   template<> inline std::string toString<morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::ufpt_state_t>(const morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::ufpt_state_t& x)
@@ -186,4 +203,31 @@
   };
 
+  template<> inline std::string toString<morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::ufpt_event_state_t>(const morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::ufpt_event_state_t& x)
+  {
+    switch (x)
+      {
+      case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::UFPT_EVENT_STATE_OK       : return "UFPT_EVENT_STATE_OK"       ; break;
+      case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::UFPT_EVENT_STATE_KO_FLUSH : return "UFPT_EVENT_STATE_KO_FLUSH" ; break;
+      default    : return ""; break; 
+      }
+  };
+
+  template<> inline std::string toString<morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::upt_event_state_t>(const morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::upt_event_state_t& x)
+  {
+    switch (x)
+      {
+      case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::UPT_EVENT_STATE_OK                        : return "UPT_EVENT_STATE_OK"                        ; break;
+      case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::UPT_EVENT_STATE_KO_MISS_WAIT_UFPT         : return "UPT_EVENT_STATE_KO_MISS_WAIT_UFPT"         ; break;
+      case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::UPT_EVENT_STATE_KO_MISS_FLUSH_UPT         : return "UPT_EVENT_STATE_KO_MISS_FLUSH_UPT"         ; break;
+      case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::UPT_EVENT_STATE_KO_EVENT_WAIT_UFPT        : return "UPT_EVENT_STATE_KO_EVENT_WAIT_UFPT"        ; break;
+      case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::UPT_EVENT_STATE_KO_EVENT_FLUSH_UPT        : return "UPT_EVENT_STATE_KO_EVENT_FLUSH_UPT"        ; break;
+      case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::UPT_EVENT_STATE_KO_DECODE_UPDATE_CONTEXT  : return "UPT_EVENT_STATE_KO_DECODE_UPDATE_CONTEXT"  ; break;
+      case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::UPT_EVENT_STATE_KO_DECODE_WAIT_END_EVENT  : return "UPT_EVENT_STATE_KO_DECODE_WAIT_END_EVENT"  ; break;
+      case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::UPT_EVENT_STATE_KO_COMMIT_UPDATE_CONTEXT  : return "UPT_EVENT_STATE_KO_COMMIT_UPDATE_CONTEXT"  ; break;
+      case morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::update_prediction_table::UPT_EVENT_STATE_KO_COMMIT_WAIT_END_EVENT  : return "UPT_EVENT_STATE_KO_COMMIT_WAIT_END_EVENT"  ; break;
+      default    : return ""; break; 
+      }
+  };
+
 }; // end namespace morpheo              
 
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/include/Update_Prediction_Table.h
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/include/Update_Prediction_Table.h	(revision 120)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/include/Update_Prediction_Table.h	(revision 122)
@@ -184,10 +184,13 @@
   private   : bool                          * reg_IS_ACCURATE                    ; //[nb_context]
 
-  private   : bool                          * reg_EVENT_VAL                      ; //[nb_context]
+  private   : ufpt_event_state_t            * reg_UFPT_EVENT_STATE               ; //[nb_context]
+  private   : upt_event_state_t             * reg_UPT_EVENT_STATE                ; //[nb_context]
+
+//   private   : bool                          * reg_EVENT_VAL                      ; //[nb_context]
   private   : uint32_t                      * reg_EVENT_UPT_PTR                  ; //[nb_context]
   private   : bool                          * reg_EVENT_UPT_FULL                 ; //[nb_context]
 
-  private   : event_state_t                 * reg_EVENT_STATE                    ; //[nb_context]
-  private   : bool                          * reg_EVENT_IS_BRANCH                ; //[nb_context]
+//   private   : event_state_t                 * reg_EVENT_STATE                    ; //[nb_context]
+//   private   : bool                          * reg_EVENT_IS_BRANCH                ; //[nb_context]
   private   : Tdepth_t                      * reg_EVENT_DEPTH                    ; //[nb_context]
   private   : Taddress_t                    * reg_EVENT_ADDRESS_SRC              ; //[nb_context] // Address branch
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Parameters.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Parameters.cpp	(revision 120)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Parameters.cpp	(revision 122)
@@ -34,6 +34,8 @@
                           uint32_t * translate_num_context_to_num_thread ,//[nb_context]
                           bool       is_toplevel):
-    _accurate_block_predict (false),
-    _accurate_block_decod   (false)
+    _always_accurate_predict (false),
+    _always_accurate_decod   (false),
+    _can_accurate_predict    (true ),
+    _can_accurate_decod      (true )
   {
     log_printf(FUNC,Update_Prediction_Table,FUNCTION,"Begin");
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_allocation.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_allocation.cpp	(revision 120)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_allocation.cpp	(revision 122)
@@ -224,10 +224,13 @@
     ALLOC1(reg_UPT_EMPTY                    ,bool         ,_param->_nb_context);
 
-    ALLOC1(reg_EVENT_VAL                    ,bool         ,_param->_nb_context);
+    ALLOC1(reg_UFPT_EVENT_STATE             ,ufpt_event_state_t,_param->_nb_context);
+    ALLOC1(reg_UPT_EVENT_STATE              ,upt_event_state_t ,_param->_nb_context);
+
+//     ALLOC1(reg_EVENT_VAL                    ,bool         ,_param->_nb_context);
     ALLOC1(reg_EVENT_UPT_PTR                ,uint32_t     ,_param->_nb_context);
     ALLOC1(reg_EVENT_UPT_FULL               ,bool         ,_param->_nb_context);
 
-    ALLOC1(reg_EVENT_STATE                  ,event_state_t ,_param->_nb_context);
-    ALLOC1(reg_EVENT_IS_BRANCH              ,bool          ,_param->_nb_context);
+//     ALLOC1(reg_EVENT_STATE                  ,event_state_t ,_param->_nb_context);
+//     ALLOC1(reg_EVENT_IS_BRANCH              ,bool          ,_param->_nb_context);
     ALLOC1(reg_EVENT_DEPTH                  ,Tdepth_t      ,_param->_nb_context);
     ALLOC1(reg_EVENT_ADDRESS_SRC            ,Taddress_t    ,_param->_nb_context);
@@ -257,5 +260,5 @@
                                                    false,
                                                    log_with_pid,
-                                                   false);
+                                                   true);
           
           branchement_log_file [i] .open(filename.c_str() ,std::ios::out | std::ios::trunc);
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_deallocation.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_deallocation.cpp	(revision 120)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_deallocation.cpp	(revision 122)
@@ -151,10 +151,13 @@
         DELETE1(reg_UPT_EMPTY                    ,_param->_nb_context);
         
-        DELETE1(reg_EVENT_VAL                    ,_param->_nb_context);
+        DELETE1(reg_UFPT_EVENT_STATE             ,_param->_nb_context);
+        DELETE1(reg_UPT_EVENT_STATE              ,_param->_nb_context);
+
+//         DELETE1(reg_EVENT_VAL                    ,_param->_nb_context);
         DELETE1(reg_EVENT_UPT_PTR                ,_param->_nb_context);
         DELETE1(reg_EVENT_UPT_FULL               ,_param->_nb_context);
 
-        DELETE1(reg_EVENT_STATE                  ,_param->_nb_context);
-        DELETE1(reg_EVENT_IS_BRANCH              ,_param->_nb_context);
+//         DELETE1(reg_EVENT_STATE                  ,_param->_nb_context);
+//         DELETE1(reg_EVENT_IS_BRANCH              ,_param->_nb_context);
         DELETE1(reg_EVENT_DEPTH                  ,_param->_nb_context);
         DELETE1(reg_EVENT_ADDRESS_SRC            ,_param->_nb_context);
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_genMealy_branch_complete.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_genMealy_branch_complete.cpp	(revision 120)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_genMealy_branch_complete.cpp	(revision 122)
@@ -33,13 +33,14 @@
         log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * BRANCH_COMPLETE [%d]",i);
 
-	Tcontext_t          context   = (_param->_have_port_context_id)?PORT_READ(in_BRANCH_COMPLETE_CONTEXT_ID [i]):0;
-	Tdepth_t            depth     = (_param->_have_port_depth     )?PORT_READ(in_BRANCH_COMPLETE_DEPTH      [i]):0;
-	Tcontrol_t          miss      = false;
-	Tcontrol_t          take      = reg_UPDATE_PREDICTION_TABLE [context][depth]._last_take   ;
-	Taddress_t          addr_dest = reg_UPDATE_PREDICTION_TABLE [context][depth]._address_dest;
-	Tbranch_condition_t condition = reg_UPDATE_PREDICTION_TABLE [context][depth]._condition   ;
+        // Read information
+	Tcontext_t          context     = (_param->_have_port_context_id)?PORT_READ(in_BRANCH_COMPLETE_CONTEXT_ID [i]):0;
+	Tdepth_t            depth       = (_param->_have_port_depth     )?PORT_READ(in_BRANCH_COMPLETE_DEPTH      [i]):0;
+	Tcontrol_t          miss        = false; // init
+	Tcontrol_t          take        = reg_UPDATE_PREDICTION_TABLE [context][depth]._last_take   ;
+	Taddress_t          addr_dest   = reg_UPDATE_PREDICTION_TABLE [context][depth]._address_dest;
+	Tbranch_condition_t condition   = reg_UPDATE_PREDICTION_TABLE [context][depth]._condition   ;
 
         Tcontrol_t          no_sequence = PORT_READ(in_BRANCH_COMPLETE_NO_SEQUENCE [i]);
-        Taddress_t          addr_good = PORT_READ(in_BRANCH_COMPLETE_ADDRESS [i]);
+        Taddress_t          addr_good   = PORT_READ(in_BRANCH_COMPLETE_ADDRESS [i]);
 
         log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * context        : %d",context);
@@ -54,4 +55,5 @@
         log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * address_dest : %.8x",addr_dest);
 
+        // Test branch condition
 	switch (condition)
 	  {
@@ -80,6 +82,4 @@
               log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * BRANCH_CONDITION_FLAG");
 
-//               Tcontrol_t take_good = not flag; // flag set = not take
-//               Tcontrol_t take_good = flag; // flag set = take
               Tcontrol_t take_good = no_sequence;
 
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_genMealy_decod.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_genMealy_decod.cpp	(revision 120)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_genMealy_decod.cpp	(revision 122)
@@ -28,37 +28,39 @@
     if (PORT_READ(in_NRESET) != 0)
       {
+    // for each decod instruction
     for (uint32_t i=0; i<_param->_nb_inst_decod; i++)
       {
         log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * DECOD [%d]",i);
 
-        Tcontext_t    context     = (_param->_have_port_context_id)?PORT_READ(in_DECOD_CONTEXT_ID [i]):0;
-        bool          is_accurate = _param->_accurate_block_decod or reg_IS_ACCURATE [context];
-        event_state_t event_state = reg_EVENT_STATE [context];
-        uint32_t      ptr_write   = reg_UPT_TOP     [context];
-        // can continue if next slot is empty
-        Tcontrol_t    can_continue= ((reg_UPDATE_PREDICTION_TABLE [context][(reg_UPT_TOP [context]+1)%_param->_size_upt_queue[context]]._state == UPDATE_PREDICTION_STATE_EMPTY) and 
-                                     (reg_EVENT_STATE [context] == EVENT_STATE_OK));
+        // Read information
+        Tcontext_t         context          = (_param->_have_port_context_id)?PORT_READ(in_DECOD_CONTEXT_ID [i]):0;
+        bool               is_accurate      = (_param->_always_accurate_decod or 
+                                              (_param->_can_accurate_decod and reg_IS_ACCURATE [context]));
+        upt_event_state_t  upt_event_state  = reg_UPT_EVENT_STATE  [context];
+        ufpt_event_state_t ufpt_event_state = reg_UFPT_EVENT_STATE [context];
+        uint32_t           ptr_write        = reg_UPT_TOP     [context]; // One branch per context per cycle
+        uint32_t           ptr_write_next   = (ptr_write+1)%_param->_size_upt_queue[context];
+        // Decod can continue until the next branch if next slot is empty, and no event
+        Tcontrol_t         can_continue     = (reg_UPDATE_PREDICTION_TABLE [context][ptr_write_next]._state == UPDATE_PREDICTION_STATE_EMPTY);
 
-        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * context     : %d",context    );
-        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * is_accurate : %d",is_accurate);
-        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * event_state : %s",toString(event_state).c_str());
-        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * ptr_write   : %d",ptr_write  );
-        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * upt_state   : %s",toString(reg_UPDATE_PREDICTION_TABLE [context][ptr_write]._state).c_str());
-        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * can_continue: %d",can_continue);
+        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * context          : %d",context);
+        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * is_accurate      : %d",is_accurate);
+        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * ufpt_event_state : %s",toString(ufpt_event_state).c_str());
+        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * upt_event_state  : %s",toString(upt_event_state).c_str());
+        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * ptr_write        : %d - %d",ptr_write,ptr_write_next);
+        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * upt_state        : %s",toString(reg_UPDATE_PREDICTION_TABLE [context][ptr_write]._state).c_str());
+        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * can_continue     : %d",can_continue);
 
-        // ack :
+        // can decod (ack) if :
         //   * in all case (miss or hit), need empty slot
+        //   * not previous event (state = ok)
         //   * is_accurate
-        //   * event_state : don't update upt
         internal_DECOD_ACK           [i] = ((reg_UPDATE_PREDICTION_TABLE [context][ptr_write]._state == UPDATE_PREDICTION_STATE_EMPTY) and
-                                            is_accurate and
-//                                             (
-                                             (event_state == EVENT_STATE_OK)//  or
-//                                              (event_state == EVENT_STATE_MISS_FLUSH_UFPT    ) or
-//                                              (event_state == EVENT_STATE_UPDATE_CONTEXT))
-                                            );
+                                            (ufpt_event_state == UFPT_EVENT_STATE_OK) and
+                                            (upt_event_state  == UPT_EVENT_STATE_OK ) and
+                                            is_accurate);
         internal_DECOD_UPT_PTR_WRITE [i] = ptr_write;
 
-        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * ack         : %d",internal_DECOD_ACK [i]);
+        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * ack              : %d",internal_DECOD_ACK [i]);
 
 	PORT_WRITE(out_DECOD_ACK          [i], internal_DECOD_ACK [i]);
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_genMealy_predict.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_genMealy_predict.cpp	(revision 120)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_genMealy_predict.cpp	(revision 122)
@@ -27,9 +27,10 @@
     if (PORT_READ(in_NRESET) != 0)
       {
-
+    // For each prediction
     for (uint32_t i=0; i<_param->_nb_inst_predict; i++)
       {
+        // Read information
 	Tcontext_t context = (_param->_have_port_context_id)?PORT_READ(in_PREDICT_CONTEXT_ID [i]):0;
-	uint32_t   top     = reg_UFPT_TOP[context];
+	uint32_t   top     = reg_UFPT_TOP[context]; // not multi branch prediction
 
 	log_printf(TRACE,Update_Prediction_Table,FUNCTION,"PREDICT [%d] (genMealy)",i);
@@ -40,23 +41,23 @@
 // 	log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * need update : %d",reg_NB_ELT_NEED_UPDATE [context]);
 
+        bool is_accurate = (_param->_always_accurate_predict or 
+                            (_param->_can_accurate_predict and reg_IS_ACCURATE [context]));
+
+        // Ack if :
+        //  * no previous event (ufpt and upt is ok)
+        //  * top slot is empty
+        //  * is_accurate
+	internal_PREDICT_ACK [i] = ((reg_UFPT_EVENT_STATE [context] == UFPT_EVENT_STATE_OK) and
+                                    (reg_UPT_EVENT_STATE  [context] == UPT_EVENT_STATE_OK ) and
+                                    (reg_UPDATE_FETCH_PREDICTION_TABLE [context][top]._state == UPDATE_FETCH_PREDICTION_STATE_EMPTY) and
+                                    is_accurate);
+
         internal_PREDICT_UPDATE_PREDICTION_ID [i] = top;
 
+ 	log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * ACK         : %d",internal_PREDICT_ACK [i]);
+
+	PORT_WRITE(out_PREDICT_ACK                  [i], internal_PREDICT_ACK                  [i]);
         if (_param->_have_port_depth)
         PORT_WRITE(out_PREDICT_UPDATE_PREDICTION_ID [i], internal_PREDICT_UPDATE_PREDICTION_ID [i]);
-
-        bool is_accurate = _param->_accurate_block_predict or reg_IS_ACCURATE[context];
-
-        // Ack if :
-        //  * slot is empty
-        //  * no previous miss
-        //  * is_accurate
-	internal_PREDICT_ACK [i] = ((reg_UPDATE_FETCH_PREDICTION_TABLE [context][top]._state == UPDATE_FETCH_PREDICTION_STATE_EMPTY) and
-   				    (reg_EVENT_STATE [context] == EVENT_STATE_OK) and
-//                                  (reg_UFPT_NB_UPDATE [context] == 0) and
-                                    is_accurate);
-
-
- 	log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * ACK         : %d",internal_PREDICT_ACK [i]);
-	PORT_WRITE(out_PREDICT_ACK [i], internal_PREDICT_ACK [i]);
       }
 
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_genMoore.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_genMoore.cpp	(revision 120)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_genMoore.cpp	(revision 122)
@@ -40,17 +40,20 @@
         //     include ]DEPTH_MIN:DEPTH_MAX] -> speculative
 
-        PORT_WRITE(out_DEPTH_VAL     [i],((reg_UPDATE_PREDICTION_TABLE [i][reg_UPT_TOP [i]]._state == UPDATE_PREDICTION_STATE_EMPTY) 
-                                          and (reg_EVENT_STATE [i] == EVENT_STATE_OK)
+        uint32_t bottom = reg_UPT_BOTTOM [i];
+        uint32_t top    = reg_UPT_TOP    [i];
+        bool     empty  = reg_UPT_EMPTY [i];
+
+        // Depth_val is set when state is ok and the UPT[top] is empty
+        PORT_WRITE(out_DEPTH_VAL     [i],((reg_UPDATE_PREDICTION_TABLE [i][top]._state == UPDATE_PREDICTION_STATE_EMPTY) 
+                                          and (reg_UFPT_EVENT_STATE [i] == UFPT_EVENT_STATE_OK)
+                                          and (reg_UPT_EVENT_STATE  [i] == UPT_EVENT_STATE_OK)
                                           ));
 	if (_param->_have_port_depth)
           {
-        PORT_WRITE(out_DEPTH_CURRENT [i], reg_UPT_TOP    [i]);
-        PORT_WRITE(out_DEPTH_MIN     [i], reg_UPT_BOTTOM [i]);
-	PORT_WRITE(out_DEPTH_MAX     [i], reg_UPT_TOP    [i]);
-          }
-	PORT_WRITE(out_DEPTH_FULL    [i], not reg_UPT_EMPTY [i] and (reg_UPT_TOP [i] == reg_UPT_BOTTOM [i]));
-
-//         bool empty = reg_UPT_EMPTY [i];
-// 	PORT_WRITE(out_DEPTH_MAX     [i], ((empty)?reg_UPT_BOTTOM [i]:((reg_UPT_TOP [i]==0)?(_param->_size_upt_queue[i]-1):(reg_UPT_TOP [i]-1))));
+        PORT_WRITE(out_DEPTH_CURRENT [i], top);
+        PORT_WRITE(out_DEPTH_MIN     [i], bottom);
+	PORT_WRITE(out_DEPTH_MAX     [i], top);
+          }
+	PORT_WRITE(out_DEPTH_FULL    [i], not empty and (top == bottom));
       }
 
@@ -58,65 +61,62 @@
     // =====[ UPDATE ]====================================================
     // ===================================================================
-
-    bool     retire_ras_from_ufpt [_param->_nb_context]; // event ufpt -> restore RAS, else update upt
-    bool     retire_ras_from_upt  [_param->_nb_context]; // event upt  -> restore RAS, else restore others structure
-//  bool     have_event           [_param->_nb_context];
-    bool     ufpt_update          [_param->_nb_context];
-    bool     upt_update           [_param->_nb_context];
-    Tdepth_t tab_ufpt_depth       [_param->_nb_context];
-    Tdepth_t tab_upt_depth        [_param->_nb_context];
-
-    for (uint32_t i=0; i<_param->_nb_context; i++)
-      {
-        event_state_t event_state = reg_EVENT_STATE [i];
-
-        retire_ras_from_ufpt [i] = ((event_state == EVENT_STATE_MISS_FLUSH_UFPT         ) or
-                                    (event_state == EVENT_STATE_MISS_FLUSH_UFPT_AND_UPT ) or
-                                    (event_state == EVENT_STATE_EVENT_FLUSH_UFPT        ) or
-                                    (event_state == EVENT_STATE_EVENT_FLUSH_UFPT_AND_UPT));
-        retire_ras_from_upt  [i] = ((event_state == EVENT_STATE_MISS_FLUSH_UPT) or
-                                    (event_state == EVENT_STATE_EVENT_FLUSH_UPT));
-
-//         have_event           [i] = (event_state == EVENT_STATE_EVENT_FLUSH_UPT);
-
-        ufpt_update          [i] = true;
-        upt_update           [i] = true;
-        tab_ufpt_depth       [i] = reg_UFPT_UPDATE [i];
-        tab_upt_depth        [i] = reg_UPT_UPDATE  [i];
-      }
+    {
+      bool     flush_ufpt      [_param->_nb_context]; // event ufpt -> restore RAS, else update upt
+      bool     flush_upt       [_param->_nb_context]; // event upt  -> restore RAS, else restore others structure
+      bool     ufpt_can_update [_param->_nb_context];
+      bool     upt_can_update  [_param->_nb_context];
+      Tdepth_t tab_ufpt_depth  [_param->_nb_context];
+      Tdepth_t tab_upt_depth   [_param->_nb_context];
+      
+      // Init 
+      for (uint32_t i=0; i<_param->_nb_context; i++)
+        {
+          ufpt_event_state_t ufpt_event_state = reg_UFPT_EVENT_STATE [i];
+          upt_event_state_t  upt_event_state  = reg_UPT_EVENT_STATE [i];
+          
+          flush_ufpt      [i] = (ufpt_event_state == UFPT_EVENT_STATE_KO_FLUSH);
+          flush_upt       [i] = ((upt_event_state == UPT_EVENT_STATE_KO_MISS_FLUSH_UPT) or
+                                 (upt_event_state == UPT_EVENT_STATE_KO_EVENT_FLUSH_UPT));
+          ufpt_can_update [i] = true;
+          upt_can_update  [i] = true;
+          tab_ufpt_depth  [i] = reg_UFPT_UPDATE [i];
+          tab_upt_depth   [i] = reg_UPT_UPDATE  [i];
+        }
 
     for (uint32_t i=0; i<_param->_nb_inst_update; i++)
       {
-	Tcontext_t          context     = (reg_UPDATE_PRIORITY+i)%_param->_nb_context;
+	Tcontext_t          context              = (reg_UPDATE_PRIORITY+i)%_param->_nb_context;
 
 	log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * UPDATE [%d] (genMoore)",i);
 	log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * context         : %d",context);
-	log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * event_state     : %s",toString(reg_EVENT_STATE [context]).c_str());
+	log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * flush_ufpt      : %d",flush_ufpt[context]);
+	log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * flush_upt       : %d",flush_upt [context]);
 
         Tcontrol_t          val                  = false;
         Tcontrol_t          val_without_ack      = false;
-        Tcontrol_t          miss_prediction      ;
-        Tcontrol_t          direction_good       ;
-        Tcontrol_t          prediction_ifetch    ;
-        Tcontrol_t          btb_val              ;
-        Taddress_t          btb_address_src      ;
-        Taddress_t          btb_address_dest     ;
-        Tbranch_condition_t btb_condition        ;
-        Tcontrol_t          dir_val              ;
-        Thistory_t          dir_history          ;
-        Tcontrol_t          ras_val              ;
-        Tcontrol_t          ras_flush            ;
-        Tcontrol_t          ras_push             ;
-        Taddress_t          ras_address          ;
-        Tptr_t              ras_index            ;
+        Tcontrol_t          miss_prediction      = 0; // not necessary init
+        Tcontrol_t          direction_good       = 0; // not necessary init
+        Tcontrol_t          prediction_ifetch    = 0; // not necessary init
+        Tcontrol_t          btb_val              = 0; // not necessary init
+        Taddress_t          btb_address_src      = 0; // not necessary init
+        Taddress_t          btb_address_dest     = 0; // not necessary init
+        Tbranch_condition_t btb_condition        = 0; // not necessary init
+        Tcontrol_t          dir_val              = 0; // not necessary init
+        Thistory_t          dir_history          = 0; // not necessary init
+        Tcontrol_t          ras_val              = 0; // not necessary init
+        Tcontrol_t          ras_flush            = 0; // not necessary init
+        Tcontrol_t          ras_push             = 0; // not necessary init
+        Taddress_t          ras_address          = 0; // not necessary init
+        Tptr_t              ras_index            = 0; // not necessary init
 
         // Test if update fetch prediction table need update port
-        if (retire_ras_from_ufpt [context])
-          {
-            if (ufpt_update [context])
+        if (flush_ufpt [context])
+          {
+            if (ufpt_can_update [context])
               {
                 // Update Fetch Prediction Table
-                // An update of ufpt is to previous miss. Just restore Return Address Stack
-                
+                // An update of ufpt is to previous miss. Just restore Prediction_unit
+                
+                // Read information
                 Tdepth_t            depth     = tab_ufpt_depth[context];
                 ufpt_state_t        state     = reg_UPDATE_FETCH_PREDICTION_TABLE [context][depth]._state; 
@@ -131,5 +131,5 @@
 //              val_without_ack       = not update_ras(condition);
 
-                miss_prediction       = 1;
+                miss_prediction       = 1; // need update, also previous miss
 //              direction_good        = ;
                 prediction_ifetch     = 1;
@@ -138,9 +138,8 @@
 //              btb_address_dest      = reg_UPDATE_PREDICTION_TABLE [context][depth]._address_dest;
 //              btb_condition         = condition;
-                dir_val               = update_ras(condition);
+                dir_val               = update_dir(condition);
                 dir_history           = reg_UPDATE_PREDICTION_TABLE [context][depth]._history;
-                // repop/ repush data -> don't corrupt ras
-                ras_val               = update_ras(condition); 
-                ras_flush             = 0;
+                ras_val               = update_ras(condition); // repop/ repush data -> don't corrupt ras
+                ras_flush             = 0; // no ras corruption
                 ras_push              = push_ras(condition);
                 ras_address           = reg_UPDATE_FETCH_PREDICTION_TABLE [context][depth]._address_ras;
@@ -153,15 +152,17 @@
                 // Warning : don't update same entry
                 if (depth == reg_UFPT_BOTTOM[context])
-                  ufpt_update [context] = false;
-                
-                tab_ufpt_depth[context] = ((depth==0)?_param->_size_ufpt_queue[context]:depth)-1;
+                  ufpt_can_update [context] = false;
+                else
+                  // update pointer
+                  tab_ufpt_depth[context] = ((depth==0)?_param->_size_ufpt_queue[context]:depth)-1;
               }
           }
         else
           {
-            if (upt_update [context])
+            if (upt_can_update [context])
               {
                 // Update Prediction Table
-                
+
+                // Read information
                 Tdepth_t            depth     = tab_upt_depth[context];
                 upt_state_t         state     = reg_UPDATE_PREDICTION_TABLE [context][depth]._state; 
@@ -174,26 +175,20 @@
                 log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * condition       : %s",toString(condition).c_str());
               
-                Tcontrol_t          state_is_ok_ko           = ((state == UPDATE_PREDICTION_STATE_OK   ) or
-                                                                (state == UPDATE_PREDICTION_STATE_KO   ));
-//                 Tcontrol_t          state_is_event           = ((state == UPDATE_PREDICTION_STATE_KO   ) or
-//                                                                 (state == UPDATE_PREDICTION_STATE_EVENT)//  or
-//                                                                 ((have_event[context])?(state == UPDATE_PREDICTION_STATE_OK):false)
-//                                                                 );
-                
-//                 Tcontrol_t          state_is_event_update    = state_is_event and     need_update(condition);
-//                 Tcontrol_t          state_is_event_no_update = state_is_event and not need_update(condition);
-
-                if (retire_ras_from_upt [context])
+                // is the valid branch (valid branch hit, or valid branch miss)
+                Tcontrol_t          state_is_ok_ko = ((state == UPDATE_PREDICTION_STATE_OK   ) or
+                                                      (state == UPDATE_PREDICTION_STATE_KO   ));
+
+                if (not flush_upt [context])
                   {
-//                 val                   = state_is_event_update;
-//                 val_without_ack       = state_is_event_no_update;
-                val                   = ((state == UPDATE_PREDICTION_STATE_KO   ) or 
-                                         ((state == UPDATE_PREDICTION_STATE_EVENT) and need_update(condition)));
-                val_without_ack       = ((state == UPDATE_PREDICTION_STATE_EVENT) and not need_update(condition));
+                    // no event, just update predictor
+                val                   = (state == UPDATE_PREDICTION_STATE_OK);
+                val_without_ack       = false;
                   }
                 else
                   {
-                val                   = (state == UPDATE_PREDICTION_STATE_OK);
-                val_without_ack       = false;
+                    // event, restore event (if need update)
+                val                   = ( (state == UPDATE_PREDICTION_STATE_KO   ) or 
+                                         ((state == UPDATE_PREDICTION_STATE_EVENT) and     need_update(condition)));
+                val_without_ack       = ( (state == UPDATE_PREDICTION_STATE_EVENT) and not need_update(condition));
                   }                  
 
@@ -205,9 +200,8 @@
                 btb_address_dest      = reg_UPDATE_PREDICTION_TABLE [context][depth]._address_dest;
                 btb_condition         = condition;
-                dir_val               = // state_is_ok_ko and 
-                                        update_dir(condition); // if not ifetch, then static prediction
+                dir_val               = ifetch and update_dir(condition); // if not ifetch, then static prediction -> history is wrong
                 dir_history           = reg_UPDATE_PREDICTION_TABLE [context][depth]._history     ;
                 ras_val               = update_ras(condition); // repop/ repush data -> don't corrupt ras
-                ras_flush             = (state == UPDATE_PREDICTION_STATE_KO); // miss prediction, RAS is corrupted
+                ras_flush             = (state == UPDATE_PREDICTION_STATE_KO); // miss prediction on RAS -> RAS is corrupted
                 ras_push              = push_ras(condition);
                 // If corrupt, RAS must be flushed.
@@ -218,20 +212,23 @@
                 internal_UPDATE_FROM_UFPT [i] = false;
                 internal_UPDATE_DEPTH     [i] = depth;
-                internal_UPDATE_RAS       [i] = retire_ras_from_upt [context];
+                internal_UPDATE_RAS       [i] = flush_upt [context];
 
                 // Warning : don't update same entry
-                if (retire_ras_from_upt [context])
+                if (flush_upt [context])
                   {
-                    // Restore RAS. 
+                    // Stop condition
                     if ((depth == reg_UPT_BOTTOM[context]) or not (val or val_without_ack))
-                      upt_update [context] = false;
+                      upt_can_update [context] = false;
                     
+                    // flush -> ptr is decrease 
                     tab_upt_depth[context] = (depth==0)?(_param->_size_upt_queue[context]-1):(depth-1);
                   }
                 else
                   {
+                    // Stop condition
                     if ((depth == reg_UPT_TOP [context]) or not (val or val_without_ack))
-                      upt_update [context] = false;
+                      upt_can_update [context] = false;
                     
+                    // flush -> ptr is increase 
                     tab_upt_depth[context] = (depth+1)%_param->_size_upt_queue[context];
                   }
@@ -273,12 +270,16 @@
           }
       }
-    
+    }
+   
     // ===================================================================
     // =====[ BRANCH_EVENT ]==============================================
     // ===================================================================
+
+    // For all context ...
     for (uint32_t i=0; i<_param->_nb_context; i++)
       {
-	Tcontrol_t val = (reg_EVENT_STATE [i] == EVENT_STATE_UPDATE_CONTEXT);
-
+        // ... send an event if upt must be update the context
+	Tcontrol_t val = ((reg_UPT_EVENT_STATE [i] == UPT_EVENT_STATE_KO_DECODE_UPDATE_CONTEXT) or
+                          (reg_UPT_EVENT_STATE [i] == UPT_EVENT_STATE_KO_COMMIT_UPDATE_CONTEXT));
         PORT_WRITE(out_BRANCH_EVENT_VAL              [i],val);
         if (_param->_have_port_depth)
@@ -291,7 +292,9 @@
 	internal_BRANCH_EVENT_VAL [i] = val;
       }
+
       }
     else
       {
+        // Reset
         for (uint32_t i=0; i<_param->_nb_inst_update; i++)
           {
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 120)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/src/Update_Prediction_Table_transition.cpp	(revision 122)
@@ -51,7 +51,10 @@
             reg_IS_ACCURATE          [i] = true;
             
-            reg_EVENT_VAL            [i] = false;
-            reg_EVENT_STATE          [i] = EVENT_STATE_OK;
-            reg_EVENT_IS_BRANCH      [i] = true;
+            reg_UFPT_EVENT_STATE     [i] = UFPT_EVENT_STATE_OK;
+            reg_UPT_EVENT_STATE      [i] = UPT_EVENT_STATE_OK;
+
+//             reg_EVENT_VAL            [i] = false;
+//             reg_EVENT_STATE          [i] = EVENT_STATE_OK;
+//             reg_EVENT_IS_BRANCH      [i] = true;
           }
       }
@@ -74,101 +77,76 @@
 	for (uint32_t i=0; i<_param->_nb_context; i++)
 	  {
+            // -----------------------------
             // UPDATE_FETCH_PREDICTION_TABLE
+            // -----------------------------
             {
               uint32_t bottom = reg_UFPT_BOTTOM [i];
-              
-              // Test if state is end
-              if (reg_UPDATE_FETCH_PREDICTION_TABLE [i][bottom]._state == UPDATE_FETCH_PREDICTION_STATE_END)
+              bool     end    = (reg_UPDATE_FETCH_PREDICTION_TABLE [i][bottom]._state == UPDATE_FETCH_PREDICTION_STATE_END);
+
+              // Test if bottom slot can be remove
+              if (end)
                 {
                   log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UFPT [%d][%d]",i,bottom);
                   log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UFPT [%d][%d].state =  UPDATE_FETCH_PREDICTION_STATE_EMPTY",i,bottom);
-
+                  
                   // Free slot
                   reg_UPDATE_FETCH_PREDICTION_TABLE [i][bottom]._state = UPDATE_FETCH_PREDICTION_STATE_EMPTY;
                   // Update pointer
-                  reg_UFPT_BOTTOM [i] = (bottom+1)%_param->_size_ufpt_queue[i];
+                  bottom = (bottom+1)%_param->_size_ufpt_queue[i];
+
+                  reg_UFPT_BOTTOM [i] = bottom;
                 }
             }
 
+            // -----------------------
             // UPDATE_PREDICTION_TABLE
+            // -----------------------
             {
-              uint32_t      bottom      = reg_UPT_BOTTOM [i];
-              bool          end         = (reg_UPDATE_PREDICTION_TABLE [i][bottom]._state == UPDATE_PREDICTION_STATE_END);
-//               bool          end_ok      = (reg_UPDATE_PREDICTION_TABLE [i][bottom]._state == UPDATE_PREDICTION_STATE_END_OK);
-//               bool          end_ko      = (reg_UPDATE_PREDICTION_TABLE [i][bottom]._state == UPDATE_PREDICTION_STATE_END_KO);
-//               event_state_t event_state = reg_EVENT_STATE [i];
-
-              // Test if state is end
-//               if (end_ok or end_ko)
-              
-              log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * state is STATE_END      : %d",end);
-              log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * reg_UPT_BOTTOM (before) : %d",reg_UPT_BOTTOM         [i]);
-
-              if (end)
+              uint32_t bottom = reg_UPT_BOTTOM [i];
+
+//               if (reg_UPT_EVENT_STATE [i] == UPT_EVENT_STATE_OK)
                 {
+                  bool     end    = (reg_UPDATE_PREDICTION_TABLE [i][bottom]._state == UPDATE_PREDICTION_STATE_END);
+                  
+                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * reg_UPT_BOTTOM (before) : %d",bottom);
+                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * state is STATE_END      : %d",end);
+                  
+                  if (end)
+                    {
 #if defined(DEBUG) and defined(DEBUG_Update_Prediction_Table) and (DEBUG_Update_Prediction_Table == true)
-                  if (reg_UPDATE_PREDICTION_TABLE [i][bottom]._retire_ok)
-                    {
-                      uint32_t num_thread = _param->_translate_num_context_to_num_thread [i];
-                      branchement_log_file [num_thread] 
-                        << std::hex
-                        << "0x" << reg_UPDATE_PREDICTION_TABLE [i][bottom]._address_src       << " "
-                        << "0x" << reg_UPDATE_PREDICTION_TABLE [i][bottom]._address_dest      << " "
-                        << std::dec
-                        <<         reg_UPDATE_PREDICTION_TABLE [i][bottom]._good_take         << " - "
-                        << "["  << simulation_cycle() << "] " << " "
-                        <<         reg_UPDATE_PREDICTION_TABLE [i][bottom]._miss_prediction   << " "
-                        <<         reg_UPDATE_PREDICTION_TABLE [i][bottom]._ifetch_prediction << " "
-                        << "("  << (uint32_t)reg_UPDATE_PREDICTION_TABLE [i][bottom]._condition         << ")"
-                        << std::endl;
+                      if (reg_UPDATE_PREDICTION_TABLE [i][bottom]._retire_ok)
+                        {
+                          uint32_t num_thread = _param->_translate_num_context_to_num_thread [i];
+                          branchement_log_file [num_thread] 
+                            << std::hex
+                            << "0x" << reg_UPDATE_PREDICTION_TABLE [i][bottom]._address_src       << " "
+                            << "0x" << reg_UPDATE_PREDICTION_TABLE [i][bottom]._address_dest      << " "
+                            << std::dec
+                            <<         reg_UPDATE_PREDICTION_TABLE [i][bottom]._good_take         << " - "
+                            << "["  << simulation_cycle() << "] " << " "
+                            <<         reg_UPDATE_PREDICTION_TABLE [i][bottom]._miss_prediction   << " "
+                            <<         reg_UPDATE_PREDICTION_TABLE [i][bottom]._ifetch_prediction << " "
+                            << "("  << (uint32_t)reg_UPDATE_PREDICTION_TABLE [i][bottom]._condition         << ")"
+                            << std::endl;
+                        }
+#endif
+                      
+                      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UPT [%d][%d]",i,bottom);
+                      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UPT [%d][%d]._state =  UPDATE_PREDICTION_STATE_EMPTY",i,bottom);
+                      // Free slot
+                      reg_UPDATE_PREDICTION_TABLE [i][bottom]._state = UPDATE_PREDICTION_STATE_EMPTY;
+                      
+                      // Update pointer
+                      reg_UPT_BOTTOM [i] = (bottom+1)%_param->_size_upt_queue[i];
+                      
+                      // Free a slot, test if bottom pointer overtake the top pointer
+                      if (reg_UPT_BOTTOM [i] == reg_UPT_TOP [i])
+                        reg_UPT_EMPTY [i] = true; // free a slot
+                      
+                      reg_EVENT_UPT_FULL [i] = false;
                     }
-#endif
-                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UPT [%d][%d]",i,bottom);
-                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UPT [%d][%d]._state =  UPDATE_PREDICTION_STATE_EMPTY",i,bottom);
-                  // Free slot
-                  reg_UPDATE_PREDICTION_TABLE [i][bottom]._state = UPDATE_PREDICTION_STATE_EMPTY;
-
-                  // Update pointer
-                  reg_UPT_BOTTOM [i] = (bottom+1)%_param->_size_upt_queue[i];
                   
-                  if (reg_UPT_BOTTOM [i] == reg_UPT_TOP [i])
-                    reg_UPT_EMPTY [i] = true; // free a slot
-
-//                   if (bottom = reg_UPT_UPDATE [i])
-//                     reg_UPT_UPDATE [i] = reg_UPT_BOTTOM [i];
-                }// @@@
-              
-              log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * reg_UPT_BOTTOM (after ) : %d",reg_UPT_BOTTOM         [i]);
-              log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * reg_EVENT_VAL           : %d",reg_EVENT_VAL     [i]);
-              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_UPT_FULL      : %d",reg_EVENT_UPT_FULL[i]);
-
-              if (reg_EVENT_VAL [i] and (reg_EVENT_UPT_PTR [i] == bottom))
-                {
-                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * END EVENT");
-
-                  if ((reg_EVENT_IS_BRANCH [i] == false) and (reg_EVENT_UPT_FULL [i] == false))
-                    reg_EVENT_STATE[i] = EVENT_STATE_OK;
-
-                  if ((reg_EVENT_IS_BRANCH [i] == true) or (reg_EVENT_UPT_FULL [i] == false))
-                    {
-                  reg_EVENT_VAL       [i] = false;
-//                reg_EVENT_IS_BRANCH [i] = true;
-                  reg_UPT_TOP         [i] = reg_UPT_TOP_EVENT [i];
-                  reg_UPT_UPDATE      [i] = reg_UPT_TOP_EVENT [i];
-                  
-                  if (reg_UPT_BOTTOM [i] != reg_UPT_TOP [i])
-                    reg_UPT_EMPTY [i] = false;
-                    }
-
-                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * reg_UPT_TOP             : %d",reg_UPT_TOP            [i]);
-                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * reg_UPT_TOP_EVENT       : %d",reg_UPT_TOP_EVENT      [i]);
-                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * reg_UPT_UPDATE          : %d",reg_UPT_UPDATE         [i]);
-                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * reg_UPT_EMPTY           : %d",reg_UPT_EMPTY          [i]);
-                
+                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * reg_UPT_BOTTOM (after ) : %d",reg_UPT_BOTTOM         [i]);
                 }
-              
-              if (end)
-                reg_EVENT_UPT_FULL [i] = false;
             }
 	  }
@@ -186,12 +164,20 @@
 
 	for (uint32_t i=0; i<_param->_nb_inst_predict; i++)
+          // Test if have a transaction
 	  if (PORT_READ(in_PREDICT_VAL[i]) and internal_PREDICT_ACK [i])
 	    {
-	      Tcontext_t context = (_param->_have_port_context_id)?PORT_READ(in_PREDICT_CONTEXT_ID [i]):0;
-	      uint32_t   top     = internal_PREDICT_UPDATE_PREDICTION_ID [i];
+              // get transaction information
+	      Tcontext_t          context     = (_param->_have_port_context_id)?PORT_READ(in_PREDICT_CONTEXT_ID [i]):0;
+	      uint32_t            top         = internal_PREDICT_UPDATE_PREDICTION_ID [i];
+              Tbranch_condition_t condition   = PORT_READ(in_PREDICT_BTB_CONDITION [i]);
+              bool                is_accurate = (_param->_always_accurate_predict or 
+                                                 (_param->_can_accurate_predict and PORT_READ(in_PREDICT_BTB_IS_ACCURATE [i])));
+
 
 	      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * PREDICT[%d] - Accepted",i);
-	      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * context : %d",context);
-	      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * top     : %d",top);
+	      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * context     : %d",context);
+	      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * top         : %d",top);
+	      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * condition   : %d",condition);
+	      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * is_accurate : %d",is_accurate);
 
 #ifdef DEBUG_TEST
@@ -200,9 +186,10 @@
 #endif
 
+              // Ifetch unit have fetch an instruction bundle with a branchement.
+              // Insert in UFPT
               log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UFPT [%d][%d].state <- UPDATE_FETCH_PREDICTION_STATE_WAIT_DECOD (predict)",context,top);
  	      reg_UPDATE_FETCH_PREDICTION_TABLE [context][top]._state        = UPDATE_FETCH_PREDICTION_STATE_WAIT_DECOD;
 
-              Tbranch_condition_t condition   = PORT_READ(in_PREDICT_BTB_CONDITION [i]);
-              bool                is_accurate = _param->_accurate_block_predict or PORT_READ(in_PREDICT_BTB_IS_ACCURATE [i]);
+              // Write information
 	      reg_UPDATE_FETCH_PREDICTION_TABLE [context][top]._condition    = condition;
 	      reg_UPDATE_FETCH_PREDICTION_TABLE [context][top]._address_src  = PORT_READ(in_PREDICT_BTB_ADDRESS_SRC  [i]);
@@ -214,11 +201,12 @@
 	      reg_UPDATE_FETCH_PREDICTION_TABLE [context][top]._index_ras    = PORT_READ(in_PREDICT_RAS_INDEX        [i]);
 
+              // Update pointer
               reg_UFPT_TOP     [context] = (top+1)%_param->_size_ufpt_queue [context];
-//            reg_UFPT_UPDATE  [context] = reg_UFPT_TOP [context];
+
+              // Test if this branchement need update
               if (need_update(condition))
                 {
                   reg_UFPT_NB_NEED_UPDATE [context] ++;
                   log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_UFPT_NB_NEED_UPDATE (after) : %d",reg_UFPT_NB_NEED_UPDATE [context]);
-
                 }
 	    }
@@ -239,10 +227,13 @@
 
 	for (uint32_t i=0; i<_param->_nb_inst_decod; i++)
+          // Test if have a decod transaction
 	  if (PORT_READ(in_DECOD_VAL[i]) and internal_DECOD_ACK [i])
 	    {
+              // Read information
 	      Tcontext_t          context       = (_param->_have_port_context_id)?PORT_READ(in_DECOD_CONTEXT_ID [i]):0;
 	      Tcontrol_t          miss_ifetch   = PORT_READ(in_DECOD_MISS_IFETCH [i]);
 	      Tcontrol_t          miss_decod    = PORT_READ(in_DECOD_MISS_DECOD  [i]);
               uint32_t            upt_ptr_write = internal_DECOD_UPT_PTR_WRITE [i];
+              uint32_t            top_next      = (upt_ptr_write+1)%_param->_size_upt_queue [context];
               Tbranch_condition_t condition  ;
               Tcontrol_t          is_accurate;
@@ -257,51 +248,106 @@
 	      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * upt_ptr_write : %d",upt_ptr_write);
 
-              if (miss_ifetch or miss_decod)
+              // In decod step, two miss type :
+              // miss_ifetch = branch is previously predict (predict interface), but it's not the good
+              // miss_decod  = branch was not detected
+              if (not (miss_ifetch or miss_decod))
 		{
+		  // Normal case : branch is previous predicted, change state of branch
+
+                  // Read ufpt_ptr (send in predic step)
+                  uint32_t ufpt_ptr_read = (_param->_have_port_depth)?PORT_READ(in_DECOD_UPDATE_PREDICTION_ID [i]):0;
+
+                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * ufpt_ptr_read : %d",ufpt_ptr_read);
+
+#ifdef DEBUG_TEST
+                  if (reg_UPDATE_FETCH_PREDICTION_TABLE [context][ufpt_ptr_read]._state != UPDATE_FETCH_PREDICTION_STATE_WAIT_DECOD)
+                    throw ERRORMORPHEO(FUNCTION,_("Decod : invalid ufpt state."));
+#endif
+                  // Change state
+                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UFPT [%d][%d].state <- UPDATE_FETCH_PREDICTION_STATE_END (decod - hit)",context,ufpt_ptr_read);
+                  reg_UPDATE_FETCH_PREDICTION_TABLE [context][ufpt_ptr_read]._state = UPDATE_FETCH_PREDICTION_STATE_END;
+
+                  // Push upt (from Pop ufpt)
+                  condition   = reg_UPDATE_FETCH_PREDICTION_TABLE [context][ufpt_ptr_read]._condition;
+                  is_accurate = reg_UPDATE_FETCH_PREDICTION_TABLE [context][ufpt_ptr_read]._is_accurate;
+
+                  reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._condition         = condition;
+                  reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._address_src       = reg_UPDATE_FETCH_PREDICTION_TABLE [context][ufpt_ptr_read]._address_src ;
+                  reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._address_dest      = reg_UPDATE_FETCH_PREDICTION_TABLE [context][ufpt_ptr_read]._address_dest;
+                  reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._last_take         = reg_UPDATE_FETCH_PREDICTION_TABLE [context][ufpt_ptr_read]._last_take   ;
+//                reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._good_take;
+                  reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._is_accurate       = is_accurate;
+                  reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._history           = reg_UPDATE_FETCH_PREDICTION_TABLE [context][ufpt_ptr_read]._history     ;
+                  reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._address_ras       = reg_UPDATE_FETCH_PREDICTION_TABLE [context][ufpt_ptr_read]._address_ras ;
+                  reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._index_ras         = reg_UPDATE_FETCH_PREDICTION_TABLE [context][ufpt_ptr_read]._index_ras   ;
+                  reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._ifetch_prediction = true ; // prediction from ifetch
+
+                  // Update pointer (now, this instruction is not in ufpt)
+                  if (need_update(condition))
+                    {
+                      reg_UFPT_NB_NEED_UPDATE [context] --;
+                      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_UFPT_NB_NEED_UPDATE (after) : %d",reg_UFPT_NB_NEED_UPDATE [context]);
+                    }
+		}
+              else
+                {
+                  // Have a miss !!!
                   log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * miss !!!");
 
-                  // Have a miss !!!
                   condition   = PORT_READ(in_DECOD_BTB_CONDITION [i]);
-                  is_accurate = _param->_accurate_block_decod or PORT_READ(in_DECOD_IS_ACCURATE   [i]);
-
-                  // if can_continue else don't wait the end of all instruction
-                  // can_continue = not miss_commit and the destination is accurate (know)
+                  is_accurate = (_param->_always_accurate_decod or 
+                                 (_param->_can_accurate_decod and PORT_READ(in_DECOD_IS_ACCURATE [i])));
+
+                  // if can_continue, don't wait the end of all instruction 
+                  // (can_continue = not miss_commit and the destination is accurate (know))
                   Tcontrol_t can_continue = is_accurate;
 
 #ifdef DEBUG_TEST
-                  if (reg_EVENT_STATE [context] != EVENT_STATE_OK)
-                    throw ERRORMORPHEO(FUNCTION,_("Decod : invalid event state."));
-#endif
-
-                  // miss_ifetch = branch is previously predict, but it's not the good
-                  //   * need flush ufpt
-                  // miss_decod  = branch was not detected
-                  //   * not necessary
+                  if (reg_UPT_EVENT_STATE [context] != UPT_EVENT_STATE_OK)
+                    throw ERRORMORPHEO(FUNCTION,_("Decod : invalid upt event state."));
+                  if (reg_UFPT_EVENT_STATE [context] != UFPT_EVENT_STATE_OK)
+                    throw ERRORMORPHEO(FUNCTION,_("Decod : invalid ufpt event state."));
+#endif
+
+                  // miss_ifetch -> need flush ufpt
+                  // miss_decod  -> not necessary
+                  // if can_continue (destination is know) and direction is not take (instruction in ifetch_queue can be valid)
+                  bool flush_ufpt = (not (can_continue and not direction and not miss_ifetch));
 
                   log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * can_continue: %d",can_continue);
                   log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * direction   : %d",direction   );
                   log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * miss_ifetch : %d",miss_ifetch );
-                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * change    : %d",(not (can_continue and not direction and not miss_ifetch)));
-
-                  // if can_continue (destination is know) and direction is not take, don't need flush fetch_unit.
-                  if (not (can_continue and not direction and not miss_ifetch))
+                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * flush_ufpt: %d",flush_ufpt  );
+
+                  // Test if can continue without flushing the ufpt (and ifetch_queue)
+                  if (flush_ufpt)
                     {
-                      if (reg_UFPT_NB_NEED_UPDATE [context] == 0)
-                        {
-                          // Change state
-                          log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * EVENT [%d] <- EVENT_STATE_UPDATE_CONTEXT (decod - miss - no flush ufpt)",context);
-                          reg_EVENT_STATE [context] = EVENT_STATE_UPDATE_CONTEXT;
-//                        reg_EVENT_SOURCE[context] = EVENT_SOURCE_UFPT;
-                        }
-                      else
-                        {
-                          log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * EVENT [%d] <- EVENT_STATE_MISS_FLUSH_UFPT (decod - miss - flush ufpt)",context);
-                          reg_EVENT_STATE [context] = EVENT_STATE_MISS_FLUSH_UFPT;
-                        }
-
-                      // Flush UPFT
+//                       // Optimisation : Test if ufpt have entry that need update prediction struction (as Return Address Stack)
+//                       if (reg_UFPT_NB_NEED_UPDATE [context] == 0)
+//                         {
+//                           // Change state
+//                           log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UPT_EVENT [%d] <- UPT_EVENT_STATE_KO_COMMIT_UPDATE_CONTEXT (decod - miss - no flush ufpt)",context);
+//                           reg_UPT_EVENT_STATE [context] = UPT_EVENT_STATE_KO_COMMIT_UPDATE_CONTEXT;
+
+//                           // @@@
+// //                           // Have an actual event ?
+// //                           if (not reg_EVENT_VAL [context])
+// //                             reg_EVENT_UPT_PTR  [context] = upt_ptr_write;
+//                         }
+//                       else
+//                         {
+//                           log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * EVENT [%d] <- UPT_EVENT_STATE_KO_MISS_WAIT_UFPT (decod - miss - flush ufpt)",context);
+//                           // just wait ufpt, don't flush upt
+//                           reg_UPT_EVENT_STATE [context] = UPT_EVENT_STATE_KO_MISS_WAIT_UFPT;
+//                         }
+
+                      reg_UPT_EVENT_STATE [context] = UPT_EVENT_STATE_KO_DECODE_UPDATE_CONTEXT;
+                      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UPT_EVENT_STATE [%d] <- %s (decod, miss)",context,toString(reg_UPT_EVENT_STATE [context]).c_str());
+
+                      // Need Flush UPFT
                       flush_UFPT [context] = true;
 
-                      reg_EVENT_IS_BRANCH       [context] = true;
+                      // Write information
+//                       reg_EVENT_IS_BRANCH       [context] = true;
                       reg_EVENT_DEPTH           [context] = upt_ptr_write;
                       reg_EVENT_ADDRESS_SRC     [context] = address_src; // delay_slot is compute in Context_State
@@ -310,5 +356,6 @@
                       reg_EVENT_CAN_CONTINUE    [context] = can_continue;
                     }
-                  
+                  // else can continue
+
                   // Push upt (from decod interface)
                   reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._condition         = condition;
@@ -323,43 +370,6 @@
                   reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._ifetch_prediction = false; // static prediction
 		}
-	      else
-		{
-		  // Normal case : branch is previous predicated, change state of branch
-                  uint32_t ufpt_ptr_read = (_param->_have_port_depth)?PORT_READ(in_DECOD_UPDATE_PREDICTION_ID [i]):0;
-
-                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * ufpt_ptr_read : %d",ufpt_ptr_read);
-
-#ifdef DEBUG_TEST
-                  if (reg_UPDATE_FETCH_PREDICTION_TABLE [context][ufpt_ptr_read]._state != UPDATE_FETCH_PREDICTION_STATE_WAIT_DECOD)
-                    throw ERRORMORPHEO(FUNCTION,_("Decod : invalid ufpt state."));
-#endif
-                  // Change state
-                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UFPT [%d][%d].state <- UPDATE_FETCH_PREDICTION_STATE_END (decod - hit)",context,ufpt_ptr_read);
-                  reg_UPDATE_FETCH_PREDICTION_TABLE [context][ufpt_ptr_read]._state = UPDATE_FETCH_PREDICTION_STATE_END;
-
-                  // Push upt (from Pop ufpt)
-                  condition   = reg_UPDATE_FETCH_PREDICTION_TABLE [context][ufpt_ptr_read]._condition;
-                  is_accurate = reg_UPDATE_FETCH_PREDICTION_TABLE [context][ufpt_ptr_read]._is_accurate;
-
-                  reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._condition         = condition;
-                  reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._address_src       = reg_UPDATE_FETCH_PREDICTION_TABLE [context][ufpt_ptr_read]._address_src ;
-                  reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._address_dest      = reg_UPDATE_FETCH_PREDICTION_TABLE [context][ufpt_ptr_read]._address_dest;
-                  reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._last_take         = reg_UPDATE_FETCH_PREDICTION_TABLE [context][ufpt_ptr_read]._last_take   ;
-//                reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._good_take;
-                  reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._is_accurate       = is_accurate;
-                  reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._history           = reg_UPDATE_FETCH_PREDICTION_TABLE [context][ufpt_ptr_read]._history     ;
-                  reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._address_ras       = reg_UPDATE_FETCH_PREDICTION_TABLE [context][ufpt_ptr_read]._address_ras ;
-                  reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._index_ras         = reg_UPDATE_FETCH_PREDICTION_TABLE [context][ufpt_ptr_read]._index_ras   ;
-                  reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._ifetch_prediction = true ; // prediction from ifetch
-
-                  // Update pointer
-                  if (need_update(condition))
-                    {
-                      reg_UFPT_NB_NEED_UPDATE [context] --;
-                      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_UFPT_NB_NEED_UPDATE (after) : %d",reg_UFPT_NB_NEED_UPDATE [context]);
-                    }
-		}
-
-              // All case !!!
+
+              // In all case !!!
 #ifdef DEBUG_TEST
               if (reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._state != UPDATE_PREDICTION_STATE_EMPTY)
@@ -369,5 +379,5 @@
               // Change state
               log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UPT  [%d][%d].state <- UPDATE_PREDICTION_STATE_WAIT_END (decod - hit)",context,upt_ptr_write);
-              reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._state = UPDATE_PREDICTION_STATE_WAIT_END;
+              reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._state       = UPDATE_PREDICTION_STATE_WAIT_END;
               reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._retire_ok   = false;
               reg_UPDATE_PREDICTION_TABLE [context][upt_ptr_write]._miss_commit = false;
@@ -384,10 +394,6 @@
               
               // Update pointer
-              reg_UPT_TOP     [context] = (upt_ptr_write+1)%_param->_size_upt_queue [context];
-              reg_UPT_EMPTY   [context] = false;
-//            reg_UPT_UPDATE  [context] = reg_UPT_TOP [context];
-
-//               if (miss_ifetch or miss_decod)
-//                 reg_UPT_TOP_EVENT [context] = reg_UPT_TOP [context];
+              reg_UPT_TOP     [context] = top_next;
+              reg_UPT_EMPTY   [context] = false; // new instruction
 	    }
 
@@ -400,8 +406,11 @@
             can_continue [i] = true;
 
+          // For each updated instruction
           for (uint32_t i=0; i<_param->_nb_inst_update; i++)
             {
 	      Tcontext_t context   = internal_UPDATE_CONTEXT_ID [i];
 
+              // Test if transaction
+              // (an val_with_out is an update and don't need update prediction structure
               if ((internal_UPDATE_VAL[i] and PORT_READ(in_UPDATE_ACK [i])) or
                   (internal_UPDATE_VAL_WITHOUT_ACK [i] and can_continue [context]))
@@ -413,26 +422,30 @@
                   log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * depth   : %d",depth);
                   
+                  upt_event_state_t upt_event_state = reg_UPT_EVENT_STATE [context];
+
+                  // One interface to two source : 
+                  //   * from ufpt -> newest prediction
+                  //   * from upt  -> oldest prediction
                   if (internal_UPDATE_FROM_UFPT [i])
                     {
                       // if free a slot, also all queue is updated
                       // Last slot ?
-//                       if (reg_UFPT_UPDATE [context] == reg_UFPT_BOTTOM [context])
                       if ((--reg_UFPT_NB_UPDATE [context])==0)
                         {
-                          switch (reg_EVENT_STATE [context])
-                            {
-                            case EVENT_STATE_MISS_FLUSH_UFPT         : 
-                              {
-                                reg_EVENT_STATE [context] = EVENT_STATE_UPDATE_CONTEXT; 
-//                                 reg_EVENT_SOURCE[context] = EVENT_SOURCE_UFPT;
-
-                                break;
-                              }
-                              // impossible to have an update on ufpt and reg_upt_update>reg_upt_top
-                            case EVENT_STATE_MISS_FLUSH_UFPT_AND_UPT : reg_EVENT_STATE [context] = EVENT_STATE_MISS_FLUSH_UPT ; break;
-                            case EVENT_STATE_EVENT_FLUSH_UFPT        : reg_EVENT_STATE [context] = EVENT_STATE_OK             ; break;
-                            case EVENT_STATE_EVENT_FLUSH_UFPT_AND_UPT: reg_EVENT_STATE [context] = EVENT_STATE_EVENT_FLUSH_UPT; break;
-                            default : break;
-                            }
+                          log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UFPT_EVENT [%d] <- UFPT_EVENT_STATE_OK (update - end flush ufpt)",context);
+                          reg_UFPT_EVENT_STATE    [context] = UFPT_EVENT_STATE_OK;
+                          reg_UFPT_NB_NEED_UPDATE [context] = 0;
+
+//                           // Test upt event to change state
+//                           // test if upt wait ufpt
+//                           switch (upt_event_state)
+//                             {
+//                               // this case when don't need flush upt (miss decod and can continue)
+//                             case UPT_EVENT_STATE_KO_MISS_WAIT_UFPT  : upt_event_state = UPT_EVENT_STATE_KO_COMMIT_UPDATE_CONTEXT; break;
+//                             case UPT_EVENT_STATE_KO_EVENT_WAIT_UFPT : upt_event_state = UPT_EVENT_STATE_OK               ; break;
+//                             default : break;
+//                             }
+
+//                           reg_UPT_EVENT_STATE [context] = upt_event_state;
                         }
                       
@@ -453,10 +466,4 @@
                       reg_UFPT_UPDATE [context] = ((depth==0)?_param->_size_ufpt_queue[context]:depth)-1;
                       log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_UFPT_UPDATE (after ) : %d",reg_UFPT_UPDATE [context]);
-                      // Free a register that need update ?
-                      if (need_update(reg_UPDATE_FETCH_PREDICTION_TABLE [context][depth]._condition))
-                        {
-                          reg_UFPT_NB_NEED_UPDATE [context] --;
-                          log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_UFPT_NB_NEED_UPDATE (after) : %d",reg_UFPT_NB_NEED_UPDATE [context]);
-                        }
                     }
                   else
@@ -464,5 +471,5 @@
                       log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * Update Prediction Table");
                       log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * reg_UPT_UPDATE (before) : %d",reg_UPT_UPDATE [context]);
-                      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * reg_EVENT_STATE         : %s",toString(reg_EVENT_STATE [context]).c_str());
+                      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * reg_UPT_EVENT_STATE     : %s",toString(upt_event_state).c_str());
  
                       // Change state
@@ -481,12 +488,11 @@
 #endif
 
-//                    bool have_event = ((reg_UPDATE_PREDICTION_TABLE [context][depth]._state == UPDATE_PREDICTION_STATE_KO) or
-//                                       (reg_UPDATE_PREDICTION_TABLE [context][depth]._state == UPDATE_PREDICTION_STATE_EVENT));
 #ifdef STATISTICS
                       Tbranch_condition_t condition = reg_UPDATE_PREDICTION_TABLE [context][depth]._condition;
 #endif
-                      bool ok     = (reg_UPDATE_PREDICTION_TABLE [context][depth]._state == UPDATE_PREDICTION_STATE_OK);
-                      bool ko     = (reg_UPDATE_PREDICTION_TABLE [context][depth]._state == UPDATE_PREDICTION_STATE_KO);
-
+                      bool ok = (reg_UPDATE_PREDICTION_TABLE [context][depth]._state == UPDATE_PREDICTION_STATE_OK);
+                      bool ko = (reg_UPDATE_PREDICTION_TABLE [context][depth]._state == UPDATE_PREDICTION_STATE_KO);
+
+                      // Test if branch is valid (prediction can be incorrect)
                       if (ok or ko)
                         {
@@ -508,18 +514,11 @@
                       if (ko)
                         {
-                          // Ko : wait end of all instruction
-//                           log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UPT  [%d][%d].state <- UPDATE_PREDICTION_STATE_END_KO_WAIT_END (update)",context,depth);
-                          
-//                           reg_UPDATE_PREDICTION_TABLE [context][depth]._state = UPDATE_PREDICTION_STATE_END_KO_WAIT_END;
-
+                          // Ko
                           log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UPT  [%d][%d].state <- UPDATE_PREDICTION_STATE_END_KO (update)",context,depth);
                           
+                          // Wait update of context_state
                           reg_UPDATE_PREDICTION_TABLE [context][depth]._state = UPDATE_PREDICTION_STATE_END_KO;
 
-                          reg_EVENT_VAL      [context] = true;
                           reg_EVENT_UPT_PTR  [context] = depth;
-//                        reg_EVENT_UPT_FULL [context] = 0;
-//                        reg_EVENT_UPT_FULL        [i] = (not reg_UPT_EMPTY [i] and (bottom == reg_UPT_TOP [i]));
-
 
 #ifdef STATISTICS
@@ -530,6 +529,5 @@
                       else
                         {
-//                           log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UPT  [%d][%d].state <- UPDATE_PREDICTION_STATE_END_OK (update)",context,depth);
-//                           reg_UPDATE_PREDICTION_TABLE [context][depth]._state = UPDATE_PREDICTION_STATE_END_OK;
+                          // ok or event
 
                           log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UPT  [%d][%d].state <- UPDATE_PREDICTION_STATE_END (update)",context,depth);
@@ -564,16 +562,24 @@
 //                            reg_UPT_UPDATE [context] = reg_UPT_BOTTOM[context];
 
-                              if (reg_EVENT_STATE [context] == EVENT_STATE_EVENT_FLUSH_UPT)
+                              switch (upt_event_state)
                                 {
-                                  reg_EVENT_STATE [context] = EVENT_STATE_OK;
+                                  // this case when don't need flush upt (miss decod and can continue)
+                                case UPT_EVENT_STATE_KO_MISS_FLUSH_UPT  : upt_event_state = UPT_EVENT_STATE_KO_COMMIT_UPDATE_CONTEXT; break;
+                                case UPT_EVENT_STATE_KO_EVENT_FLUSH_UPT : 
+                                  {
+                                    upt_event_state = UPT_EVENT_STATE_OK;
+                                    reg_UPT_TOP    [context] = reg_UPT_TOP_EVENT [context];
+                                    reg_UPT_UPDATE [context] = reg_UPT_TOP_EVENT [context];
+
+                                    break;
+                                  }
+                                default : break;
                                 }
-                              else
-                                {
-                                  reg_EVENT_STATE [context] = EVENT_STATE_UPDATE_CONTEXT;
-//                                   reg_EVENT_SOURCE[context] = EVENT_SOURCE_UPT;
-                                }
+                              
+                              reg_UPT_EVENT_STATE [context] = upt_event_state;
                             }
                           else
                             {
+                              // else, decrease update pointer
                               reg_UPT_UPDATE [context] = (((depth==0)?_param->_size_upt_queue[context]:depth)-1);
                             }
@@ -587,10 +593,10 @@
                         }
                       
-                      // Free the branch with no accurate ?
+                      // Test if freeing the branch with no accurate ?
                       if ((reg_UPDATE_PREDICTION_TABLE [context][depth]._is_accurate == false) and not ko)
                         reg_IS_ACCURATE [context] = true;
 
                       log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * reg_UPT_UPDATE (after ) : %d",reg_UPT_UPDATE[context]);
-                      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * reg_EVENT_STATE         : %s",toString(reg_EVENT_STATE [context]).c_str());
+                      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * reg_UPT_EVENT_STATE     : %s",toString(reg_UPT_EVENT_STATE [context]).c_str());
                     }
                 }
@@ -611,153 +617,167 @@
         //     * update status
         //   * Miss prediction :
-	for (uint32_t i=0; i<_param->_nb_inst_branch_complete; i++)
-	  if (PORT_READ(in_BRANCH_COMPLETE_VAL[i]) and internal_BRANCH_COMPLETE_ACK [i])
-	    {
-	      Tcontext_t context   = (_param->_have_port_context_id)?PORT_READ(in_BRANCH_COMPLETE_CONTEXT_ID [i]):0;
-	      Tdepth_t   depth     = (_param->_have_port_depth     )?PORT_READ(in_BRANCH_COMPLETE_DEPTH      [i]):0;
-              Tcontrol_t miss      = internal_BRANCH_COMPLETE_MISS_PREDICTION [i];
-              Tcontrol_t good_take = internal_BRANCH_COMPLETE_TAKE            [i];
-              Taddress_t good_addr = internal_BRANCH_COMPLETE_ADDRESS_DEST    [i];
-
-	      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,"    * reg_EVENT_STATE     : %s",toString(reg_EVENT_STATE [context]).c_str());
-	      
-              if (miss)
-		{
-                  // Flush UPT
-                  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];
-                  upt_state_t   event_top           = reg_UPDATE_PREDICTION_TABLE [context][top]._state;
-
-                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * event_top           : %s",toString(event_top).c_str());
-
-                  bool          previous_ufpt_event = ((event_state == EVENT_STATE_MISS_FLUSH_UFPT_AND_UPT ) or
-                                                       (event_state == EVENT_STATE_MISS_FLUSH_UFPT         ) or
-                                                       (event_state == EVENT_STATE_EVENT_FLUSH_UFPT_AND_UPT) or
-                                                       (event_state == EVENT_STATE_EVENT_FLUSH_UFPT        ));
-
-                  bool          previous_upt_event  = (false
-                                                       or  (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_top   == UPDATE_PREDICTION_STATE_END_KO      )
-                                                       or  (event_top   == UPDATE_PREDICTION_STATE_KO          )
-//                                                     or  (event_state == EVENT_STATE_WAIT_END_EVENT          )
-//                                                        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_upt_event  : %d",previous_upt_event);
-                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * previous_ufpt_event : %d",previous_ufpt_event);
-                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_UPT_UPDATE      : %d",reg_UPT_UPDATE [context]);
-                          
-                  // Have a miss !!!
-                  // Flush UPFT
-                  flush_UFPT [context] |= not previous_ufpt_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_UPDATE_PREDICTION_TABLE [context][j]._retire_ok = false;
-                        }
-                      
-                  
-//                    reg_UPT_BOTTOM    [context];
-                      reg_UPT_TOP       [context] = depth;
-//                    reg_UPT_TOP_EVENT [context] = top;
-                      
-                      if (not previous_upt_event)
-                        {
-                          reg_UPT_TOP_EVENT [context] = top;
-                          reg_UPT_UPDATE    [context] = new_update;
-                        }
-                      else
-                        {
-                          // Have event. Top index this slot
-                          reg_UPDATE_PREDICTION_TABLE [context][top]._retire_ok = false;
-
-                          switch (event_top)
-                            {
-                            case UPDATE_PREDICTION_STATE_END_KO : 
+        {
+          bool branch_complete_miss [_param->_nb_context];
+          for (uint32_t i=0; i<_param->_nb_context; ++i)
+            branch_complete_miss [i] = false;
+
+          for (uint32_t i=0; i<_param->_nb_inst_branch_complete; i++)
+            if (PORT_READ(in_BRANCH_COMPLETE_VAL[i]) and internal_BRANCH_COMPLETE_ACK [i])
+              {
+                // Read information
+                Tcontext_t context   = (_param->_have_port_context_id)?PORT_READ(in_BRANCH_COMPLETE_CONTEXT_ID [i]):0;
+                Tdepth_t   depth     = (_param->_have_port_depth     )?PORT_READ(in_BRANCH_COMPLETE_DEPTH      [i]):0;
+                Tcontrol_t miss      = internal_BRANCH_COMPLETE_MISS_PREDICTION [i];
+                Tcontrol_t good_take = internal_BRANCH_COMPLETE_TAKE            [i];
+                Taddress_t good_addr = internal_BRANCH_COMPLETE_ADDRESS_DEST    [i];
+                
+                upt_event_state_t upt_event_state  = reg_UPT_EVENT_STATE [context];
+                
+                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,"    * reg_UPT_EVENT_STATE : %s",toString(upt_event_state).c_str());
+                
+                // Test if the completed branch is a speculation miss
+                if (miss)
+                  {
+                    // special case : two branch complete on the same context.
+                    // when the re order keep the order, the branch complete j is most speculative that the branch comple i if i < j
+                    if (not branch_complete_miss [context])
+                      {
+                        branch_complete_miss [context] = true;
+                        // Flush UPT
+                        // get information
+                        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;
+                        upt_state_t       event_top           = reg_UPDATE_PREDICTION_TABLE [context][top]._state;
+                        
+                        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * upt_event_state     : %s",toString(upt_event_state).c_str());
+                        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * event_top           : %s",toString(event_top).c_str());
+                        
+                        bool              previous_ufpt_event = (reg_UFPT_EVENT_STATE [i] == UFPT_EVENT_STATE_KO_FLUSH);
+                        
+                        
+                        bool              previous_upt_event  = (false
+                                                                 or (upt_event_state == UPT_EVENT_STATE_KO_MISS_WAIT_UFPT )
+                                                                 or (upt_event_state == UPT_EVENT_STATE_KO_MISS_FLUSH_UPT )
+                                                                 or (upt_event_state == UPT_EVENT_STATE_KO_EVENT_WAIT_UFPT)
+                                                                 or (upt_event_state == UPT_EVENT_STATE_KO_EVENT_FLUSH_UPT)
+                                                                 or (event_top       == UPDATE_PREDICTION_STATE_END_KO    )
+                                                                 or (event_top       == UPDATE_PREDICTION_STATE_KO        )
+                                                                 );
+                        
+                        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,"    * previous_upt_event  : %d",previous_upt_event);
+                        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * previous_ufpt_event : %d",previous_ufpt_event);
+                        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_UPT_UPDATE      : %d",reg_UPT_UPDATE [context]);
+                        
+                        // Have a miss !!!
+                        // Flush UPFT
+                        flush_UFPT [context] |= not previous_ufpt_event;
+                        
+                        // Test if the entry wait the branchment (else, they have a previous event)
+                        if (reg_UPDATE_PREDICTION_TABLE [context][depth]._state == UPDATE_PREDICTION_STATE_WAIT_END)
+                          {
+                            // All instruction between the instruction and the top is disable
+                            for (uint32_t j=(depth+1)%_param->_size_upt_queue[context];
+                                 j!=top; 
+                                 j=(j+1)%_param->_size_upt_queue[context])
                               {
-                                // Have already update predictor
-                                reg_UPDATE_PREDICTION_TABLE [context][top]._state = UPDATE_PREDICTION_STATE_END;
-                                reg_UPT_UPDATE              [context] = new_update;
-                                break;
+                                reg_UPDATE_PREDICTION_TABLE [context][j]._state     = UPDATE_PREDICTION_STATE_EVENT;
+                                reg_UPDATE_PREDICTION_TABLE [context][j]._retire_ok = false; // event
                               }
-                            case UPDATE_PREDICTION_STATE_KO :
+                            
+                            // New top
+                            reg_UPT_TOP       [context] = depth;
+                            
+                            if (not previous_upt_event)
                               {
-                                // Doesn't have update predictor
-                                reg_UPDATE_PREDICTION_TABLE [context][top]._state = UPDATE_PREDICTION_STATE_EVENT;
-                                break;
+                                reg_UPT_TOP_EVENT [context] = top;
+                                reg_UPT_UPDATE    [context] = new_update;
                               }
-                            default :
+                            else
                               {
-//                                 reg_UPDATE_PREDICTION_TABLE [context][top]._state = UPDATE_PREDICTION_STATE_EVENT;
+                                // Have event. Top index this slot
+                                reg_UPDATE_PREDICTION_TABLE [context][top]._retire_ok = false;
+                                
+                                switch (event_top)
+                                  {
+                                  case UPDATE_PREDICTION_STATE_END_KO : 
+                                    {
+                                      // Have already update predictor
+                                      reg_UPDATE_PREDICTION_TABLE [context][top]._state = UPDATE_PREDICTION_STATE_END;
+                                      reg_UPT_UPDATE              [context] = new_update;
+                                      break;
+                                    }
+                                  case UPDATE_PREDICTION_STATE_KO :
+                                    {
+                                      // Doesn't have update predictor
+                                      reg_UPDATE_PREDICTION_TABLE [context][top]._state = UPDATE_PREDICTION_STATE_EVENT;
+                                      break;
+                                    }
+                                  default :
+                                    {
+                                      //                                 reg_UPDATE_PREDICTION_TABLE [context][top]._state = UPDATE_PREDICTION_STATE_EVENT;
 //                                 break;
-
+                                      
 #ifdef DEBUG_TEST
-                                throw ERRORMORPHEO(FUNCTION,_("Branch complete : invalid upt state."));
-#endif
+                                      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;
-
-                      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_UFPT_NB_NEED_UPDATE [%d] : %d",context,reg_UFPT_NB_NEED_UPDATE [context]);
-                     
-                      if ( (reg_UFPT_NB_NEED_UPDATE [context] > 0) or
-                           (reg_UFPT_NB_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;
+                            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;
+                            
+                            log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_UFPT_NB_NEED_UPDATE [%d] : %d",context,reg_UFPT_NB_NEED_UPDATE [context]);
+                            
+//                       if ( (reg_UFPT_NB_NEED_UPDATE [context] > 0) or
+//                            (reg_UFPT_NB_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_UPT_EVENT_STATE [context] = UPT_EVENT_STATE_KO_MISS_FLUSH_UPT;
+                            log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UPT_EVENT_STATE [%d] <- %s (branch_complete, ifetch hit)",context,toString(reg_UPT_EVENT_STATE [context]).c_str());
+                            
+                            //                       reg_EVENT_SOURCE          [context] = EVENT_SOURCE_UPT;
+                            
+                            // else no update
+                            
+                            //                       reg_EVENT_IS_BRANCH       [context] = true;
+                            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;
+                            reg_EVENT_CAN_CONTINUE    [context] = false;
                             
                           }
-                        }
-//                       reg_EVENT_SOURCE          [context] = EVENT_SOURCE_UPT;
-                      
-                      // else no update
-                      
-                      reg_EVENT_IS_BRANCH       [context] = true;
-                      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;
-                      reg_EVENT_CAN_CONTINUE    [context] = false;
-
-                    }
-                  reg_UPDATE_PREDICTION_TABLE [context][depth]._miss_commit = true;
-                }
-	      else
-		{
+                        
+                        reg_UPDATE_PREDICTION_TABLE [context][depth]._miss_commit = true;
+                      }
+                  }
+                else
+                  {
                   // Hit case
 
@@ -767,25 +787,26 @@
 // #endif
 
-                  if (reg_UPDATE_PREDICTION_TABLE [context][depth]._state == UPDATE_PREDICTION_STATE_WAIT_END)
-                    {
-                      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UPT  [%d][%d].state <- UPDATE_PREDICTION_STATE_OK (branch_complete, ifetch hit)",context,depth);
-                      reg_UPDATE_PREDICTION_TABLE [context][depth]._state = UPDATE_PREDICTION_STATE_OK;
-                    }
-		}
-
-              log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_EVENT_STATE     : %s",toString(reg_EVENT_STATE [context]).c_str());
-
-	      // In all case : update good_take
-	      reg_UPDATE_PREDICTION_TABLE [context][depth]._good_take    = good_take;
-
-              // Write address_dest if need read register
-              Tbranch_condition_t condition = reg_UPDATE_PREDICTION_TABLE [context][depth]._condition;
-              
-              if ((condition == BRANCH_CONDITION_READ_REGISTER_WITHOUT_WRITE_STACK) or
-                  (condition == BRANCH_CONDITION_READ_REGISTER_WITH_WRITE_STACK   ) or
-                  (condition == BRANCH_CONDITION_READ_STACK                       ) )
-                reg_UPDATE_PREDICTION_TABLE [context][depth]._address_dest = good_addr;
-            }
-
+                  // In same cycle, can have a previous branch_complete
+                    if (reg_UPDATE_PREDICTION_TABLE [context][depth]._state == UPDATE_PREDICTION_STATE_WAIT_END)
+                      {
+                        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UPT  [%d][%d].state <- UPDATE_PREDICTION_STATE_OK (branch_complete, ifetch hit)",context,depth);
+                        reg_UPDATE_PREDICTION_TABLE [context][depth]._state = UPDATE_PREDICTION_STATE_OK;
+                      }
+                  }
+                
+                log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_UPT_EVENT_STATE : %s",toString(reg_UPT_EVENT_STATE [context]).c_str());
+                
+                // In all case : update good_take
+                reg_UPDATE_PREDICTION_TABLE [context][depth]._good_take    = good_take;
+                
+                // Write address_dest if need read register
+                Tbranch_condition_t condition = reg_UPDATE_PREDICTION_TABLE [context][depth]._condition;
+                
+                if ((condition == BRANCH_CONDITION_READ_REGISTER_WITHOUT_WRITE_STACK) or
+                    (condition == BRANCH_CONDITION_READ_REGISTER_WITH_WRITE_STACK   ) or
+                    (condition == BRANCH_CONDITION_READ_STACK                       ) )
+                  reg_UPDATE_PREDICTION_TABLE [context][depth]._address_dest = good_addr;
+              }
+        }
 
  	// ===================================================================
@@ -797,11 +818,15 @@
 	      log_printf(TRACE,Update_Prediction_Table,FUNCTION,"  * BRANCH_EVENT [%d] - Accepted",i);
 
-              // if different : an other branch is occured
-              if (reg_EVENT_STATE        [i] == EVENT_STATE_UPDATE_CONTEXT)
+              upt_event_state_t upt_event_state  = reg_UPT_EVENT_STATE [i];
+              
+              switch (upt_event_state)
                 {
-                  // Change state
-                  log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * EVENT [%d] <- EVENT_STATE_WAIT_END_EVENT (branch_event)",i);
-                  reg_EVENT_STATE [i] = EVENT_STATE_WAIT_END_EVENT;
+                case UPT_EVENT_STATE_KO_DECODE_UPDATE_CONTEXT : upt_event_state = UPT_EVENT_STATE_KO_DECODE_WAIT_END_EVENT; break;
+                case UPT_EVENT_STATE_KO_COMMIT_UPDATE_CONTEXT : upt_event_state = UPT_EVENT_STATE_KO_COMMIT_WAIT_END_EVENT; break;
+                default : break; // an other branch is occured
                 }
+
+              reg_UPT_EVENT_STATE [i] = upt_event_state;
+              log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_UPT_EVENT_STATE : %s (branch_event)",toString(upt_event_state).c_str());
             }
 
@@ -826,5 +851,6 @@
               //   * EVENT_TYPE_CSYNC              - nothing
               
-              Tevent_type_t  event_type  = PORT_READ(in_EVENT_TYPE  [i]);
+              Tevent_type_t     event_type      = PORT_READ(in_EVENT_TYPE  [i]);
+              upt_event_state_t upt_event_state = reg_UPT_EVENT_STATE [i];
 
               // Test if end of miss -> all previous branch is complete
@@ -837,38 +863,37 @@
                     log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * type  : EVENT_TYPE_BRANCH_MISS_SPECULATION");
 
-// #ifdef DEBUG_TEST
-//                     if (reg_EVENT_STATE [i] != EVENT_STATE_WAIT_END_EVENT)
-//                       throw ERRORMORPHEO(FUNCTION,_("Event : invalid event state."));
-// #endif
-                    // Special case : test if event and branch_complete !
-                    if (reg_EVENT_STATE [i] == EVENT_STATE_WAIT_END_EVENT)
+                    switch (upt_event_state)
                       {
-                    
-                        // Change state
-                        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * EVENT [%d] <- EVENT_STATE_OK (event)",i);
-                        
-                        reg_EVENT_STATE [i] = EVENT_STATE_OK;
-                        reg_IS_ACCURATE [i] = true;
-                        
-                        Tdepth_t depth = reg_EVENT_UPT_PTR [i];
-                        
-                        if (reg_UPDATE_PREDICTION_TABLE [i][depth]._state == UPDATE_PREDICTION_STATE_END_KO)
-                          {
-                            log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UPT  [%d][%d].state <- UPDATE_PREDICTION_STATE_END (event)",i,depth);
-                            
-                            reg_UPDATE_PREDICTION_TABLE [i][depth]._state = UPDATE_PREDICTION_STATE_END;
-                          }
-                        
-#ifdef DEBUG_TEST
-//                     if (reg_UPDATE_PREDICTION_TABLE [i][depth]._state != UPDATE_PREDICTION_STATE_END_KO_WAIT_END)
-//                       throw ERRORMORPHEO(FUNCTION,_("Event : invalid upt event state."));
-//                  if (reg_UPDATE_PREDICTION_TABLE [i][depth]._state != UPDATE_PREDICTION_STATE_END_KO)
-//                    throw ERRORMORPHEO(FUNCTION,_("Event : invalid upt event state."));
-#endif
-
-//                     log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UPT  [%d][%d].state <- UPDATE_PREDICTION_STATE_END_KO (update)",i,depth);
-                    
-//                     reg_UPDATE_PREDICTION_TABLE [i][depth]._state = UPDATE_PREDICTION_STATE_END_KO;
+                      case UPT_EVENT_STATE_KO_COMMIT_WAIT_END_EVENT :
+                        {
+                          Tdepth_t depth = reg_EVENT_UPT_PTR [i];
+                          
+                          log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * depth : %d",depth);
+                          
+                          if (reg_UPDATE_PREDICTION_TABLE [i][depth]._state == UPDATE_PREDICTION_STATE_END_KO)
+                            {
+                              log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UPT  [%d][%d].state <- UPDATE_PREDICTION_STATE_END (event)",i,depth);
+                              
+                              reg_UPDATE_PREDICTION_TABLE [i][depth]._state = UPDATE_PREDICTION_STATE_END;
+                            }
+
+                            reg_UPT_TOP    [i] = reg_UPT_TOP_EVENT [i];
+                            reg_UPT_UPDATE [i] = reg_UPT_TOP_EVENT [i];
+
+                          // break; continue
+                        }
+                      case UPT_EVENT_STATE_KO_DECODE_WAIT_END_EVENT :
+                        {
+                          // Change state
+                          log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * EVENT [%d] <- EVENT_STATE_OK (event)",i);
+                          
+                          upt_event_state = UPT_EVENT_STATE_OK;
+                          reg_IS_ACCURATE [i] = true;
+
+                          break;
+                        }
+                      default : break; // an other branch is occured
                       }
+
                     break;
                   }
@@ -893,8 +918,9 @@
 //                                                          (event_state == EVENT_STATE_EVENT_FLUSH_UPT));
 
-                    bool     find   = false; // have slot to update ???
-                    Tdepth_t top    = bottom;
-                    Tdepth_t update = bottom;
-                    bool     empty  = reg_UPT_EMPTY [i];
+                    bool     find     = false; // have slot to update ???
+                    bool     find_top = false;
+                    Tdepth_t top      = bottom;
+                    Tdepth_t update   = bottom;
+                    bool     empty    = reg_UPT_EMPTY [i];
 
                     // flush all slot, because this event is in head of rob
@@ -902,10 +928,14 @@
                       {
                         Tdepth_t x = (bottom+j)%_param->_size_upt_queue[i];
+
+                        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * UPT [%d] : %s",x,toString(reg_UPDATE_PREDICTION_TABLE [i][x]._state).c_str());
                         
                         if ((reg_UPDATE_PREDICTION_TABLE [i][x]._state != UPDATE_PREDICTION_STATE_END) and
                             (reg_UPDATE_PREDICTION_TABLE [i][x]._state != UPDATE_PREDICTION_STATE_EMPTY))
                           {
+                            log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * find at UPT[%d]",x);
+
                             find = true; // find a not empty slot
-                            reg_UPDATE_PREDICTION_TABLE [i][x]._state = UPDATE_PREDICTION_STATE_EVENT;
+                            reg_UPDATE_PREDICTION_TABLE [i][x]._state     = UPDATE_PREDICTION_STATE_EVENT;
                             reg_UPDATE_PREDICTION_TABLE [i][x]._retire_ok = false;
                             update = x;
@@ -913,23 +943,27 @@
 
                         if (reg_UPDATE_PREDICTION_TABLE [i][x]._state != UPDATE_PREDICTION_STATE_EMPTY)
-                          top = x+1;
+                          if (not find_top)
+                            {
+                              top = x;
+                              find_top = true;
+                            }
                       }
-
-                    top = top%_param->_size_upt_queue[i];
 
                     log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * find       : %d",find);
                     log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * top        : %d",top);
+                    log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * update     : %d",update);
                     
                     // Test if have update slot
+                    reg_UPT_TOP_EVENT [i] = reg_UPT_TOP[i];
                     if (find)
                       {
                         // TODO : special case : event is an exception on branch, also depth is not valid
                         reg_UPT_TOP       [i] = top; // depth is again valid
-                        reg_UPT_TOP_EVENT [i] = top;
                         
                         if (bottom == reg_UPT_TOP [i])
                           reg_UPT_EMPTY [i] = true;
+
+                        reg_UPT_UPDATE [i]  = update;
                       }
-                    reg_UPT_UPDATE [i]  = update;
               
                     // new state :
@@ -939,6 +973,7 @@
                     //            * ok : nothing
                     //            * ko : flush upt
-                    reg_EVENT_VAL             [i] = find;
-                    reg_EVENT_IS_BRANCH       [i] = false;
+//                     reg_EVENT_VAL             [i] = find;
+//                     reg_EVENT_IS_BRANCH       [i] = false;
+//                     reg_EVENT_UPT_PTR         [i] = ((top==0)?_param->_size_upt_queue[i]:top)-1; ///// ZE MODIF
                     reg_EVENT_UPT_PTR         [i] = top;
                     reg_EVENT_UPT_FULL        [i] = (not empty and (bottom == reg_UPT_TOP [i]));
@@ -952,5 +987,5 @@
                     log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_UPT_EMPTY                    : %d",reg_UPT_EMPTY           [i]);
 
-                    log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_EVENT_VAL                    : %d",reg_EVENT_VAL           [i]);
+//                     log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_EVENT_VAL                    : %d",reg_EVENT_VAL           [i]);
                     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_UPT_FULL               : %d",reg_EVENT_UPT_FULL      [i]);
@@ -958,172 +993,20 @@
                     log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_UFPT_NB_UPDATE               : %d",reg_UFPT_NB_UPDATE      [i]);
 
-                    if ( (reg_UFPT_NB_NEED_UPDATE [i] > 0) or
-                         (reg_UFPT_NB_UPDATE      [i] > 0))
+                    if (find)
                       {
-                        if (find)
-                          {
-                            log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * EVENT [%d] <- EVENT_STATE_EVENT_FLUSH_UFPT_AND_UPT (event - find)",i);
-                            reg_EVENT_STATE [i] = EVENT_STATE_EVENT_FLUSH_UFPT_AND_UPT;
-                          }
-                        else
-                          {
-                            log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * EVENT [%d] <- EVENT_STATE_EVENT_FLUSH_UFPT (event - not find)",i);
-//                          reg_EVENT_VAL   [i] = false;
-
-                            reg_EVENT_STATE [i] = EVENT_STATE_EVENT_FLUSH_UFPT;
-                          }                          
+                        // have ras prediction ?
+                        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UPT_EVENT [%d] <- UPT_EVENT_STATE_KO_EVENT_FLUSH_UPT (event - find)",i);
+                        
+                        upt_event_state = UPT_EVENT_STATE_KO_EVENT_FLUSH_UPT;
                       }
                     else
                       {
-                        if (find)
-                          {
-                            // have ras prediction ?
-                            log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * EVENT [%d] <- EVENT_STATE_EVENT_FLUSH_UPT (event - find)",i);
-                            
-                            reg_EVENT_STATE [i] = EVENT_STATE_EVENT_FLUSH_UPT;
-                          }
-                        else
-                          {
-                            // special case : nothing
-                            log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * EVENT [%d] <- EVENT_STATE_EVENT_FLUSH_UPT (event - not find)",i);
-
-//                          reg_EVENT_VAL     [i] = false;
-
-                            reg_EVENT_STATE [i] = EVENT_STATE_OK;
-                          }
+                        // special case : nothing
+                        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * UPT_EVENT [%d] <- UPT_EVENT_STATE_KO_EVENT_WAIT_UFPT (event - not find)",i);
+                        
+//                      reg_EVENT_VAL     [i] = false;
+                        
+                        upt_event_state = UPT_EVENT_STATE_KO_EVENT_WAIT_UFPT;
                       }
-
-                    // else no update
-                    
-//                     Tdepth_t depth      = (_param->_have_port_depth)?PORT_READ(in_EVENT_DEPTH [i]):0;
-//                     uint32_t top        = reg_UPT_TOP    [i];
-//                     uint32_t bottom     = reg_UPT_BOTTOM [i];
-//                     uint32_t new_update = ((top==0)?_param->_size_upt_queue[i]:top)-1; 
-// //                     bool     empty      = reg_UPT_EMPTY [i];
-
-//                     log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * top        : %d",top);
-//                     log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * depth      : %d",depth);
-//                     log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * new_update : %d",new_update);
-
-//                     event_state_t event_state         = reg_EVENT_STATE [i];
-//                     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     find = false; // have slot to update ???
-//                     Tdepth_t depth_new = depth;
-
-//                     // flush all slot, because this event is in head of rob
-//                     for (uint32_t j=(depth+1)%_param->_size_upt_queue[i];
-//                          //uint32_t j=bottom;
-//                          j!=top; 
-//                          j=(j+1)%_param->_size_upt_queue[i])
-//                       if ((reg_UPDATE_PREDICTION_TABLE [i][j]._state != UPDATE_PREDICTION_STATE_END) and
-//                           (reg_UPDATE_PREDICTION_TABLE [i][j]._state != UPDATE_PREDICTION_STATE_EMPTY))
-//                         {
-//                           find = true;
-//                           reg_UPDATE_PREDICTION_TABLE [i][j]._state = UPDATE_PREDICTION_STATE_EVENT;
-//                           reg_UPDATE_PREDICTION_TABLE [i][j]._retire_ok = false;
-//                         }
-//                       else
-//                         if (not find) // while state == end or empty
-//                           depth_new ++;
-                    
-//                     if ((reg_UPDATE_PREDICTION_TABLE [i][depth]._state != UPDATE_PREDICTION_STATE_END) and
-//                         (reg_UPDATE_PREDICTION_TABLE [i][depth]._state != UPDATE_PREDICTION_STATE_EMPTY))
-//                       {
-//                         find = true;
-//                         reg_UPDATE_PREDICTION_TABLE [i][depth]._state = UPDATE_PREDICTION_STATE_EVENT;
-//                         reg_UPDATE_PREDICTION_TABLE [i][depth]._retire_ok = false;
-
-//                       }
-//                     else
-//                       // while state == end or empty
-//                       depth = (depth_new+1)%_param->_size_upt_queue[i];
-
-//                     log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * find       : %d",find);
-//                     log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * depth_new  : %d",depth_new);
-                    
-//                     // Test if have update slot
-//                     if (find)
-//                       {
-// //                         // flush all slot after the event
-// //                         for (uint32_t j=(depth+1)%_param->_size_upt_queue[i];
-// //                              j!=top; 
-// //                              j=(j+1)%_param->_size_upt_queue[i])
-// //                           reg_UPDATE_PREDICTION_TABLE [i][j]._state = UPDATE_PREDICTION_STATE_EVENT;
-
-// //                         reg_UPDATE_PREDICTION_TABLE [i][depth]._state = UPDATE_PREDICTION_STATE_EVENT;
-                        
-//                         // reg_UPT_BOTTOM    [i];
-//                         // TODO : special case : event is an exception on branch, also depth is not valid
-//                         reg_UPT_TOP       [i] = depth; // depth is again valid
-//                         reg_UPT_TOP_EVENT [i] = top;
-                        
-//                         if (bottom == reg_UPT_TOP [i])
-//                           reg_UPT_EMPTY [i] = true;
-//                       }
-
-//                     bool     full       = ((depth == top) and (top == bottom) and not reg_UPT_EMPTY [i]);
-//                     bool     update_ras = find and ((top != depth) or full);
-                    
-//                     log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * update_ras : %d",update_ras);
-                    
-//                     if (not previous_update_ras and update_ras)
-//                       reg_UPT_UPDATE [i]  = new_update;
-              
-//                     // new state :
-//                     //   * test if ufpt is empty
-//                     //     * ok : flush upft and upt
-//                     //     * ko : test if have previous flush upt
-//                     //            * ok : nothing
-//                     //            * ko : flush upt
-//                     reg_EVENT_VAL     [i] = update_ras;
-//                     reg_EVENT_UPT_PTR [i] = depth;
-
-//                     log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_UFPT_NB_NEED_UPDATE          : %d",reg_UFPT_NB_NEED_UPDATE [i]);
-// //                     if (reg_UFPT_NB_NEED_UPDATE [i] > 0)
-//                     if ( (reg_UFPT_NB_NEED_UPDATE [i] > 0) or
-//                          (reg_UFPT_NB_UPDATE      [i] > 0))
-//                       {
-//                         if (update_ras)
-//                           {
-//                             log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * EVENT [%d] <- EVENT_STATE_EVENT_FLUSH_UFPT_AND_UPT (branch_complete - miss)",i);
-//                             reg_EVENT_STATE [i] = EVENT_STATE_EVENT_FLUSH_UFPT_AND_UPT;
-//                           }
-//                         else
-//                           {
-//                             log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * EVENT [%d] <- EVENT_STATE_EVENT_FLUSH_UFPT (branch_complete - miss)",i);
-// //                          reg_EVENT_VAL   [i] = false;
-
-//                             reg_EVENT_STATE [i] = EVENT_STATE_EVENT_FLUSH_UFPT;
-//                           }                          
-//                       }
-//                     else
-//                       {
-// //                         if (not previous_update_ras)
-//                         if (update_ras)
-//                           {
-//                             // have ras prediction ?
-//                             log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * EVENT [%d] <- EVENT_STATE_EVENT_FLUSH_UPT (branch_complete - miss)",i);
-                            
-//                             reg_EVENT_STATE [i] = EVENT_STATE_EVENT_FLUSH_UPT;
-//                           }
-//                         else
-//                           {
-//                             // special case : nothing
-// //                          reg_EVENT_VAL     [i] = false;
-
-//                             reg_EVENT_STATE [i] = EVENT_STATE_OK;
-//                           }
-//                       }
-
-//                     // else no update
-                    
-//                     reg_EVENT_DEPTH           [i] = depth;
-// //                  reg_EVENT_ADDRESS_SRC     [i] = address_src; // delay_slot is compute in I_State
-// //                  reg_EVENT_ADDRESS_DEST_VAL[i] = good_take;
-// //                  reg_EVENT_ADDRESS_DEST    [i] = good_addr;
 
                     break;
@@ -1135,4 +1018,7 @@
                   }
                 }
+
+              reg_UPT_EVENT_STATE [i] = upt_event_state;
+              log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_UPT_EVENT_STATE : %s (branch_event)",toString(upt_event_state).c_str());
             }
 
@@ -1149,5 +1035,5 @@
                 log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_UFPT_NB_NEED_UPDATE          : %d",reg_UFPT_NB_NEED_UPDATE [i]);
 
-              // It's to accelerate miss speculation
+              // It's to accelerate miss speculation -> associative access
               if (reg_UFPT_NB_NEED_UPDATE [i] == 0)
                 {
@@ -1157,5 +1043,4 @@
                   reg_UFPT_BOTTOM [i] = 0;
                   reg_UFPT_TOP    [i] = 0;
-//                reg_UFPT_UPDATE [i];
                 }
               else
@@ -1176,10 +1061,6 @@
                     }
 
-//                   // TOP is next write slot : last slot is TOP-1
-//                   uint32_t top = reg_UFPT_TOP [i];
-//                   reg_UFPT_UPDATE    [i] = ((top==0)?_param->_size_ufpt_queue[i]:top)-1;
-
-//                reg_UFPT_BOTTOM    [i];
-//                reg_UFPT_TOP       [i];
+                  // Change state
+                  reg_UFPT_EVENT_STATE [i] = UFPT_EVENT_STATE_KO_FLUSH;
                 }
 
@@ -1187,4 +1068,23 @@
 
               }
+
+            // Change state on UPT
+            {
+              upt_event_state_t  upt_event_state  = reg_UPT_EVENT_STATE  [i];
+              ufpt_event_state_t ufpt_event_state = reg_UFPT_EVENT_STATE [i];
+              
+              // Test upt event to change state
+              // test if upt wait ufpt
+              if (ufpt_event_state == UFPT_EVENT_STATE_OK)
+                switch (upt_event_state)
+                  {
+                    // this case when don't need flush upt (miss decod and can continue)
+                  case UPT_EVENT_STATE_KO_MISS_WAIT_UFPT  : upt_event_state = UPT_EVENT_STATE_KO_COMMIT_UPDATE_CONTEXT; break;
+                  case UPT_EVENT_STATE_KO_EVENT_WAIT_UFPT : upt_event_state = UPT_EVENT_STATE_OK               ; break;
+                  default : break;
+                  }
+              
+              reg_UPT_EVENT_STATE [i] = upt_event_state;
+            }
           }
 
@@ -1212,9 +1112,10 @@
       {
         log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_IS_ACCURATE           : %d",reg_IS_ACCURATE        [i]);
-        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_EVENT_VAL             : %d"  ,reg_EVENT_VAL             [i]);
+        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_EVENT_UFPT_STATE      : %s"  ,toString(reg_UFPT_EVENT_STATE [i]).c_str());
+        log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_EVENT_UPT_STATE       : %s"  ,toString(reg_UPT_EVENT_STATE [i]).c_str());
+//         log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_EVENT_VAL             : %d"  ,reg_EVENT_VAL             [i]);
         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_UPT_FULL        : %d"  ,reg_EVENT_UPT_FULL        [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_IS_BRANCH       : %d"  ,reg_EVENT_IS_BRANCH       [i]);
+//         log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_EVENT_IS_BRANCH       : %d"  ,reg_EVENT_IS_BRANCH       [i]);
         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);
@@ -1223,5 +1124,5 @@
         log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * reg_EVENT_CAN_CONTINUE    : %d"  ,reg_EVENT_CAN_CONTINUE    [i]);
 
-	log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * Update_Fetch_Prediction_Table   [%d]",i);
+	log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * Dump UFPT [%d] (Update_Fetch_Prediction_Table)",i);
 	log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * reg_UFPT_BOTTOM         : %d",reg_UFPT_BOTTOM         [i]);
 	log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * reg_UFPT_TOP            : %d",reg_UFPT_TOP            [i]);
@@ -1246,5 +1147,5 @@
                      );
 
-	log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * Update_Prediction_Table   [%d]",i);
+	log_printf(TRACE,Update_Prediction_Table,FUNCTION,"    * Dump UPT [%d] (Update_Prediction_Table)",i);
 	log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * reg_UPT_BOTTOM          : %d",reg_UPT_BOTTOM         [i]);
 	log_printf(TRACE,Update_Prediction_Table,FUNCTION,"      * reg_UPT_TOP             : %d",reg_UPT_TOP            [i]);
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/src/Front_end_deallocation.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/src/Front_end_deallocation.cpp	(revision 120)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/src/Front_end_deallocation.cpp	(revision 122)
@@ -120,6 +120,10 @@
     delete    _component_glue           ;
     delete    _component_context_state  ;
+    for (uint32_t i=0; i<_param->_nb_decod_unit; i++)
+    delete    _component_decod_unit  [i];
     delete [] _component_decod_unit     ;
     delete    _component_prediction_unit;
+    for (uint32_t i=0; i<_param->_nb_context; i++)
+    delete    _component_ifetch_unit [i];
     delete [] _component_ifetch_unit    ;
 
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/src/Parameters.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/src/Parameters.cpp	(revision 120)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/src/Parameters.cpp	(revision 122)
@@ -292,12 +292,12 @@
     log_begin(Front_end,FUNCTION);
     
-    delete [] _param_glue           ;
-    delete [] _param_context_state  ;
+    delete    _param_glue           ;
+    delete    _param_context_state  ;
     for (uint32_t i=0; i<_nb_decod_unit; i++)
-      delete [] _param_decod_unit [i];
+    delete    _param_decod_unit [i];
     delete [] _param_decod_unit     ;
-    delete [] _param_prediction_unit;
+    delete    _param_prediction_unit;
     for (uint32_t i=0; i<_nb_context; i++)
-      delete [] _param_ifetch_unit [i];
+    delete    _param_ifetch_unit [i];
     delete [] _param_ifetch_unit    ;
 
