Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/SelfTest/config_mono_context.cfg
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/SelfTest/config_mono_context.cfg	(revision 94)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/SelfTest/config_mono_context.cfg	(revision 95)
@@ -1,5 +1,5 @@
 Update_Prediction_Table
 1	1	+1	# nb_context             
-4	8	*2	# size_upt_queue         [0] [nb_context]
+4	8	+1	# size_upt_queue         [0] [nb_context]
 1	4	+1	# size_ufpt_queue        [0] [nb_context]
 32	32	*2	# size_address           
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/SelfTest/src/test.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/SelfTest/src/test.cpp	(revision 94)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/SelfTest/src/test.cpp	(revision 95)
@@ -7,6 +7,6 @@
  */
 
-#define NB_ITERATION  8
-#define CYCLE_MAX     (128*NB_ITERATION)
+#define NB_ITERATION  16
+#define CYCLE_MAX     (1024*NB_ITERATION)
 
 #include "Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Update_Prediction_Table/SelfTest/include/test.h"
@@ -136,4 +136,9 @@
   ALLOC1_SC_SIGNAL(out_UPDATE_RAS_INDEX               ,"out_UPDATE_RAS_INDEX               ",Tptr_t             ,_param->_nb_inst_update);
   ALLOC1_SC_SIGNAL(out_UPDATE_RAS_PREDICTION_IFETCH   ,"out_UPDATE_RAS_PREDICTION_IFETCH   ",Tcontrol_t         ,_param->_nb_inst_update);
+
+  ALLOC1_SC_SIGNAL( in_EVENT_STATE                    ," in_EVENT_STATE                    ",Tevent_state_t     ,_param->_nb_context);
+  ALLOC1_SC_SIGNAL( in_EVENT_TYPE                     ," in_EVENT_TYPE                     ",Tevent_type_t      ,_param->_nb_context);
+  ALLOC1_SC_SIGNAL( in_EVENT_DEPTH                    ," in_EVENT_DEPTH                    ",Tdepth_t           ,_param->_nb_context);
+
   ALLOC1_SC_SIGNAL(out_DEPTH_CURRENT                  ,"out_DEPTH_CURRENT                  ",Tdepth_t           ,_param->_nb_context);
   ALLOC1_SC_SIGNAL(out_DEPTH_MIN                      ,"out_DEPTH_MIN                      ",Tdepth_t           ,_param->_nb_context);
@@ -225,6 +230,9 @@
   INSTANCE1_SC_SIGNAL(_Update_Prediction_Table,out_UPDATE_RAS_INDEX               ,_param->_nb_inst_update);
   INSTANCE1_SC_SIGNAL(_Update_Prediction_Table,out_UPDATE_RAS_PREDICTION_IFETCH   ,_param->_nb_inst_update);
+  INSTANCE1_SC_SIGNAL(_Update_Prediction_Table, in_EVENT_STATE                    ,_param->_nb_context);
+  INSTANCE1_SC_SIGNAL(_Update_Prediction_Table, in_EVENT_TYPE                     ,_param->_nb_context);
   if (_param->_have_port_depth)
     {
+  INSTANCE1_SC_SIGNAL(_Update_Prediction_Table, in_EVENT_DEPTH                    ,_param->_nb_context);
   INSTANCE1_SC_SIGNAL(_Update_Prediction_Table,out_DEPTH_CURRENT                  ,_param->_nb_context);
   INSTANCE1_SC_SIGNAL(_Update_Prediction_Table,out_DEPTH_MIN                      ,_param->_nb_context);
@@ -253,7 +261,7 @@
   const  int32_t percent_transaction_branch_event    = 75;
 
-  const bool     test1 = false;
-  const bool     test2 = false;
-  const bool     test3 = false;
+  const bool     test1 = true;
+  const bool     test2 = true;
+  const bool     test3 = true;
   const bool     test4 = true;
 
@@ -270,16 +278,18 @@
   in_NRESET->write(1);  
 
-  Tdepth_t ufpt_bottom [_param->_nb_context];
-  Tdepth_t ufpt_top    [_param->_nb_context];
-
-  Tdepth_t upt_bottom  [_param->_nb_context];
-  Tdepth_t upt_top     [_param->_nb_context];
+  Tdepth_t ufpt_bottom  [_param->_nb_context];
+  Tdepth_t ufpt_top     [_param->_nb_context];
+                       
+  Tdepth_t upt_bottom   [_param->_nb_context];
+  Tdepth_t upt_top      [_param->_nb_context];
+  Tdepth_t upt_top_event[_param->_nb_context];
 
   for (uint32_t i=0; i<_param->_nb_context; ++i)
     {
-      ufpt_bottom [i] = 0;
-      ufpt_top    [i] = 0;
-      upt_bottom  [i] = 0;
-      upt_top     [i] = 0;
+      ufpt_bottom  [i] = 0;
+      ufpt_top     [i] = 0;
+      upt_bottom   [i] = 0;
+      upt_top      [i] = 0;
+      upt_top_event[i] = 0;
     }
 
@@ -305,5 +315,9 @@
       for (uint32_t i=0; i<_param->_nb_inst_update; ++i)
         in_UPDATE_ACK          [i]->write(0);
-
+      for (uint32_t i=0; i<_param->_nb_context; ++i)
+        {
+        in_EVENT_STATE [i]->write(EVENT_STATE_NO_EVENT);
+        in_EVENT_TYPE  [i]->write(EVENT_TYPE_NONE     );
+        }
       //---------------------------------------------------------------------
       //---------------------------------------------------------------------
@@ -913,5 +927,16 @@
           }
         }
-
+ 
+        {
+          LABEL("EVENT_STATE");
+         
+          SC_START(1);
+          in_EVENT_STATE [context]->write(EVENT_STATE_END            );
+          in_EVENT_TYPE  [context]->write(EVENT_TYPE_MISS_SPECULATION);
+
+          SC_START(1);
+          in_EVENT_STATE [context]->write(EVENT_STATE_NO_EVENT       );
+          in_EVENT_TYPE  [context]->write(EVENT_TYPE_NONE            );
+        }
 
         // Wait Garbage Collector
@@ -1337,4 +1362,16 @@
         }
 
+        {
+          LABEL("EVENT_STATE");
+         
+          SC_START(1);
+          in_EVENT_STATE [context]->write(EVENT_STATE_END            );
+          in_EVENT_TYPE  [context]->write(EVENT_TYPE_MISS_SPECULATION);
+
+          SC_START(1);
+          in_EVENT_STATE [context]->write(EVENT_STATE_NO_EVENT       );
+          in_EVENT_TYPE  [context]->write(EVENT_TYPE_NONE            );
+        }
+
         // Wait Garbage Collector
         {
@@ -1378,5 +1415,5 @@
                 request.take_good        = 1;                                              
                 request.flag             = (request.condition == BRANCH_CONDITION_FLAG_SET)?request.take_good:(not request.take_good);
-                request.is_accurate      = false;
+                request.is_accurate      = true ;
                 request.miss_ifetch      = false;
                 request.miss_decod       = false;
@@ -1472,6 +1509,6 @@
                     LABEL("DECOD           [%d] %d - %d",
                           port,
-                          in_PREDICT_VAL [port]->read(),
-                          out_PREDICT_ACK [port]->read());
+                          in_DECOD_VAL [port]->read(),
+                          out_DECOD_ACK [port]->read());
                     
                     if (in_DECOD_VAL [port]->read() and out_DECOD_ACK [port]->read())
@@ -1520,5 +1557,5 @@
                 request.take_good        = 1;                                              
                 request.flag             = (request.condition == BRANCH_CONDITION_FLAG_SET)?request.take_good:(not request.take_good);
-                request.is_accurate      = false;
+                request.is_accurate      = true ;
                 request.miss_ifetch      = false;
                 request.miss_decod       = false;
@@ -1583,5 +1620,5 @@
           std::list<request_t>::iterator it_event;
           {
-            LABEL("BRANCH_COMPLETE - hit ifetch");
+            LABEL("BRANCH_COMPLETE - Miss ifetch");
             
             uint32_t port = rand() % _param->_nb_inst_branch_complete;
@@ -1600,5 +1637,7 @@
 
             if (update_ras(it_event->condition))
-              it_event->address_good = ~(it_event->address_dest);
+              {
+                it_event->address_good = ~(it_event->address_dest);
+              }
             else
               {
@@ -1649,5 +1688,66 @@
 		      TEST(Taddress_t,out_BRANCH_COMPLETE_ADDRESS_DEST   [port]->read(),it_event->address_good);
 
-                      upt_top [it_event->context] = it_event->upt_ptr;
+                      upt_top_event [it_event->context] = upt_top [it_event->context];
+                      upt_top       [it_event->context] = it_event->upt_ptr;
+		    }
+		  
+		  SC_START(1);
+		} while (not have_transaction);
+              
+	      in_BRANCH_COMPLETE_VAL [port]->write(0);
+	      
+              if (_param->_have_port_depth)
+              TEST(Tdepth_t,out_DEPTH_MIN [context]->read(), upt_bottom [context]);
+              TEST(Tdepth_t,out_DEPTH_MAX [context]->read(), upt_top [context]);
+	    }
+          }
+
+          {
+            LABEL("BRANCH_COMPLETE - Hit ifetch");
+            
+            uint32_t port = rand() % _param->_nb_inst_branch_complete;
+            
+            LABEL("  * port    : %d",port);
+            
+            std::list<request_t>::iterator it_upt = upt.begin();
+            
+            while (it_upt != it_event)
+            {
+	      bool have_transaction = false;
+              
+	      do
+		{
+		  in_BRANCH_COMPLETE_VAL        [port]->write((rand()%100)<percent_transaction_branch_complete);
+		  in_BRANCH_COMPLETE_CONTEXT_ID [port]->write(it_upt->context     );
+		  in_BRANCH_COMPLETE_DEPTH      [port]->write(it_upt->upt_ptr     );
+		  in_BRANCH_COMPLETE_ADDRESS    [port]->write(it_upt->address_dest);
+		  in_BRANCH_COMPLETE_FLAG       [port]->write(it_upt->flag        );
+
+                  if (_param->_have_port_depth)
+                  TEST(Tdepth_t,out_DEPTH_MIN [context]->read(), upt_bottom [context]);
+                  TEST(Tdepth_t,out_DEPTH_MAX [context]->read(), upt_top [context]);
+		  
+		  SC_START(0);
+		  
+		  LABEL("BRANCH_COMPLETE [%d] %d - %d.",port,in_BRANCH_COMPLETE_VAL [port]->read(),out_BRANCH_COMPLETE_ACK [port]->read());
+		  
+		  if (in_BRANCH_COMPLETE_VAL [port]->read() and out_BRANCH_COMPLETE_ACK [port]->read())
+		    {
+		      LABEL("BRANCH_COMPLETE [%d] - Transaction accepted",port);
+                      LABEL("  * CONTEXT_ID %d"  ,it_upt->context     );
+                      LABEL("  * DEPTH      %d"  ,it_upt->upt_ptr     );
+                      LABEL("  * CONDITION  %d"  ,it_upt->condition   );
+                      LABEL("  * ADDRESS    %.8x",it_upt->address_dest);
+                      LABEL("  * FLAG       %d"  ,it_upt->flag        );
+
+		      have_transaction = true;
+		      
+		      TEST(Tcontrol_t,out_BRANCH_COMPLETE_MISS_PREDICTION[port]->read(),it_upt->miss_commit );
+		      TEST(Tcontrol_t,out_BRANCH_COMPLETE_TAKE           [port]->read(),it_upt->take        );
+                      it_upt->take_good = it_upt->take;
+		      TEST(Taddress_t,out_BRANCH_COMPLETE_ADDRESS_SRC    [port]->read(),it_upt->address_src );
+		      TEST(Taddress_t,out_BRANCH_COMPLETE_ADDRESS_DEST   [port]->read(),it_upt->address_dest);
+
+                      it_upt++;
 		    }
 		  
@@ -1740,5 +1840,5 @@
 
           {
-            LABEL("UPDATE - upt");
+            LABEL("UPDATE - upt (after event)");
             
             uint32_t port = 0;
@@ -1746,11 +1846,13 @@
             LABEL("  * port    : %d",port);
             std::list<request_t>::iterator it_upt = upt.end();
-            --it_upt;
 
 //             for (uint32_t i=0; i<upt.size(); i++)
-            while (it_upt != it_event)
+            do
               {
+                --it_upt;
+                
                 bool have_transaction = false;
                 
+                if (need_update(it_upt->condition))
                 do
                   {
@@ -1768,12 +1870,22 @@
                       {
                         LABEL("UPDATE [%d] - Transaction accepted",port);
+                        LABEL("  * address_src                : %.8x",it_upt->address_src);
+                        LABEL("  * out_UPDATE_BTB_ADDRESS_SRC : %.8x",out_UPDATE_BTB_ADDRESS_SRC[port]->read());
+
                         have_transaction = true;
                         
+                        bool btb_val = ((it_upt == it_event) and
+                                        (update_btb(it_upt->condition)));
+                        bool dir_val = ((it_upt == it_event) and
+                                        update_dir(it_upt->condition) and 
+                                        not (it_upt->miss_ifetch or it_upt->miss_decod));
+                        bool ras_val = update_ras(it_upt->condition);
+
                         if (_param->_have_port_context_id)
                         TEST(Tcontext_t         ,out_UPDATE_CONTEXT_ID            [port]->read(),it_upt->context);
                         TEST(Tcontrol_t         ,out_UPDATE_MISS_PREDICTION       [port]->read(),it_upt->miss_commit);
-                        TEST(Tcontrol_t         ,out_UPDATE_DIRECTION_GOOD        [port]->read(),it_upt->take_good);
-                        TEST(Tcontrol_t         ,out_UPDATE_BTB_VAL               [port]->read(),update_btb(it_upt->condition));
-                        if (update_btb(it_upt->condition))
+                        TEST(Tcontrol_t         ,out_UPDATE_BTB_VAL               [port]->read(),btb_val);
+
+                        if (btb_val)
                           {
                         TEST(Taddress_t         ,out_UPDATE_BTB_ADDRESS_SRC       [port]->read(),it_upt->address_src);
@@ -1781,11 +1893,15 @@
                         TEST(Tbranch_condition_t,out_UPDATE_BTB_CONDITION         [port]->read(),it_upt->condition);
                           }
-                        TEST(Tcontrol_t         ,out_UPDATE_DIR_VAL               [port]->read(),update_dir(it_upt->condition) and not (it_upt->miss_ifetch or it_upt->miss_decod));
+                        TEST(Tcontrol_t         ,out_UPDATE_DIR_VAL               [port]->read(),dir_val);
                         
-                        if (update_dir(it_upt->condition))
+                        if (dir_val)
+                          {
+                        TEST(Tcontrol_t         ,out_UPDATE_DIRECTION_GOOD        [port]->read(),it_upt->take_good);
                         if (_param->_have_port_history)
                         TEST(Thistory_t         ,out_UPDATE_DIR_HISTORY           [port]->read(),it_upt->history);
-                        TEST(Tcontrol_t         ,out_UPDATE_RAS_VAL               [port]->read(),update_ras(it_upt->condition));
-                        if (update_ras(it_upt->condition))
+                          }
+                        TEST(Tcontrol_t         ,out_UPDATE_RAS_VAL               [port]->read(),ras_val);
+
+                        if (ras_val)
                           {
 //                      TEST(Tcontrol_t         ,out_UPDATE_RAS_FLUSH             [port]->read(),0);
@@ -1796,5 +1912,5 @@
                           }
 
-                        -- it_upt;
+//                         -- it_upt;
                       }
                     
@@ -1808,7 +1924,8 @@
 //               TEST(Tdepth_t,out_DEPTH_MAX [context]->read(), upt_top [context]);
               }
+            while (it_upt != it_event);
+
           }
-//           upt.clear(); // Not yet
-
+          
           {
             LABEL("BRANCH_EVENT - have miss decod");
@@ -1852,11 +1969,24 @@
             }
           }
-          
+
           {
-            LABEL("UPDATE - upt");
+            LABEL("EVENT_STATE");
+            
+            SC_START(1);
+            in_EVENT_STATE [context]->write(EVENT_STATE_END            );
+            in_EVENT_TYPE  [context]->write(EVENT_TYPE_MISS_SPECULATION);
+            
+            SC_START(1);
+            in_EVENT_STATE [context]->write(EVENT_STATE_NO_EVENT       );
+            in_EVENT_TYPE  [context]->write(EVENT_TYPE_NONE            );
+          }
+
+          {
+            LABEL("UPDATE - upt (before event)");
             
             uint32_t port = 0;
             
             LABEL("  * port    : %d",port);
+            LABEL("  * size    : %d",upt.size());
             std::list<request_t>::iterator it_upt = upt.begin();
 
@@ -1908,5 +2038,5 @@
                           }
 
-                        -- it_upt;
+                        ++ it_upt;
                       }
                     
@@ -1920,14 +2050,20 @@
               }
           }
-          upt.clear(); // Not yet
+          upt.clear();
 
           // Wait Garbage Collector
           {
-            upt_bottom [context] = (upt_bottom [context]+1)%_param->_size_upt_queue[context];
-//        upt_top    [context] = (upt_top    [context]);
+            LABEL("GARBAGE COLLECTOR");
+            LABEL(" * upt bottom : %d",upt_bottom [context]);
+            LABEL(" * upt top    : %d",upt_top    [context]);
+
+            upt_top    [context] = (upt_top_event [context]);
+            upt_bottom [context] = (upt_top       [context]);
 
             while ((upt_bottom [context] != out_DEPTH_MIN [context]->read()) or
                    (upt_top    [context] != out_DEPTH_MAX [context]->read()))
-              SC_START(1);
+              {
+                SC_START(1);
+              }
             
           }
@@ -1993,7 +2129,7 @@
   delete [] out_BRANCH_EVENT_VAL            ;
   delete []  in_BRANCH_EVENT_ACK            ;
-//   delete []  in_BRANCH_EVENT_CONTEXT_ID     ;
-//   delete []  in_BRANCH_EVENT_DEPTH          ;
-//   delete [] out_BRANCH_EVENT_MISS_PREDICTION;
+//delete []  in_BRANCH_EVENT_CONTEXT_ID     ;
+//delete []  in_BRANCH_EVENT_DEPTH          ;
+//delete [] out_BRANCH_EVENT_MISS_PREDICTION;
   delete [] out_BRANCH_EVENT_ADDRESS_SRC    ;
   delete [] out_BRANCH_EVENT_ADDRESS_DEST_VAL;
@@ -2019,4 +2155,8 @@
   delete [] out_UPDATE_RAS_PREDICTION_IFETCH;
 
+  DELETE1_SC_SIGNAL( in_EVENT_STATE                    ,_param->_nb_context);
+  DELETE1_SC_SIGNAL( in_EVENT_TYPE                     ,_param->_nb_context);
+  DELETE1_SC_SIGNAL( in_EVENT_DEPTH                    ,_param->_nb_context);
+
   // ~~~~~[ Interface : "depth" ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   delete [] out_DEPTH_CURRENT;
