Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Decod_unit/Decod/Instruction/src/Instruction.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Decod_unit/Decod/Instruction/src/Instruction.cpp	(revision 98)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Decod_unit/Decod/Instruction/src/Instruction.cpp	(revision 100)
@@ -903,6 +903,6 @@
     inst->_type               = instruction_information(INSTRUCTION_L_JALR)._type     ; //TYPE_BRANCH;
     inst->_operation          = instruction_information(INSTRUCTION_L_JALR)._operation; //OPERATION_BRANCH_L_JALR;
-    inst->_has_immediat       = 0;
-    inst->_immediat           = 0; // unnecessary
+    inst->_has_immediat       = 1;
+    inst->_immediat           = inst->_address_next+1;
     inst->_read_ra            = 0;
     inst->_num_reg_ra         = 0; //unnecessary
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Prediction_unit_Glue/SelfTest/config_mono_context.cfg
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Prediction_unit_Glue/SelfTest/config_mono_context.cfg	(revision 98)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Prediction_unit_Glue/SelfTest/config_mono_context.cfg	(revision 100)
@@ -3,5 +3,5 @@
 1	1	*4	# nb_decod_unit      
 30	30	+32	# size_address       
-1	1	*4	# nb_instruction  [0] [nb_context]
+1	4	*2	# nb_instruction  [0] [nb_context]
 1	1	*4	# size_depth      [0] [nb_context]
 4	4	*4	# nb_inst_decod   [0] [nb_decod_unit]
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Prediction_unit_Glue/SelfTest/src/test.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Prediction_unit_Glue/SelfTest/src/test.cpp	(revision 98)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Prediction_unit_Glue/SelfTest/src/test.cpp	(revision 100)
@@ -362,4 +362,8 @@
 
   // Initialisation
+  const bool test1 = false;
+  const bool test2 = true ;
+  const bool test3 = false;
+  const bool test4 = false;
 
   const uint32_t seed = 0;
@@ -402,4 +406,5 @@
       LABEL("Iteration %d",iteration);
 
+      if (test1)
       {
 	LABEL("Test sequential");
@@ -481,4 +486,5 @@
       }
 
+      if (test2)
       {
       	LABEL("Test no sequential - L.J");
@@ -489,11 +495,13 @@
 	for (uint32_t i=0; i<_param->_nb_instruction [context]; i++)
 	  {
-	    Taddress_t addr      = (1<<(_param->_nb_instruction[context]+4));
-	    Taddress_t addr_src  = addr+i;
+	    Taddress_t pc_current  = (1<<(_param->_nb_instruction[context]+3));
+            Taddress_t pc_previous = pc_current-1;
+	    Taddress_t addr_src  = pc_current+i;
 	    Taddress_t addr_dest = 0xdeadbeef;
-	    
-	    in_PREDICT_PC_PREVIOUS           [context]->write(0);
-	    in_PREDICT_PC_CURRENT            [context]->write(addr);
-	    in_PREDICT_PC_CURRENT_IS_DS_TAKE [context]->write(0);
+	    Tcontrol_t is_ds_take= rand()%2;
+
+	    in_PREDICT_PC_PREVIOUS           [context]->write(pc_previous);
+	    in_PREDICT_PC_CURRENT            [context]->write(pc_current);
+	    in_PREDICT_PC_CURRENT_IS_DS_TAKE [context]->write(is_ds_take);
 
 	    bool find = false;
@@ -515,5 +523,5 @@
 		    LABEL(" * BTB address : 0x%x",out_PREDICT_BTB_ADDRESS    [port]->read());
 		    if ((out_PREDICT_BTB_CONTEXT_ID [port]->read() == context) and
-			(out_PREDICT_BTB_ADDRESS    [port]->read() == addr   ))
+			(out_PREDICT_BTB_ADDRESS    [port]->read() == (is_ds_take)?pc_previous:pc_current   ))
 		      {
 			in_PREDICT_BTB_ACK          [port]->write((rand()%100)<percent_transaction_predict);
@@ -531,27 +539,42 @@
 		SC_START(0);
 
+                LABEL ("PREDICT_VAL : %d", in_PREDICT_VAL[context]->read());
+                LABEL ("PREDICT_ACK : %d",out_PREDICT_ACK[context]->read());
+                
 		if (in_PREDICT_VAL[context]->read() and out_PREDICT_ACK[context]->read())
 		  {
 		    LABEL ("PREDICT         [%d] - Transaction accepted",context);
+		    LABEL ("  * pc_previous: 0x%x",pc_previous );
+		    LABEL ("  * pc_current : 0x%x",pc_current      );
+		    LABEL ("  * addr_src   : 0x%x",addr_src  );
+		    LABEL ("  * addr_dest  : 0x%x",addr_dest );
+		    LABEL ("  * is_ds_take : %d"  ,is_ds_take);
+
 		    find = true;
-
-		    TEST(Taddress_t        ,out_PREDICT_PC_NEXT                     [context]->read(),addr_dest);
-		    TEST(Tcontrol_t        ,out_PREDICT_PC_NEXT_IS_DS_TAKE          [context]->read(),i==(_param->_nb_instruction [context]-1));
+                    
+                    Tcontrol_t next_is_ds_take = (not is_ds_take and (i==(_param->_nb_instruction [context]-1)));
+
+                    TEST(Tcontrol_t        ,out_PREDICT_PC_NEXT_IS_DS_TAKE          [context]->read(), next_is_ds_take);
+		    TEST(Taddress_t        ,out_PREDICT_PC_NEXT                     [context]->read(),(next_is_ds_take)?(addr_src+1):addr_dest);
 		    TEST(Tinst_ifetch_ptr_t,out_PREDICT_INST_IFETCH_PTR             [context]->read(),i);
-		    TEST(Tbranch_state_t   ,out_PREDICT_BRANCH_STATE                [context]->read(),BRANCH_STATE_NSPEC_TAKE);
+                    TEST(Tbranch_state_t   ,out_PREDICT_BRANCH_STATE                [context]->read(),(next_is_ds_take)?BRANCH_STATE_NONE:BRANCH_STATE_NSPEC_TAKE);
 // 		    TEST(Tprediction_ptr_t ,out_PREDICT_BRANCH_UPDATE_PREDICTION_ID [context]->read(),0);
 
-		    uint32_t k=((addr_src%_param->_nb_instruction[context])==_param->_nb_instruction[context]-1)?_param->_nb_instruction[context]:((addr_src%_param->_nb_instruction[context])+2);
+		    uint32_t k=((is_ds_take)?1:((next_is_ds_take)?_param->_nb_instruction[context]:((addr_src%_param->_nb_instruction [context])+2)));
+
+
+// ((addr_src%_param->_nb_instruction[context])==_param->_nb_instruction[context]-1)?_param->_nb_instruction[context]:((addr_src%_param->_nb_instruction[context])+2);
+
 		    LABEL("instruction enable : ");
 		    LABEL("  [0:%d[ = 1",k);
-		    LABEL("  [%d:%d[ = 1",k,_param->_nb_instruction[context]);
+		    LABEL("  [%d:%d[ = 0",k,_param->_nb_instruction[context]);
 		    for (uint32_t j=0; j<k; j++)
-		      TEST(Tcontrol_t        ,out_PREDICT_INSTRUCTION_ENABLE [context][j]->read(),1);
+		    TEST(Tcontrol_t        ,out_PREDICT_INSTRUCTION_ENABLE [context][j]->read(),1);
 		    for (uint32_t j=k; j<_param->_nb_instruction[context]; j++)
-		      TEST(Tcontrol_t        ,out_PREDICT_INSTRUCTION_ENABLE [context][j]->read(),0);
+		    TEST(Tcontrol_t        ,out_PREDICT_INSTRUCTION_ENABLE [context][j]->read(),0);
 
 		    TEST(Tcontrol_t        ,out_PREDICT_BTB_VAL        [port]->read(),1); 
 		    TEST(Tcontext_t        ,out_PREDICT_BTB_CONTEXT_ID [port]->read(),context);
-		    TEST(Taddress_t        ,out_PREDICT_BTB_ADDRESS    [port]->read(),addr);
+		    TEST(Taddress_t        ,out_PREDICT_BTB_ADDRESS    [port]->read(),(is_ds_take)?pc_previous:pc_current);
 		  }
 		
@@ -571,5 +594,6 @@
 	  }
       }
-
+      
+      if (test3)
       {
 	LABEL("Decod - Ok");
@@ -618,4 +642,5 @@
       }
 
+      if (test4)
       {
 	LABEL("Decod - Ko");
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Prediction_unit_Glue/src/Prediction_unit_Glue_genMealy_predict.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Prediction_unit_Glue/src/Prediction_unit_Glue_genMealy_predict.cpp	(revision 98)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Prediction_unit_Glue/src/Prediction_unit_Glue_genMealy_predict.cpp	(revision 100)
@@ -27,5 +27,4 @@
     if (PORT_READ(in_NRESET))
       {
-  
     // Init
     Tcontrol_t ack [_param->_nb_context];
@@ -36,5 +35,6 @@
       {
         log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"  * PREDICT [%d]",i);
-
+        
+        // No access
         Tcontrol_t btb_val = false;
         Tcontrol_t dir_val = false;
@@ -42,4 +42,5 @@
         Tcontrol_t upt_val = false;
 
+        // Get ack
         Tcontrol_t btb_ack = PORT_READ(in_PREDICT_BTB_ACK [i]);
         Tcontrol_t dir_ack = PORT_READ(in_PREDICT_DIR_ACK [i]);
@@ -47,11 +48,14 @@
         Tcontrol_t upt_ack = PORT_READ(in_PREDICT_UPT_ACK [i]);
 
+        // Read context_id
         Tcontext_t context = (reg_PREDICT_PRIORITY+i)%_param->_nb_context; // priority
         log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * context    : %d",context);
 
+        // Now : ack transaction
         ack [context] = 1;
 
         if (PORT_READ(in_PREDICT_VAL[context]) == 0)
           {
+            // Nothing
             log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * not valid ...");
 
@@ -63,12 +67,14 @@
         else
           {
+            // Have transaction
             log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * valid ...");
 
+            // Read information (PC)
             Taddress_t          pc_previous           = PORT_READ(in_PREDICT_PC_PREVIOUS           [context]);
             Taddress_t          pc_current            = PORT_READ(in_PREDICT_PC_CURRENT            [context]);
             Tcontrol_t          pc_current_is_ds_take = PORT_READ(in_PREDICT_PC_CURRENT_IS_DS_TAKE [context]);
 
-            log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * pc_previous           : 0x%.8x",pc_previous          );
-            log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * pc_current            : 0x%.8x",pc_current           );
+            log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * pc_previous           : 0x%.8x (0x%.8x)",pc_previous,pc_previous<<2);
+            log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * pc_current            : 0x%.8x (0x%.8x)",pc_current ,pc_current <<2);
             log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * pc_current_is_ds_take : %d"    ,pc_current_is_ds_take);
 
@@ -80,30 +86,35 @@
             
             // STEP (1) - Compute the address source
-            // if pc_current is a ds take, then pc_previous is a branchement
+            //   -> if pc_current is a ds take, then pc_previous is a branchement
+            //      get branchement address to send at the BTB
             Taddress_t          address     = (pc_current_is_ds_take)?pc_previous:pc_current;
+            // Address_lsb = position in fetch packet
             Taddress_t          address_lsb = pc_current%_param->_nb_instruction [context]; //if pc_current_is_ds_take, then pc_current%_param->_nb_instruction [context] == 0
             Taddress_t          address_msb;
 
-            log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * address               : 0x%.8x",address);
+            log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * address               : 0x%.8x (0x%.8x)",address,address<<2);
             log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * address_lsb           : %d"    ,address_lsb);
 
             // STEP (2) - Test if branch (access at branch_target_buffer)
+            // Access at the btb
             btb_val = true;
 
+            // Create the request
             if (_param->_have_port_context_id)
             PORT_WRITE(out_PREDICT_BTB_CONTEXT_ID [i],context);
             PORT_WRITE(out_PREDICT_BTB_ADDRESS    [i],address);
 
+            // Transaction can be ack if btb is not busy
             ack [context] &= btb_ack;
 
             log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * btb_ack               : %d"    ,btb_ack);
 
-            // BTB_ack = 0 ?
+            // BTB_ack = 0 ? else can continue
             if (not btb_ack)
               continue;
 
-            // special case :
-            //  if pc_current_is_ds, then pc_previous have branch, also hit must be set.
-            //  else : a another branch have eject this branch : can't accurate
+            // Test a special case :
+            //  if pc_current is a delay slot, then pc_previous is a branchement instruction, also hit must be set.
+            //  else : an another branch instruction have eject this branch : can't accurate
             Tcontrol_t          hit         = PORT_READ(in_PREDICT_BTB_HIT[i]);
             Tcontrol_t          is_accurate = PORT_READ(in_PREDICT_BTB_IS_ACCURATE  [i]) and not (pc_current_is_ds_take and not hit);
@@ -112,193 +123,214 @@
             log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * is_accurate           : %d"    ,is_accurate);
 
-            // STEP (3) : Test if have branch in the packet
+            // STEP (3) : Test if BTB find a branch instruction in the packet
             if (hit == 1)
               {
+                log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * BTB hit : no sequential order");
+
                 // STEP (3a) : branch - test condition
                 bool                use_dir      = false;
                 bool                use_ras      = false;
                 bool                use_upt      = false;
-                
-                Tbranch_condition_t condition    = PORT_READ(in_PREDICT_BTB_CONDITION    [i]);
-                Taddress_t          address_src  = PORT_READ(in_PREDICT_BTB_ADDRESS_SRC  [i]);
-                Taddress_t          address_dest = PORT_READ(in_PREDICT_BTB_ADDRESS_DEST [i]);
-                Tcontrol_t          push     ;
-                Tcontrol_t          direction;
-
-                log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * condition             : %s"    ,toString(condition).c_str());
-                log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * address_src           : 0x%.8x",address_src);
-                log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * address_dest          : 0x%.8x",address_dest);
-
-                switch (condition)
-                  {
-                  case BRANCH_CONDITION_NONE_WITHOUT_WRITE_STACK          : // l.j
-                    {
-                      // use none unit (dir, upt and ras)
-                      direction    = true;
-                      pc_next      = address_dest;
-                      branch_state = BRANCH_STATE_NSPEC_TAKE;
-                      break;
-                    }
-                  case BRANCH_CONDITION_NONE_WITH_WRITE_STACK             : // l.jal
-                    {
-                      use_upt      = true;
-                      use_ras      = true;
-                      push         = true;
-                      direction    = true;
-                      pc_next      = address_dest;
-                      branch_state = BRANCH_STATE_NSPEC_TAKE;
-                      break;
-                    }
-                  case BRANCH_CONDITION_FLAG_UNSET                        : // l.bnf
-                  case BRANCH_CONDITION_FLAG_SET                          : // l.bf
-                    {
-                      use_upt      = true;
-                      use_dir      = true;
-                      // Test direction
-                      direction = PORT_READ(in_PREDICT_DIR_DIRECTION [i]); // Direction is not the "flag predict" ... also flag_unset and flag_set is the same
-                      if (direction = 1)
-                        {
-                          branch_state = BRANCH_STATE_SPEC_TAKE;
-                          pc_next      = address_dest;
-                        }
-                      else
-                        {
-                          branch_state = BRANCH_STATE_SPEC_NTAKE;
-                          pc_next      = address_src+2; // +1 = delay slot
-                        }
-                      break;
-                    }
-                  case BRANCH_CONDITION_READ_REGISTER_WITHOUT_WRITE_STACK : // l.jr (rb!=9)
-                    {
-                      use_upt      = true;
-                      use_ras      = true;
-                      push         = true;
-                      direction    = true;
-                      pc_next      = address_dest;
-                      branch_state = BRANCH_STATE_SPEC_TAKE;
-                      break;
-                    }
-                  case BRANCH_CONDITION_READ_REGISTER_WITH_WRITE_STACK    : // l.jalr
-                    {
-                      use_upt      = true;
-                      use_ras      = true;
-                      push         = true;
-                      direction    = true;
-                      pc_next      = address_dest;
-                      branch_state = BRANCH_STATE_NSPEC_TAKE;
-                      break;
-                    }
-                  case BRANCH_CONDITION_READ_STACK                        : // l.jr (rb==9)
-                    {
-                      use_upt      = true;
-                      use_ras      = true;
-                      push         = false;
-                      direction    = true;
-                      pc_next      = PORT_READ(in_PREDICT_RAS_ADDRESS_POP  [i]);
-                      branch_state = BRANCH_STATE_SPEC_TAKE;
-                      break;
-                    }
-                  default :
-                    {
-                      ERRORMORPHEO(FUNCTION,"Unknow Condition");
-                      break;
-                    }
-                  }
-
-                if (use_dir)
-                  {
-                    ack[context] &= dir_ack;
-                    PORT_WRITE(out_PREDICT_DIR_ADDRESS_SRC [i], address_src);
-                    PORT_WRITE(out_PREDICT_DIR_STATIC      [i], address_dest<address_src); // if destination is previous : the static direction is take
-//                  PORT_WRITE(out_PREDICT_DIR_LAST_TAKE   [i], PORT_READ(in_PREDICT_BTB_LAST_TAKE [i]));
-                  }
-
-                if (use_ras)
-                  {
-                    ack[context] &= ras_ack;
-                    if (_param->_have_port_context_id)
-                    PORT_WRITE(out_PREDICT_RAS_CONTEXT_ID   [i], context);
-                    PORT_WRITE(out_PREDICT_RAS_PUSH         [i], push); 
-                    PORT_WRITE(out_PREDICT_RAS_ADDRESS_PUSH [i], address_src+2); 
-
-                    is_accurate &= PORT_READ(in_PREDICT_RAS_HIT [i]); // if miss - prediction is not accurate
-                  }
-
-                if (use_upt)
-                  {
-                    ack[context] &= upt_ack;
-                    
-                    if (_param->_have_port_context_id)
-                    PORT_WRITE(out_PREDICT_UPT_CONTEXT_ID       [i],context);
-                    PORT_WRITE(out_PREDICT_UPT_BTB_ADDRESS_SRC  [i],address_src);
-                    PORT_WRITE(out_PREDICT_UPT_BTB_ADDRESS_DEST [i],address_dest);
-                    PORT_WRITE(out_PREDICT_UPT_BTB_CONDITION    [i],condition);
-                    PORT_WRITE(out_PREDICT_UPT_BTB_LAST_TAKE    [i],direction);
-                    PORT_WRITE(out_PREDICT_UPT_BTB_IS_ACCURATE  [i],is_accurate);
-//                  PORT_WRITE(out_PREDICT_UPT_DIR_HISTORY      [i],PORT_READ(in_PREDICT_DIR_HISTORY      [i]));
-                    PORT_WRITE(out_PREDICT_UPT_RAS_ADDRESS      [i],PORT_READ(in_PREDICT_RAS_ADDRESS_POP  [i]));
-//                  PORT_WRITE(out_PREDICT_UPT_RAS_INDEX        [i],PORT_READ(in_PREDICT_RAS_INDEX        [i]));
-                  }
-
-                // ack = 1 if :
-                //   *             btb_ack
-                //   * use_dir and dir_ack
-                //   * use_ras and ras_ack
-                //   * use_upt and upt_ack
-//              ack [context] = (btb_ack and 
-//                               (use_dir and dir_ack) and 
-//                               (use_ras and ras_ack) and 
-//                               (use_upt and upt_ack));
-
-                dir_val = (btb_ack and 
-                           use_dir and
-//                         use_ras and
-//                         use_upt and
-//                         (not use_dir or (use_dir and dir_ack)) and 
-                           (not use_ras or (use_ras and ras_ack)) and 
-                           (not use_upt or (use_upt and upt_ack)));
-
-                ras_val = (btb_ack and 
-//                         use_dir and
-                           use_ras and
-//                         use_upt and
-                           (not use_dir or (use_dir and dir_ack)) and 
-//                         (not use_ras or (use_ras and ras_ack)) and 
-                           (not use_upt or (use_upt and upt_ack)));
-
-                upt_val = (btb_ack and 
-//                         use_dir and
-//                         use_ras and
-                           use_upt and
-                           (not use_dir or (use_dir and dir_ack)) and 
-                           (not use_ras or (use_ras and ras_ack))//  and 
-//                         (not use_upt or (use_upt and upt_ack))
-                           );
-
-//              pc_next      - is previously computed
-//              branch_state - is previously computed
-
-                Taddress_t address_src_lsb  = address_src%_param->_nb_instruction [context];
-
-                log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * address_src     : 0x%x",address_src);
+
+                Taddress_t          address_src      = PORT_READ(in_PREDICT_BTB_ADDRESS_SRC  [i]);
+                Taddress_t          address_src_lsb  = address_src%_param->_nb_instruction [context];
+
+                inst_ifetch_ptr = address_src_lsb;
+
+                log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * address_src     : 0x%.8x (0x%.8x)",address_src,address_src<<2);
                 log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * address_src_lsb : %d",address_src_lsb);
 
-                if (address_src_lsb == (_param->_nb_instruction [context]-1))
+                // Special case :
+                //   * BTB hit and the branchement is the PC current and it's the last slot.
+                //     -> next pc must be the delay slot
+                if ((not pc_current_is_ds_take) and // if pc_current is ds_take, alors pc_next is the destination of branchement
+                    (address_src_lsb == (_param->_nb_instruction [context]-1)))
                   {
                     // branch is in the last slot of the packet
                     log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * branch is in the last slot of the packet");
                 
+                    // Branch is the last slot : next paquet is the delay slot
+                    pc_next            = address_src+1; // sequencial
+                    pc_next_is_ds_take = 1;
                     address_msb        = _param->_nb_instruction [context]; // == (address_src_lsb+1)
-                    pc_next_is_ds_take = 1;
+                    branch_state       = BRANCH_STATE_NONE;
                   }
                 else
                   {
+                    Tbranch_condition_t condition    = PORT_READ(in_PREDICT_BTB_CONDITION    [i]);
+                    Taddress_t          address_dest = PORT_READ(in_PREDICT_BTB_ADDRESS_DEST [i]);
+                    Tcontrol_t          push     ;
+                    Tcontrol_t          direction;
+                    
+                    log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * condition             : %s"    ,toString(condition).c_str());
+                    log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * address_src           : 0x%.8x (0x%.8x)",address_src ,address_src <<2);
+                    log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * address_dest          : 0x%.8x (0x%.8x)",address_dest,address_dest<<2);
+                    
+                    switch (condition)
+                      {
+                      case BRANCH_CONDITION_NONE_WITHOUT_WRITE_STACK          : // l.j
+                        {
+                          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * BRANCH_CONDITION_NONE_WITHOUT_WRITE_STACK");
+                          
+                          // use none unit (dir, upt and ras)
+                          direction    = true;
+                          pc_next      = address_dest;
+                          branch_state = BRANCH_STATE_NSPEC_TAKE;
+                          break;
+                        }
+                      case BRANCH_CONDITION_NONE_WITH_WRITE_STACK             : // l.jal
+                        {
+                          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * BRANCH_CONDITION_NONE_WITH_WRITE_STACK");
+                          
+                          use_upt      = true;
+                          use_ras      = true;
+                          push         = true;
+                          direction    = true;
+                          pc_next      = address_dest;
+                          branch_state = BRANCH_STATE_NSPEC_TAKE;
+                          break;
+                        }
+                      case BRANCH_CONDITION_FLAG_UNSET                        : // l.bnf
+                      case BRANCH_CONDITION_FLAG_SET                          : // l.bf
+                        {
+                          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * BRANCH_CONDITION_FLAG");
+                          
+                          use_upt      = true;
+                          use_dir      = true;
+                          // Test direction
+                          direction = PORT_READ(in_PREDICT_DIR_DIRECTION [i]); // Direction is not the "flag predict" ... also flag_unset and flag_set is the same
+                          if (direction = 1)
+                            {
+                              branch_state = BRANCH_STATE_SPEC_TAKE;
+                              pc_next      = address_dest;
+                            }
+                          else
+                            {
+                              branch_state = BRANCH_STATE_SPEC_NTAKE;
+                              pc_next      = address_src+2; // +1 = delay slot
+                            }
+                          break;
+                        }
+                      case BRANCH_CONDITION_READ_REGISTER_WITHOUT_WRITE_STACK : // l.jr (rb!=9)
+                        {
+                          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * BRANCH_CONDITION_READ_REGISTER_WITHOUT_WRITE_STACK");
+                          
+                          use_upt      = true;
+                          use_ras      = true;
+                          push         = true;
+                          direction    = true;
+                          pc_next      = address_dest;
+                          branch_state = BRANCH_STATE_SPEC_TAKE;
+                          break;
+                        }
+                      case BRANCH_CONDITION_READ_REGISTER_WITH_WRITE_STACK    : // l.jalr
+                        {
+                          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * BRANCH_CONDITION_READ_REGISTER_WITH_WRITE_STACK");
+                          
+                          use_upt      = true;
+                          use_ras      = true;
+                          push         = true;
+                          direction    = true;
+                          pc_next      = address_dest;
+                          branch_state = BRANCH_STATE_NSPEC_TAKE;
+                          break;
+                        }
+                      case BRANCH_CONDITION_READ_STACK                        : // l.jr (rb==9)
+                        {
+                          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * BRANCH_CONDITION_READ_STACK");
+                          use_upt      = true;
+                          use_ras      = true;
+                          push         = false;
+                          direction    = true;
+                          pc_next      = PORT_READ(in_PREDICT_RAS_ADDRESS_POP  [i]);
+                          branch_state = BRANCH_STATE_SPEC_TAKE;
+                          break;
+                        }
+                      default :
+                        {
+                          ERRORMORPHEO(FUNCTION,"Unknow Condition");
+                          break;
+                        }
+                      }
+                    
+                    if (use_dir)
+                      {
+                        ack[context] &= dir_ack;
+                        PORT_WRITE(out_PREDICT_DIR_ADDRESS_SRC [i], address_src);
+                        PORT_WRITE(out_PREDICT_DIR_STATIC      [i], address_dest<address_src); // if destination is previous : the static direction is take
+//                      PORT_WRITE(out_PREDICT_DIR_LAST_TAKE   [i], PORT_READ(in_PREDICT_BTB_LAST_TAKE [i]));
+                      }
+                    
+                    if (use_ras)
+                      {
+                        ack[context] &= ras_ack;
+                        if (_param->_have_port_context_id)
+                        PORT_WRITE(out_PREDICT_RAS_CONTEXT_ID   [i], context);
+                        PORT_WRITE(out_PREDICT_RAS_PUSH         [i], push); 
+                        PORT_WRITE(out_PREDICT_RAS_ADDRESS_PUSH [i], address_src+2); 
+                        
+                        is_accurate &= PORT_READ(in_PREDICT_RAS_HIT [i]); // if miss - prediction is not accurate
+                      }
+                    
+                    if (use_upt)
+                      {
+                        ack[context] &= upt_ack;
+                        
+                        if (_param->_have_port_context_id)
+                        PORT_WRITE(out_PREDICT_UPT_CONTEXT_ID       [i],context);
+                        PORT_WRITE(out_PREDICT_UPT_BTB_ADDRESS_SRC  [i],address_src);
+                        PORT_WRITE(out_PREDICT_UPT_BTB_ADDRESS_DEST [i],address_dest);
+                        PORT_WRITE(out_PREDICT_UPT_BTB_CONDITION    [i],condition);
+                        PORT_WRITE(out_PREDICT_UPT_BTB_LAST_TAKE    [i],direction);
+                        PORT_WRITE(out_PREDICT_UPT_BTB_IS_ACCURATE  [i],is_accurate);
+//                      PORT_WRITE(out_PREDICT_UPT_DIR_HISTORY      [i],PORT_READ(in_PREDICT_DIR_HISTORY      [i]));
+                        PORT_WRITE(out_PREDICT_UPT_RAS_ADDRESS      [i],PORT_READ(in_PREDICT_RAS_ADDRESS_POP  [i]));
+//                      PORT_WRITE(out_PREDICT_UPT_RAS_INDEX        [i],PORT_READ(in_PREDICT_RAS_INDEX        [i]));
+                      }
+                    
+                    // ack = 1 if :
+                    //   *             btb_ack
+                    //   * use_dir and dir_ack
+                    //   * use_ras and ras_ack
+                    //   * use_upt and upt_ack
+//                  ack [context] = (btb_ack and 
+//                                   (use_dir and dir_ack) and 
+//                                   (use_ras and ras_ack) and 
+//                                   (use_upt and upt_ack));
+
+                    dir_val = (btb_ack and 
+                               use_dir and
+//                             use_ras and
+//                             use_upt and
+//                             (not use_dir or (use_dir and dir_ack)) and 
+                               (not use_ras or (use_ras and ras_ack)) and 
+                               (not use_upt or (use_upt and upt_ack)));
+                    
+                    ras_val = (btb_ack and 
+//                             use_dir and
+                               use_ras and
+//                             use_upt and
+                               (not use_dir or (use_dir and dir_ack)) and 
+//                             (not use_ras or (use_ras and ras_ack)) and 
+                               (not use_upt or (use_upt and upt_ack)));
+                    
+                    upt_val = (btb_ack and 
+//                             use_dir and
+//                             use_ras and
+                               use_upt and
+                               (not use_dir or (use_dir and dir_ack)) and 
+                               (not use_ras or (use_ras and ras_ack))//  and 
+//                             (not use_upt or (use_upt and upt_ack))
+                               );
+                    
+//                  pc_next      - is previously computed
+//                  branch_state - is previously computed
+
+
                     // branch is in the last slot of the packet
                     address_msb        = (address_src_lsb+2); // +1 == delayed slot
                     pc_next_is_ds_take = 0;
                   }
-                log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * address_msb     : %d",address_msb);
-
-                inst_ifetch_ptr             = address_src_lsb;
+
 //              branch_update_prediction_id = (_param->_have_port_depth)?((PORT_READ(in_DEPTH_UPT_TAIL[context])+PORT_READ(in_DEPTH_UPT_NB_BRANCH [context]))%_param->_array_size_depth[context]):0;
               }
@@ -308,5 +340,6 @@
                 log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * BTB miss : sequential order");
 
-                pc_next                     = address-address_lsb+_param->_nb_instruction [context]; // sequencial
+                // Take the address packet base and add new packet
+                pc_next                     = pc_current-address_lsb+_param->_nb_instruction [context]; // sequencial
                 pc_next_is_ds_take          = 0; // no branch, also no delay slot
                 inst_ifetch_ptr             = 0;
@@ -316,28 +349,35 @@
                 address_msb = _param->_nb_instruction [context];
               }
-              
-              PORT_WRITE(out_PREDICT_PC_NEXT                     [context]   , pc_next                    );
-              PORT_WRITE(out_PREDICT_PC_NEXT_IS_DS_TAKE          [context]   , pc_next_is_ds_take         );
-
-              Taddress_t address_limit_min = address_lsb;
-              Taddress_t address_limit_max = ((pc_current_is_ds_take)?(address_lsb+1):address_msb);
-
-              log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * instruction enable :");
-              log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * nb_inst : %d",_param->_nb_instruction [context]);
-              log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * [0:%d[ = 0" ,address_limit_min);
-              log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * [%d:%d[ = 1",address_limit_min,address_limit_max);
-              log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * [%d:%d[ = 0",address_limit_max,_param->_nb_instruction [context]);
-
-              for (uint32_t j=0; j<address_limit_min; j++)
-              PORT_WRITE(out_PREDICT_INSTRUCTION_ENABLE          [context][j], 0); // Before the address : not valid
-              for (uint32_t j=address_limit_min; j<address_limit_max; j++)
-              PORT_WRITE(out_PREDICT_INSTRUCTION_ENABLE          [context][j], 1); // Vald packet
-              for (uint32_t j=address_limit_max; j<_param->_nb_instruction [context]; j++)
-              PORT_WRITE(out_PREDICT_INSTRUCTION_ENABLE          [context][j], 0); // After last address (branch) : not valid
-              if (_param->_have_port_inst_ifetch_ptr)
-              PORT_WRITE(out_PREDICT_INST_IFETCH_PTR             [context]   , inst_ifetch_ptr            );
-              PORT_WRITE(out_PREDICT_BRANCH_STATE                [context]   , branch_state               );
-              if (_param->_have_port_depth)
-              PORT_WRITE(out_PREDICT_BRANCH_UPDATE_PREDICTION_ID [context]   , PORT_READ(in_PREDICT_UPT_BRANCH_UPDATE_PREDICTION_ID [i]));
+
+            log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * address_msb           : %d",address_msb);
+            log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * pc_next               : 0x%.8x (0x%.8x)",pc_next,pc_next<<2);
+            log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * pc_next_is_ds_take    : %d"    ,pc_next_is_ds_take);
+            
+            // Write Output
+            PORT_WRITE(out_PREDICT_PC_NEXT                     [context]   , pc_next                    );
+            PORT_WRITE(out_PREDICT_PC_NEXT_IS_DS_TAKE          [context]   , pc_next_is_ds_take         );
+
+            // Create enable mask
+            Taddress_t address_limit_min = address_lsb;
+            Taddress_t address_limit_max = ((pc_current_is_ds_take)?(address_lsb+1):address_msb);
+
+            log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * instruction enable :");
+            log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * nb_inst : %d",_param->_nb_instruction [context]);
+            log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * [0:%d[ = 0" ,address_limit_min);
+            log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * [%d:%d[ = 1",address_limit_min,address_limit_max);
+            log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * [%d:%d[ = 0",address_limit_max,_param->_nb_instruction [context]);
+
+            for (uint32_t j=0; j<address_limit_min; j++)
+            PORT_WRITE(out_PREDICT_INSTRUCTION_ENABLE          [context][j], 0); // Before the address : not valid
+            for (uint32_t j=address_limit_min; j<address_limit_max; j++)
+            PORT_WRITE(out_PREDICT_INSTRUCTION_ENABLE          [context][j], 1); // Valid packet
+            for (uint32_t j=address_limit_max; j<_param->_nb_instruction [context]; j++)
+            PORT_WRITE(out_PREDICT_INSTRUCTION_ENABLE          [context][j], 0); // After last address (branch) : not valid
+
+            if (_param->_have_port_inst_ifetch_ptr)
+            PORT_WRITE(out_PREDICT_INST_IFETCH_PTR             [context]   , inst_ifetch_ptr            );
+            PORT_WRITE(out_PREDICT_BRANCH_STATE                [context]   , branch_state               );
+            if (_param->_have_port_depth)
+            PORT_WRITE(out_PREDICT_BRANCH_UPDATE_PREDICTION_ID [context]   , PORT_READ(in_PREDICT_UPT_BRANCH_UPDATE_PREDICTION_ID [i]));
           }
 
@@ -348,5 +388,6 @@
         PORT_WRITE(out_PREDICT_UPT_VAL [i], upt_val);
       }
-
+    
+    // Write output
     for (uint32_t i=0; i<_param->_nb_context; i++)
       PORT_WRITE(out_PREDICT_ACK[i],ack[i]);
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/SelfTest/src/test.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/SelfTest/src/test.cpp	(revision 98)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/SelfTest/src/test.cpp	(revision 100)
@@ -125,5 +125,9 @@
 
   // Initialisation
-
+  const bool test1 = true;
+  const bool test2 = true;
+  const bool test3 = true;
+  const bool test4 = true;
+  
   const uint32_t seed = 0;
 //const uint32_t seed = static_cast<uint32_t>(time(NULL));
@@ -144,275 +148,447 @@
     {
       LABEL("Iteration %d",iteration);
-
-      if (1)
+      
+      if (test1)
 	{
-	uint32_t port = rand()%_param->_nb_inst_predict;
-
-	LABEL("PREDICT - PUSH");
+          uint32_t port = rand()%_param->_nb_inst_predict;
+          
+          LABEL("PREDICT - PUSH");
+          
+          in_PREDICT_VAL  [port]->write(1);
+          in_PREDICT_PUSH [port]->write(1);
+          
+          for (uint32_t i=0; i<_param->_nb_context; i++)
+            for (uint32_t j=0; j<_param->_size_queue[i]; j++)
+              {
+                in_PREDICT_CONTEXT_ID   [port]->write(i);
+                in_PREDICT_ADDRESS_PUSH [port]->write(0xdeadbeef+j);
+                
+                SC_START(0);
+                
+                TEST(Tcontrol_t, out_PREDICT_ACK  [port]->read(), 1);
+                TEST(Tptr_t    , out_PREDICT_INDEX[port]->read(),(j+1)%_param->_size_queue[i]);
+                
+                SC_START(1);
+                
+              }
+          in_PREDICT_VAL [port]->write(0);
+          
+          SC_START(1);
+          
+          in_PREDICT_VAL  [port]->write(1);
+          in_PREDICT_PUSH [port]->write(1);
+          for (uint32_t i=0; i<_param->_nb_context; i++)
+            for (uint32_t j=0; j<_param->_size_queue[i]; j++)
+              {
+                in_PREDICT_CONTEXT_ID   [port]->write(i);
+                in_PREDICT_ADDRESS_PUSH [port]->write(0x21071981+j);
+                
+                SC_START(0);
+                
+                TEST(Tcontrol_t, out_PREDICT_ACK        [port]->read(), 1);
+                TEST(Tptr_t    , out_PREDICT_INDEX      [port]->read(),(j+1)%_param->_size_queue[i]);
+                TEST(Taddress_t, out_PREDICT_ADDRESS_POP[port]->read(),0xdeadbeef+j);
+                
+                SC_START(1);
+              }
+          in_PREDICT_VAL [port]->write(0);
+          
+          LABEL("PREDICT - POP");
+          
+          in_PREDICT_VAL  [port]->write(1);
+          in_PREDICT_PUSH [port]->write(0);
+          for (uint32_t i=0; i<_param->_nb_context; i++)
+            for (uint32_t j=0; j< _param->_size_queue[i]; j++)
+              {
+                in_PREDICT_CONTEXT_ID   [port]->write(i);
+                in_PREDICT_ADDRESS_PUSH [port]->write(0xbabedead);
+                
+                SC_START(0);
+                
+                TEST(Tcontrol_t, out_PREDICT_ACK        [port]->read(), 1);
+                TEST(Tcontrol_t, out_PREDICT_HIT        [port]->read(), 1);
+                uint32_t k=(_param->_size_queue[i]-j)%_param->_size_queue[i];
+                TEST(Tptr_t    , out_PREDICT_INDEX      [port]->read(), k);
+                TEST(Taddress_t, out_PREDICT_ADDRESS_POP[port]->read(),(0x21071981+((k==0)?(_param->_size_queue[i]-1):(k-1))));
+                
+                SC_START(1);
+              }
+          in_PREDICT_VAL [port]->write(0);
+
+          // Now, the stack is empty
+        }
+
+      if (test2)
+	{
+          uint32_t port = rand()%_param->_nb_inst_decod;
+          
+          LABEL("DECOD - without predict");
+          
+          LABEL("DECOD - PUSH");  
+          
+          in_DECOD_VAL             [port]->write(1);
+          in_DECOD_PUSH            [port]->write(1);
+          in_DECOD_MISS_PREDICTION [port]->write(0);
+          
+          for (uint32_t i=0; i<_param->_nb_context; i++)
+            for (uint32_t j=0; j<_param->_size_queue[i]; j++)
+              {
+                in_DECOD_CONTEXT_ID   [port]->write(i);
+                in_DECOD_ADDRESS_PUSH [port]->write(0xbeefcaca+j);
+                
+                SC_START(0);
+                
+                TEST(Tcontrol_t, out_DECOD_ACK  [port]->read(), 1);
+                TEST(Tptr_t    , out_DECOD_INDEX[port]->read(),(j+1)%_param->_size_queue[i]);
+                
+                SC_START(1);
+                
+              }
+          in_DECOD_VAL [port]->write(0);
 	
-	in_PREDICT_VAL  [port]->write(1);
-	in_PREDICT_PUSH [port]->write(1);
-	for (uint32_t i=0; i<_param->_nb_context; i++)
-	  for (uint32_t j=0; j<_param->_size_queue[i]; j++)
-	    {
-	      in_PREDICT_CONTEXT_ID   [port]->write(i);
-	      in_PREDICT_ADDRESS_PUSH [port]->write(0xdeadbeef+j);
-	      
-	      SC_START(0);
-	      
-	      TEST(Tcontrol_t, out_PREDICT_ACK  [port]->read(), 1);
-	      TEST(Tptr_t    , out_PREDICT_INDEX[port]->read(),(j+1)%_param->_size_queue[i]);
-	      
-	      SC_START(1);
-	      
-	    }
-	in_PREDICT_VAL [port]->write(0);
-	
-	SC_START(1);
-	
-	in_PREDICT_VAL  [port]->write(1);
-	in_PREDICT_PUSH [port]->write(1);
-	for (uint32_t i=0; i<_param->_nb_context; i++)
-	  for (uint32_t j=0; j<_param->_size_queue[i]; j++)
-	    {
-	      in_PREDICT_CONTEXT_ID   [port]->write(i);
-	      in_PREDICT_ADDRESS_PUSH [port]->write(0x21071981+j);
-	      
-	      SC_START(0);
-	      
-	      TEST(Tcontrol_t, out_PREDICT_ACK        [port]->read(), 1);
-	      TEST(Tptr_t    , out_PREDICT_INDEX      [port]->read(),(j+1)%_param->_size_queue[i]);
-	      TEST(Taddress_t, out_PREDICT_ADDRESS_POP[port]->read(),0xdeadbeef+j);
-	      
-	      SC_START(1);
-	    }
-	in_PREDICT_VAL [port]->write(0);
-	
-	LABEL("PREDICT - POP");
-	
-	in_PREDICT_VAL  [port]->write(1);
-	in_PREDICT_PUSH [port]->write(0);
-	for (uint32_t i=0; i<_param->_nb_context; i++)
-	  for (uint32_t j=0; j< _param->_size_queue[i]; j++)
-	    {
-	      in_PREDICT_CONTEXT_ID   [port]->write(i);
-	      in_PREDICT_ADDRESS_PUSH [port]->write(0xbabedead);
-	      
-	      SC_START(0);
-	      
-	      TEST(Tcontrol_t, out_PREDICT_ACK        [port]->read(), 1);
-	      TEST(Tcontrol_t, out_PREDICT_HIT        [port]->read(), 1);
-	      uint32_t k=(_param->_size_queue[i]-j)%_param->_size_queue[i];
-	      TEST(Tptr_t    , out_PREDICT_INDEX      [port]->read(), k);
-	      TEST(Taddress_t, out_PREDICT_ADDRESS_POP[port]->read(),(0x21071981+((k==0)?(_param->_size_queue[i]-1):(k-1))));
-	      
-	      SC_START(1);
-	    }
-	in_PREDICT_VAL [port]->write(0);
-	}
-
-      // Now, the stack is empty
-
-      if (1)
-	{
-	uint32_t port1 = rand()%_param->_nb_inst_decod;
-	uint32_t port2 = rand()%_param->_nb_inst_predict;
-
-	LABEL("DECOD - without predict");
-	
-	LABEL("DECOD - PUSH");  
-	
-	in_DECOD_VAL             [port1]->write(1);
-	in_DECOD_PUSH            [port1]->write(1);
-	in_DECOD_MISS_PREDICTION [port1]->write(0);
-	
-	for (uint32_t i=0; i<_param->_nb_context; i++)
-	  for (uint32_t j=0; j<_param->_size_queue[i]; j++)
-	    {
-	      in_DECOD_CONTEXT_ID   [port1]->write(i);
-	      in_DECOD_ADDRESS_PUSH [port1]->write(0xbeefcaca+j);
-	      
-	      SC_START(0);
-	      
-	      TEST(Tcontrol_t, out_DECOD_ACK  [port1]->read(), 1);
-	      TEST(Tptr_t    , out_DECOD_INDEX[port1]->read(),(j+1)%_param->_size_queue[i]);
-	      
-	      SC_START(1);
-	      
-	    }
-	in_DECOD_VAL [port1]->write(0);
-	
-	SC_START(1);
-	
-	in_DECOD_VAL  [port1]->write(1);
-	in_DECOD_PUSH [port1]->write(1);
-	for (uint32_t i=0; i<_param->_nb_context; i++)
-	  for (uint32_t j=0; j<_param->_size_queue[i]; j++)
-	    {
-	      in_DECOD_CONTEXT_ID   [port1]->write(i);
-	      in_DECOD_ADDRESS_PUSH [port1]->write(0x21071981+j);
-	      
-	      SC_START(0);
-	      
-	      TEST(Tcontrol_t, out_DECOD_ACK        [port1]->read(), 1);
-	      TEST(Tptr_t    , out_DECOD_INDEX      [port1]->read(),(j+1)%_param->_size_queue[i]);
-	      TEST(Taddress_t, out_DECOD_ADDRESS_POP[port1]->read(),0xbeefcaca+j);
-	      
-	      SC_START(1);
-	    }
-	in_DECOD_VAL [port1]->write(0);
-	
-	LABEL("DECOD - POP");
-	
-	in_DECOD_VAL  [port1]->write(1);
-	in_DECOD_PUSH [port1]->write(0);
-	for (uint32_t i=0; i<_param->_nb_context; i++)
-	  for (uint32_t j=0; j< _param->_size_queue[i]; j++)
-	    {
-	      in_DECOD_CONTEXT_ID   [port1]->write(i);
-	      in_DECOD_ADDRESS_PUSH [port1]->write(0xbabedead);
-	      
-	      SC_START(0);
-	      
-	      TEST(Tcontrol_t, out_DECOD_ACK        [port1]->read(), 1);
-	      TEST(Tcontrol_t, out_DECOD_HIT        [port1]->read(), 1);
-	      uint32_t k=(_param->_size_queue[i]-j)%_param->_size_queue[i];
-	      TEST(Tptr_t    , out_DECOD_INDEX      [port1]->read(), k);
-	      TEST(Taddress_t, out_DECOD_ADDRESS_POP[port1]->read(),(0x21071981+((k==0)?(_param->_size_queue[i]-1):(k-1))));
-	      
-	      SC_START(1);
-	    }
-	in_DECOD_VAL [port1]->write(0);
-
-	LABEL("DECOD - with predict");
-	
-	LABEL("DECOD - PUSH (size_queue/2)");  
-	
-	in_DECOD_VAL             [port1]->write(1);
-	in_DECOD_PUSH            [port1]->write(1);
-	in_DECOD_MISS_PREDICTION [port1]->write(1);
-	
-	for (uint32_t i=0; i<_param->_nb_context; i++)
-	  for (uint32_t j=0; j<_param->_size_queue[i]/2;j++)
-	    {
-	      in_DECOD_CONTEXT_ID   [port1]->write(i);
-	      in_DECOD_ADDRESS_PUSH [port1]->write(0x01234567+j);
-	      
-	      SC_START(0);
-	      
-	      TEST(Tcontrol_t, out_DECOD_ACK  [port1]->read(), 1);
-	      TEST(Tptr_t    , out_DECOD_INDEX[port1]->read(),(j+1)%_param->_size_queue[i]);
-	      
-	      SC_START(1);
-	      
-	    }
-	in_DECOD_VAL [port1]->write(0);
-
-	LABEL("PREDICT - PUSH (size_queue/2)");  
-	
-	in_PREDICT_VAL             [port2]->write(1);
-	in_PREDICT_PUSH            [port2]->write(1);
-	
-	for (uint32_t i=0; i<_param->_nb_context; i++)
-	  for (uint32_t j=0; j<_param->_size_queue[i]/2;j++)
-	    {
-	      in_PREDICT_CONTEXT_ID   [port2]->write(i);
-	      in_PREDICT_ADDRESS_PUSH [port2]->write((0x89abcdef+j)+(_param->_size_queue[i]/2));
-	      
-	      SC_START(0);
-	      
-	      TEST(Tcontrol_t, out_PREDICT_ACK  [port2]->read(), 1);
-	      TEST(Tptr_t    , out_PREDICT_INDEX[port2]->read(),(j+1+(_param->_size_queue[i]/2))%_param->_size_queue[i]);
-	      
-	      SC_START(1);
-	    }
-
-	in_PREDICT_VAL [port2]->write(0);
-
-	LABEL("PREDICT - POP (size_queue/2)");  
-
-	in_PREDICT_VAL  [port2]->write(1);
-	in_PREDICT_PUSH [port2]->write(0);
-	for (uint32_t i=0; i<_param->_nb_context; i++)
-	  {
-	    for (uint32_t j=0; j< _param->_size_queue[i]/2; j++)
-	      {
-		in_PREDICT_CONTEXT_ID   [port2]->write(i);
-		in_PREDICT_ADDRESS_PUSH [port2]->write(0xbabedead);
-		
-		SC_START(0);
-		
-		TEST(Tcontrol_t, out_PREDICT_ACK        [port2]->read(), 1);
-		TEST(Tcontrol_t, out_PREDICT_HIT        [port2]->read(), 1);
-		uint32_t k=  (_param->_size_queue[i]-j)%_param->_size_queue[i];
-		TEST(Tptr_t    , out_PREDICT_INDEX      [port2]->read(), k);
-
-		Taddress_t res = (0x89abcdef+((k==0)?(_param->_size_queue[i]-1):(k-1)));
-		LABEL("k      : %d",k);
-		LABEL("res    : %x",res);
-		LABEL("@_pop  : %x",out_PREDICT_ADDRESS_POP[port2]->read());
-
-		TEST(Taddress_t, out_PREDICT_ADDRESS_POP[port2]->read(),res);
-		
-		SC_START(1);
-	      }
-
-	    for (uint32_t j=0; j< _param->_size_queue[i]/2; j++)
-	      {
-		in_PREDICT_CONTEXT_ID   [port2]->write(i);
-		in_PREDICT_ADDRESS_PUSH [port2]->write(0xbabedead);
-		
-		SC_START(0);
-		
-		TEST(Tcontrol_t, out_PREDICT_ACK        [port2]->read(), 1);
-		TEST(Tcontrol_t, out_PREDICT_HIT        [port2]->read(), 1);
-		uint32_t k=(_param->_size_queue[i]/2-j)%_param->_size_queue[i];
-		TEST(Tptr_t    , out_PREDICT_INDEX      [port2]->read(), k);
-
-		Taddress_t res = (0x01234567+((k==0)?(_param->_size_queue[i]/2-1):(k-1)));
-
-		LABEL("k      : %d",k);
-		LABEL("res    : %x",res);
-		LABEL("@_pop  : %x",out_PREDICT_ADDRESS_POP[port2]->read());
-
-		TEST(Taddress_t, out_PREDICT_ADDRESS_POP[port2]->read(),res);
-		
-		SC_START(1);
-	      }
-	  }
-
-	in_PREDICT_VAL [port2]->write(0);
-
-	in_DECOD_VAL  [port1]->write(1);
-	in_DECOD_PUSH [port1]->write(0);
-	in_DECOD_MISS_PREDICTION [port1]->write(0);
-
-	for (uint32_t i=0; i<_param->_nb_context; i++)
-	  {
-	    for (uint32_t j=0; j< _param->_size_queue[i]/2; j++)
-	      {
-		in_DECOD_CONTEXT_ID   [port1]->write(i);
-		in_DECOD_ADDRESS_PUSH [port1]->write(0xbabedead);
-		
-		SC_START(0);
-		
-		TEST(Tcontrol_t, out_DECOD_ACK        [port1]->read(), 1);
-		TEST(Tcontrol_t, out_DECOD_HIT        [port1]->read(), 1);
-		uint32_t k=(_param->_size_queue[i]/2-j)%_param->_size_queue[i];
-		TEST(Tptr_t    , out_DECOD_INDEX      [port1]->read(), k);
-
-		Taddress_t res = (0x01234567+((k==0)?(_param->_size_queue[i]/2-1):(k-1)));
-
-		LABEL("k      : %d",k);
-		LABEL("res    : %x",res);
-		LABEL("@_pop  : %x",out_DECOD_ADDRESS_POP[port1]->read());
-
-		TEST(Taddress_t, out_DECOD_ADDRESS_POP[port1]->read(),res);
-		
-		SC_START(1);
-	      }
-	  }
-
-	in_DECOD_VAL [port1]->write(0);
+          SC_START(1);
+          
+          in_DECOD_VAL  [port]->write(1);
+          in_DECOD_PUSH [port]->write(1);
+          for (uint32_t i=0; i<_param->_nb_context; i++)
+            for (uint32_t j=0; j<_param->_size_queue[i]; j++)
+              {
+                in_DECOD_CONTEXT_ID   [port]->write(i);
+                in_DECOD_ADDRESS_PUSH [port]->write(0x21071981+j);
+                
+                SC_START(0);
+                
+                TEST(Tcontrol_t, out_DECOD_ACK        [port]->read(), 1);
+                TEST(Tptr_t    , out_DECOD_INDEX      [port]->read(),(j+1)%_param->_size_queue[i]);
+                TEST(Taddress_t, out_DECOD_ADDRESS_POP[port]->read(),0xbeefcaca+j);
+                
+                SC_START(1);
+              }
+          in_DECOD_VAL [port]->write(0);
+          
+          LABEL("DECOD - POP");
+          
+          in_DECOD_VAL  [port]->write(1);
+          in_DECOD_PUSH [port]->write(0);
+          for (uint32_t i=0; i<_param->_nb_context; i++)
+            for (uint32_t j=0; j< _param->_size_queue[i]; j++)
+              {
+                in_DECOD_CONTEXT_ID   [port]->write(i);
+                in_DECOD_ADDRESS_PUSH [port]->write(0xbabedead);
+                
+                SC_START(0);
+                
+                TEST(Tcontrol_t, out_DECOD_ACK        [port]->read(), 1);
+                TEST(Tcontrol_t, out_DECOD_HIT        [port]->read(), 1);
+                uint32_t k=(_param->_size_queue[i]-j)%_param->_size_queue[i];
+                TEST(Tptr_t    , out_DECOD_INDEX      [port]->read(), k);
+                TEST(Taddress_t, out_DECOD_ADDRESS_POP[port]->read(),(0x21071981+((k==0)?(_param->_size_queue[i]-1):(k-1))));
+                
+                SC_START(1);
+              }
+          in_DECOD_VAL [port]->write(0);
+          // Now, the stack is empty
+        }
+
+      if (test3)
+        {
+          uint32_t port1 = rand()%_param->_nb_inst_predict;
+          uint32_t port2 = rand()%_param->_nb_inst_decod;
+          uint32_t port3 = rand()%_param->_nb_inst_update;
+
+          LABEL("Test UPDATE");
+
+          LABEL("Predict");
+          in_PREDICT_VAL  [port1]->write(1);
+          in_PREDICT_PUSH [port1]->write(1);
+          for (uint32_t i=0; i<_param->_nb_context; i++)
+            for (uint32_t j=0; j<_param->_size_queue[i]; j++)
+              {
+                in_PREDICT_CONTEXT_ID   [port1]->write(i);
+                in_PREDICT_ADDRESS_PUSH [port1]->write(0x25071959+j);
+                
+                SC_START(0);
+                
+                TEST(Tcontrol_t, out_PREDICT_ACK        [port1]->read(), 1);
+                TEST(Tptr_t    , out_PREDICT_INDEX      [port1]->read(),(j+1)%_param->_size_queue[i]);
+//              TEST(Taddress_t, out_PREDICT_ADDRESS_POP[port1]->read(),0xdeadbeef+j);
+                
+                SC_START(1);
+              }
+          in_PREDICT_VAL [port1]->write(0);
+
+          LABEL("Decod");
+          in_DECOD_VAL  [port2]->write(1);
+          in_DECOD_PUSH [port2]->write(1);
+          for (uint32_t i=0; i<_param->_nb_context; i++)
+            for (uint32_t j=0; j<_param->_size_queue[i]/2; j++)
+              {
+                in_DECOD_CONTEXT_ID      [port2]->write(i);
+                in_DECOD_ADDRESS_PUSH    [port2]->write(0x25071959+j);
+                in_DECOD_MISS_PREDICTION [port2]->write(0);
+                
+                SC_START(0);
+                
+                TEST(Tcontrol_t, out_DECOD_ACK        [port2]->read(), 1);
+                TEST(Tptr_t    , out_DECOD_INDEX      [port2]->read(),(j+1)%_param->_size_queue[i]);
+                TEST(Taddress_t, out_DECOD_ADDRESS_POP[port2]->read(),0x25071959+j);
+                
+                SC_START(1);
+              }
+          in_DECOD_VAL [port2]->write(0);
+
+          LABEL("Update Decod OK");
+          in_UPDATE_VAL  [port3]->write(1);
+          in_UPDATE_PUSH [port3]->write(1);
+          in_UPDATE_FLUSH[port3]->write(0);
+          for (uint32_t i=0; i<_param->_nb_context; i++)
+            for (uint32_t j=0; j<_param->_size_queue[i]/2; j++)
+              {
+                uint32_t x=(_param->_size_queue[i]/2)-1;
+                in_UPDATE_CONTEXT_ID        [port3]->write(i);
+                in_UPDATE_MISS_PREDICTION   [port3]->write(0);
+                in_UPDATE_PREDICTION_IFETCH [port3]->write(0);
+                in_UPDATE_INDEX             [port3]->write((x+1)%_param->_size_queue[i]);
+                in_UPDATE_ADDRESS           [port3]->write(0x25071959+x);
+                
+                SC_START(0);
+                
+                TEST(Tcontrol_t, out_UPDATE_ACK        [port3]->read(), 1);
+                
+                SC_START(1);
+              }
+          in_UPDATE_VAL [port3]->write(0);
+
+          LABEL("Update FLUSH");
+          in_UPDATE_VAL  [port3]->write(1);
+          in_UPDATE_FLUSH[port3]->write(1);
+          for (uint32_t i=0; i<_param->_nb_context; i++)
+            for (uint32_t j=0; j<_param->_size_queue[i]/2; j++)
+              {
+                in_UPDATE_CONTEXT_ID        [port3]->write(i);
+                SC_START(1);
+                TEST(Tcontrol_t, out_UPDATE_ACK        [port3]->read(), 1);
+              }
+          in_UPDATE_VAL [port3]->write(0);
+
+
+// Tcontrol_t, in_UPDATE_VAL               
+// Tcontrol_t,out_UPDATE_ACK               
+// Tcontext_t, in_UPDATE_CONTEXT_ID        
+// Tcontrol_t, in_UPDATE_PUSH              
+// Tcontrol_t, in_UPDATE_FLUSH             
+// Tptr_t    , in_UPDATE_INDEX             
+// Taddress_t, in_UPDATE_ADDRESS           
+// Tcontrol_t, in_UPDATE_MISS_PREDICTION   
+// Tcontrol_t, in_UPDATE_PREDICTION_IFETCH 
+
+
+        }
+
+      if (test4)
+        {
+          uint32_t port1 = rand()%_param->_nb_inst_predict;
+          uint32_t port2 = rand()%_param->_nb_inst_decod;
+          uint32_t port3 = rand()%_param->_nb_inst_update;
+
+          LABEL("Test UPDATE");
+
+          LABEL("Predict");
+          in_PREDICT_VAL  [port1]->write(1);
+          in_PREDICT_PUSH [port1]->write(1);
+          for (uint32_t i=0; i<_param->_nb_context; i++)
+            for (uint32_t j=0; j<_param->_size_queue[i]; j++)
+              {
+                in_PREDICT_CONTEXT_ID   [port1]->write(i);
+                in_PREDICT_ADDRESS_PUSH [port1]->write(0x14011959+j);
+                
+                SC_START(0);
+                
+                TEST(Tcontrol_t, out_PREDICT_ACK        [port1]->read(), 1);
+                TEST(Tptr_t    , out_PREDICT_INDEX      [port1]->read(),(j+1)%_param->_size_queue[i]);
+//              TEST(Taddress_t, out_PREDICT_ADDRESS_POP[port1]->read(),0xdeadbeef+j);
+                
+                SC_START(1);
+              }
+          in_PREDICT_VAL [port1]->write(0);
+
+          LABEL("Decod");
+          in_DECOD_VAL  [port2]->write(1);
+          in_DECOD_PUSH [port2]->write(1);
+          for (uint32_t i=0; i<_param->_nb_context; i++)
+            for (uint32_t j=0; j<_param->_size_queue[i]/2; j++)
+              {
+                in_DECOD_CONTEXT_ID      [port2]->write(i);
+                in_DECOD_ADDRESS_PUSH    [port2]->write(0x14011959+j);
+                in_DECOD_MISS_PREDICTION [port2]->write(0);
+                
+                SC_START(0);
+                
+                TEST(Tcontrol_t, out_DECOD_ACK        [port2]->read(), 1);
+                TEST(Tptr_t    , out_DECOD_INDEX      [port2]->read(),(j+1)%_param->_size_queue[i]);
+                TEST(Taddress_t, out_DECOD_ADDRESS_POP[port2]->read(),0x14011959+j);
+                
+                SC_START(1);
+              }
+          in_DECOD_VAL [port2]->write(0);
+
+          LABEL("Update Decod KO");
+          in_UPDATE_VAL  [port3]->write(1);
+          in_UPDATE_PUSH [port3]->write(1);
+          in_UPDATE_FLUSH[port3]->write(0);
+          for (uint32_t i=0; i<_param->_nb_context; i++)
+            for (uint32_t j=0; j<_param->_size_queue[i]/2; j++)
+              {
+                uint32_t x=(_param->_size_queue[i]/2);
+                in_UPDATE_CONTEXT_ID        [port3]->write(i);
+                in_UPDATE_MISS_PREDICTION   [port3]->write(1);
+                in_UPDATE_PREDICTION_IFETCH [port3]->write(0);
+                in_UPDATE_INDEX             [port3]->write((x-j)%_param->_size_queue[i]);
+                in_UPDATE_ADDRESS           [port3]->write(0xffffffff+x);
+                
+                SC_START(0);
+                
+                TEST(Tcontrol_t, out_UPDATE_ACK        [port3]->read(), 1);
+                
+                SC_START(1);
+              }
+          in_UPDATE_VAL [port3]->write(0);
+
+          LABEL("Decod");
+          in_DECOD_VAL  [port2]->write(1);
+          in_DECOD_PUSH [port2]->write(1);
+          for (uint32_t i=0; i<_param->_nb_context; i++)
+            for (uint32_t j=0; j<_param->_size_queue[i]/2; j++)
+              {
+                in_DECOD_CONTEXT_ID      [port2]->write(i);
+                in_DECOD_ADDRESS_PUSH    [port2]->write(0x14011959+j);
+                in_DECOD_MISS_PREDICTION [port2]->write(0);
+                
+                SC_START(0);
+                
+                TEST(Tcontrol_t, out_DECOD_ACK        [port2]->read(), 1);
+                TEST(Tptr_t    , out_DECOD_INDEX      [port2]->read(),(j+1)%_param->_size_queue[i]);
+                TEST(Taddress_t, out_DECOD_ADDRESS_POP[port2]->read(),0x14011959+j);
+                
+                SC_START(1);
+              }
+          in_DECOD_VAL [port2]->write(0);
+
+
+          LABEL("Update Decod KO");
+          in_UPDATE_VAL  [port3]->write(1);
+          in_UPDATE_PUSH [port3]->write(1);
+          in_UPDATE_FLUSH[port3]->write(0);
+          for (uint32_t i=0; i<_param->_nb_context; i++)
+            for (uint32_t j=0; j<_param->_size_queue[i]/2; j++)
+              {
+                uint32_t x=(_param->_size_queue[i]/2);
+                in_UPDATE_CONTEXT_ID        [port3]->write(i);
+                in_UPDATE_MISS_PREDICTION   [port3]->write(1);
+                in_UPDATE_PREDICTION_IFETCH [port3]->write(0);
+                in_UPDATE_INDEX             [port3]->write((x-j)%_param->_size_queue[i]);
+                in_UPDATE_ADDRESS           [port3]->write(0xffffffff+x);
+                
+                SC_START(0);
+                
+                TEST(Tcontrol_t, out_UPDATE_ACK        [port3]->read(), 1);
+                
+                SC_START(1);
+              }
+          in_UPDATE_VAL [port3]->write(0);
+
+          LABEL("Update Predict KO");
+          in_UPDATE_VAL  [port3]->write(1);
+          in_UPDATE_PUSH [port3]->write(1);
+          in_UPDATE_FLUSH[port3]->write(0);
+          for (uint32_t i=0; i<_param->_nb_context; i++)
+            for (uint32_t j=0; j<_param->_size_queue[i]; j++)
+              {
+                uint32_t x=(_param->_size_queue[i]);
+                in_UPDATE_CONTEXT_ID        [port3]->write(i);
+                in_UPDATE_MISS_PREDICTION   [port3]->write(1);
+                in_UPDATE_PREDICTION_IFETCH [port3]->write(1);
+                in_UPDATE_INDEX             [port3]->write((x-j)%_param->_size_queue[i]);
+                in_UPDATE_ADDRESS           [port3]->write(0xffffffff+x);
+                
+                SC_START(0);
+                
+                TEST(Tcontrol_t, out_UPDATE_ACK        [port3]->read(), 1);
+                
+                SC_START(1);
+              }
+          in_UPDATE_VAL [port3]->write(0);
+
+          LABEL("Predict");
+          in_PREDICT_VAL  [port1]->write(1);
+          in_PREDICT_PUSH [port1]->write(1);
+          for (uint32_t i=0; i<_param->_nb_context; i++)
+            for (uint32_t j=0; j<_param->_size_queue[i]; j++)
+              {
+                in_PREDICT_CONTEXT_ID   [port1]->write(i);
+                in_PREDICT_ADDRESS_PUSH [port1]->write(0x14011959+j);
+                
+                SC_START(0);
+                
+                TEST(Tcontrol_t, out_PREDICT_ACK        [port1]->read(), 1);
+                TEST(Tptr_t    , out_PREDICT_INDEX      [port1]->read(),(j+1)%_param->_size_queue[i]);
+                TEST(Taddress_t, out_PREDICT_ADDRESS_POP[port1]->read(),0x14011959+j);
+                
+                SC_START(1);
+              }
+          in_PREDICT_VAL [port1]->write(0);
+
+          LABEL("Update Predict KO");
+          in_UPDATE_VAL  [port3]->write(1);
+          in_UPDATE_PUSH [port3]->write(0);
+          in_UPDATE_FLUSH[port3]->write(0);
+          for (uint32_t i=0; i<_param->_nb_context; i++)
+            for (uint32_t j=0; j<_param->_size_queue[i]; j++)
+              {
+                uint32_t x=(_param->_size_queue[i]);
+                in_UPDATE_CONTEXT_ID        [port3]->write(i);
+                in_UPDATE_MISS_PREDICTION   [port3]->write(1);
+                in_UPDATE_PREDICTION_IFETCH [port3]->write(1);
+                in_UPDATE_INDEX             [port3]->write((x+j+1)%_param->_size_queue[i]);
+                in_UPDATE_ADDRESS           [port3]->write(0x87654321+j);
+                
+                SC_START(0);
+                
+                TEST(Tcontrol_t, out_UPDATE_ACK        [port3]->read(), 1);
+                
+                SC_START(1);
+              }
+          in_UPDATE_VAL [port3]->write(0);
+
+          LABEL("Predict");
+          in_PREDICT_VAL  [port1]->write(1);
+          in_PREDICT_PUSH [port1]->write(1);
+          for (uint32_t i=0; i<_param->_nb_context; i++)
+            for (uint32_t j=0; j<_param->_size_queue[i]; j++)
+              {
+                in_PREDICT_CONTEXT_ID   [port1]->write(i);
+                in_PREDICT_ADDRESS_PUSH [port1]->write(0x14011959+j);
+                
+                SC_START(0);
+                
+                TEST(Tcontrol_t, out_PREDICT_ACK        [port1]->read(), 1);
+                TEST(Tptr_t    , out_PREDICT_INDEX      [port1]->read(),(j+1)%_param->_size_queue[i]);
+                TEST(Taddress_t, out_PREDICT_ADDRESS_POP[port1]->read(),0x87654321+j);
+                
+                SC_START(1);
+              }
+          in_PREDICT_VAL [port1]->write(0);
+
+          LABEL("Update FLUSH");
+          in_UPDATE_VAL  [port3]->write(1);
+          in_UPDATE_FLUSH[port3]->write(1);
+          for (uint32_t i=0; i<_param->_nb_context; i++)
+            for (uint32_t j=0; j<_param->_size_queue[i]/2; j++)
+              {
+                in_UPDATE_CONTEXT_ID        [port3]->write(i);
+                SC_START(1);
+                TEST(Tcontrol_t, out_UPDATE_ACK        [port3]->read(), 1);
+              }
+          in_UPDATE_VAL [port3]->write(0);
         }
     }
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/include/Return_Address_Stack.h
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/include/Return_Address_Stack.h	(revision 98)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/include/Return_Address_Stack.h	(revision 100)
@@ -88,5 +88,5 @@
   public    : SC_IN (Tcontext_t)           **  in_UPDATE_CONTEXT_ID       ; //[nb_inst_update] 
   public    : SC_IN (Tcontrol_t)           **  in_UPDATE_PUSH             ; //[nb_inst_update]  1 = push, else pop
-  public    : SC_IN (Tcontrol_t)           **  in_UPDATE_FLUSH            ; //[nb_inst_update]  1 = push, else pop
+  public    : SC_IN (Tcontrol_t)           **  in_UPDATE_FLUSH            ; //[nb_inst_update]
   public    : SC_IN (Taddress_t)           **  in_UPDATE_ADDRESS          ; //[nb_inst_update]
   public    : SC_IN (Tptr_t    )           **  in_UPDATE_INDEX            ; //[nb_inst_update]
@@ -99,8 +99,8 @@
   private   : ras_entry_t                  ** reg_stack         ; //[nb_context][size_queue]
   private   : Tptr_t                        * reg_TOP           ; //[nb_context]
-  private   : Tptr_t                        * reg_BOTTOM        ; //[nb_context]
+//private   : Tptr_t                        * reg_BOTTOM        ; //[nb_context]
   private   : Tptr_t                        * reg_NB_ELT        ; //[nb_context]
   private   : Tptr_t                        * reg_PREDICT_TOP   ; //[nb_context]
-  private   : Tptr_t                        * reg_PREDICT_BOTTOM; //[nb_context]
+//private   : Tptr_t                        * reg_PREDICT_BOTTOM; //[nb_context]
   private   : Tptr_t                        * reg_PREDICT_NB_ELT; //[nb_context]
 
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/include/Types.h
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/include/Types.h	(revision 98)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/include/Types.h	(revision 100)
@@ -21,7 +21,7 @@
   class ras_entry_t
   {
-  public : bool       _val    ;
-  public : bool       _predict;
-  public : bool       _miss   ;
+//public : bool       _val    ;
+//public : bool       _predict;
+//public : bool       _miss   ;
   public : Taddress_t _address;
   };
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/src/Return_Address_Stack_allocation.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/src/Return_Address_Stack_allocation.cpp	(revision 98)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/src/Return_Address_Stack_allocation.cpp	(revision 100)
@@ -107,9 +107,9 @@
 
     reg_TOP              = new Tptr_t     [_param->_nb_context];
-    reg_BOTTOM           = new Tptr_t     [_param->_nb_context];
+//  reg_BOTTOM           = new Tptr_t     [_param->_nb_context];
     reg_NB_ELT           = new Tptr_t     [_param->_nb_context];
 
     reg_PREDICT_TOP      = new Tptr_t     [_param->_nb_context];
-    reg_PREDICT_BOTTOM   = new Tptr_t     [_param->_nb_context];
+//  reg_PREDICT_BOTTOM   = new Tptr_t     [_param->_nb_context];
     reg_PREDICT_NB_ELT   = new Tptr_t     [_param->_nb_context];
 
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/src/Return_Address_Stack_deallocation.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/src/Return_Address_Stack_deallocation.cpp	(revision 98)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/src/Return_Address_Stack_deallocation.cpp	(revision 100)
@@ -64,8 +64,8 @@
         delete [] reg_stack;
         delete [] reg_TOP;
-        delete [] reg_BOTTOM;
+//      delete [] reg_BOTTOM;
         delete [] reg_NB_ELT;
         delete [] reg_PREDICT_TOP;
-        delete [] reg_PREDICT_BOTTOM;
+//      delete [] reg_PREDICT_BOTTOM;
         delete [] reg_PREDICT_NB_ELT;
         
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/src/Return_Address_Stack_genMealy_decod.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/src/Return_Address_Stack_genMealy_decod.cpp	(revision 98)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/src/Return_Address_Stack_genMealy_decod.cpp	(revision 100)
@@ -22,7 +22,9 @@
   void Return_Address_Stack::genMealy_decod (void)
   {
-    log_printf(FUNC,Return_Address_Stack,FUNCTION,"Begin");
+    log_begin(Return_Address_Stack,FUNCTION);
+    log_function(Return_Address_Stack,FUNCTION,_name.c_str());
 
 #ifdef DEBUG_TEST
+    // just to test if have many transaction on a same context
     bool context_valid [_param->_nb_context];
     for (uint32_t i=0; i<_param->_nb_context; i++)
@@ -32,4 +34,5 @@
     for (uint32_t i=0; i<_param->_nb_inst_decod; i++)
       {
+        // Read context number
 	Tcontext_t context = (_param->_have_port_context_id)?PORT_READ(in_DECOD_CONTEXT_ID [i]):0;
 
@@ -49,5 +52,5 @@
 	// if pop  : val and not miss
 	//   when the predictor : if hit = 0, wait (is not accurate)
-	internal_DECOD_HIT [i] = (push or (reg_stack[context][top]._val and not reg_stack[context][top]._miss and (reg_NB_ELT[context]>0)));
+	internal_DECOD_HIT [i] = (push or (reg_NB_ELT[context]>0));
 	PORT_WRITE(out_DECOD_HIT         [i], internal_DECOD_HIT [i]);
 
@@ -61,5 +64,5 @@
       }
 
-    log_printf(FUNC,Return_Address_Stack,FUNCTION,"End");
+    log_end(Return_Address_Stack,FUNCTION);
   };
 
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/src/Return_Address_Stack_genMealy_predict.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/src/Return_Address_Stack_genMealy_predict.cpp	(revision 98)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/src/Return_Address_Stack_genMealy_predict.cpp	(revision 100)
@@ -22,7 +22,9 @@
   void Return_Address_Stack::genMealy_predict (void)
   {
-    log_printf(FUNC,Return_Address_Stack,FUNCTION,"Begin");
+    log_begin(Return_Address_Stack,FUNCTION);
+    log_function(Return_Address_Stack,FUNCTION,_name.c_str());
 
 #ifdef DEBUG_TEST
+    // just to test if have many transaction on a same context
     bool context_valid [_param->_nb_context];
     for (uint32_t i=0; i<_param->_nb_context; i++)
@@ -32,6 +34,7 @@
     for (uint32_t i=0; i<_param->_nb_inst_predict; i++)
       {
+        // Read context number
 	Tcontext_t context = (_param->_have_port_context_id)?PORT_READ(in_PREDICT_CONTEXT_ID [i]):0;
-
+        
 #ifdef DEBUG_TEST
 	if (PORT_READ(in_PREDICT_VAL [i]))
@@ -42,15 +45,18 @@
 	  }
 #endif
-
+        
+        // Get top
 	Tptr_t     top  = reg_PREDICT_TOP[context];
 	Tcontrol_t push = PORT_READ(in_PREDICT_PUSH [i]);
 
-	// if push : value is hit
-	// if pop  : val and not miss
-	internal_PREDICT_HIT [i] = (push or (reg_stack[context][top]._val and not reg_stack[context][top]._miss and (reg_PREDICT_NB_ELT[context]>0)));
+        // Hit :
+	//   * if push : value is hit
+	//   * if pop  : no empty
+	internal_PREDICT_HIT [i] = (push or (reg_PREDICT_NB_ELT[context]>0));
+
 	PORT_WRITE(out_PREDICT_HIT         [i], internal_PREDICT_HIT [i]);
 
 	// if pop  : address_pop   = stack [top]
-	// if push : stock [top+1] = address_push; also stock [top+1] is erase ! give the old value at the update table
+	// if push : stock [top+1] = address_push; also stack [top+1] is erase ! save the old value in the update table
 	if (push)
 	  top = (top+1)%_param->_size_queue[context];
@@ -60,5 +66,5 @@
       }
 
-    log_printf(FUNC,Return_Address_Stack,FUNCTION,"End");
+    log_end(Return_Address_Stack,FUNCTION);
   };
 
Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/src/Return_Address_Stack_transition.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/src/Return_Address_Stack_transition.cpp	(revision 98)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/src/Return_Address_Stack_transition.cpp	(revision 100)
@@ -22,24 +22,19 @@
   void Return_Address_Stack::transition (void)
   {
-    log_printf(FUNC,Return_Address_Stack,FUNCTION,"Begin");
+    log_begin(Return_Address_Stack,FUNCTION);
+    log_function(Return_Address_Stack,FUNCTION,_name.c_str());
 
     if (PORT_READ(in_NRESET)==0)
       {
+        // Reset all structure
 	for (uint32_t i=0; i<_param->_nb_context; i++)
 	  {
 	    reg_TOP    [i] = 0;
-	    reg_BOTTOM [i] = 0;
+// 	    reg_BOTTOM [i] = 0;
 	    reg_NB_ELT [i] = 0;
 
 	    reg_PREDICT_TOP    [i] = 0;
-	    reg_PREDICT_BOTTOM [i] = 0;
+// 	    reg_PREDICT_BOTTOM [i] = 0;
 	    reg_PREDICT_NB_ELT [i] = 0;
-
-	    for (uint32_t j=0; j<_param->_size_queue [i]; j++)
-	      {
-		reg_stack[i][j]._val     = false;
-		reg_stack[i][j]._predict = false;
-		reg_stack[i][j]._miss    = false;
-	      }
 	  }
       }
@@ -52,67 +47,76 @@
 	  if (PORT_READ(in_PREDICT_VAL [i]) and internal_PREDICT_ACK [i])
 	    {
-	      log_printf(TRACE,Return_Address_Stack,FUNCTION,"PREDICT[%d] : Transaction",i);
+	      log_printf(TRACE,Return_Address_Stack,FUNCTION,"  * PREDICT [%d] : Transaction",i);
+              
+              // Read information and pointer
 	      Tcontext_t context    = (_param->_have_port_context_id)?PORT_READ(in_PREDICT_CONTEXT_ID [i]):0;
 	      Tcontrol_t push       = PORT_READ(in_PREDICT_PUSH [i]);
+
 	      Tptr_t     top_old    = reg_PREDICT_TOP    [context];
 	      Tptr_t     top_new    = top_old;
-	      Tptr_t     bottom_old = reg_PREDICT_BOTTOM [context];
-
-	      log_printf(TRACE,Return_Address_Stack,FUNCTION," * context : %d",context);
-
-	      // Hit  : push or (val and not miss and not empty)
+// 	      Tptr_t     bottom_old = reg_PREDICT_BOTTOM [context];
+// 	      Tptr_t     bottom_new = bottom_old;
+	      Tptr_t     nb_elt_old = reg_PREDICT_NB_ELT [context];
+	      Tptr_t     nb_elt_new = nb_elt_old;
+
+	      log_printf(TRACE,Return_Address_Stack,FUNCTION,"    * context : %d",context);
+
+	      // Hit  : push or not empty
 	      // Miss : ifetch is stall, no update
+
+              // Test if hit
 	      if (internal_PREDICT_HIT [i])
 		{
-		  log_printf(TRACE,Return_Address_Stack,FUNCTION," * before");
-		  log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_predict_top     : %d",reg_PREDICT_TOP    [context]);
-		  log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_predict_bottom  : %d",reg_PREDICT_BOTTOM [context]);
-		  log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_predict_nb_elt  : %d",reg_PREDICT_NB_ELT [context]);
-
+		  log_printf(TRACE,Return_Address_Stack,FUNCTION,"    * before");
+		  log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_predict_top     : %d",top_old);
+// 		  log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_predict_bottom  : %d",bottom_old);
+		  log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_predict_nb_elt  : %d",nb_elt_old);
+
+                  // Test if push
 		  if (push)
 		    {
+                      log_printf(TRACE,Return_Address_Stack,FUNCTION,"    * push (call procedure)");
+
 		      // push : increase the top (circular)
 		      top_new = (top_old+1)%_param->_size_queue[context];
-		      
-		      reg_stack [context][top_new]._val     = true; // New addr
-		      reg_stack [context][top_new]._predict = true; // Is speculative (erase a old addr (or not))
-		    //reg_stack [context][top_new]._miss    = ;
+
+                      // Write new value in Queue
 		      reg_stack [context][top_new]._address = PORT_READ(in_PREDICT_ADDRESS_PUSH [i]);
 
-		      // the stack is full, erase the most old stack
-
 		      // Test if full
-		      if (reg_PREDICT_NB_ELT[context]==_param->_size_queue[context])
-			reg_PREDICT_BOTTOM [context] = (bottom_old+1)%_param->_size_queue[context];
-		      // A new data is write : the stack is not empty
-		      if (reg_PREDICT_NB_ELT[context]< _param->_size_queue[context])
-			reg_PREDICT_NB_ELT[context]++;
+                      //   -> is full, the push erase the oldest value in stack, also nb_elt is the same
+                      //   -> is not full, increase nb_elt
+// 		      if (nb_elt_old==_param->_size_queue[context])
+// 			bottom_new = (bottom_old+1)%_param->_size_queue[context];
+//                       else
+// 			nb_elt_new ++;
+		      if (nb_elt_old!=_param->_size_queue[context])
+			nb_elt_new ++;
 		    }
 		  else
 		    {
 		      // pop
-// 		      top_new = (top_old==0)?(_param->_size_queue[context]-1):(top_old-1);
-		      
-		    //reg_stack [context][top_new]._val     = ;
-		    //reg_stack [context][top_new]._predict = ;
-		    //reg_stack [context][top_new]._miss    = ;
-		    //reg_stack [context][top_new]._address = ; 
-
-		      // the stack is empty
-		      if (reg_PREDICT_NB_ELT[context]>0)
+                      log_printf(TRACE,Return_Address_Stack,FUNCTION,"    * pop (return procedure)");
+
+		      // Test if the stack is empty
+		      if (nb_elt_old>0)
 			{
 			  top_new = (top_old==0)?(_param->_size_queue[context]-1):(top_old-1);
-			  reg_PREDICT_NB_ELT[context] --;
+			  nb_elt_new --;
 			}
+                      // no else : can't pop
 		    }
 		  
-		  reg_PREDICT_TOP [context] = top_new;
-
-		  log_printf(TRACE,Return_Address_Stack,FUNCTION," * after");
-		  log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_predict_top     : %d",reg_PREDICT_TOP    [context]);
-		  log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_predict_bottom  : %d",reg_PREDICT_BOTTOM [context]);
-		  log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_predict_nb_elt  : %d",reg_PREDICT_NB_ELT [context]);
-		}
-	    }
+                  // Write new pointer
+		  reg_PREDICT_TOP    [context] = top_new;
+// 		  reg_PREDICT_BOTTOM [context] = bottom_new;
+		  reg_PREDICT_NB_ELT [context] = nb_elt_new;
+
+		  log_printf(TRACE,Return_Address_Stack,FUNCTION,"    * after");
+		  log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_predict_top     : %d",top_new);
+// 		  log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_predict_bottom  : %d",bottom_new);
+		  log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_predict_nb_elt  : %d",nb_elt_new);
+                }
+            }
 
 	// ===================================================================
@@ -122,81 +126,96 @@
 	  if (PORT_READ(in_DECOD_VAL [i]) and internal_DECOD_ACK [i])
 	    {
-	      log_printf(TRACE,Return_Address_Stack,FUNCTION,"DECOD[%d] : Transaction",i);
+	      log_printf(TRACE,Return_Address_Stack,FUNCTION,"  * DECOD [%d] : Transaction",i);
+
+              // Read information
 	      Tcontext_t context    = (_param->_have_port_context_id)?PORT_READ(in_DECOD_CONTEXT_ID [i]):0;
 	      Tcontrol_t push       = PORT_READ(in_DECOD_PUSH [i]);
+
+              // Read pointer
 	      Tptr_t     top_old    = reg_TOP    [context];
 	      Tptr_t     top_new    = top_old;
-	      Tptr_t     bottom_old = reg_BOTTOM [context];
-	      //Tcontrol_t hit        = internal_DECOD_HIT [i];
-	      Tcontrol_t miss       = PORT_READ(in_DECOD_MISS_PREDICTION [i]);
-
-	      log_printf(TRACE,Return_Address_Stack,FUNCTION," * context : %d",context);
-
-	      log_printf(TRACE,Return_Address_Stack,FUNCTION," * before");
-	      log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_top     : %d",reg_TOP    [context]);
-	      log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_bottom  : %d",reg_BOTTOM [context]);
-	      log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_nb_elt  : %d",reg_NB_ELT [context]);
-
-	      if (push)
-		{
-		  // push : increase the top (circular)
-		  top_new = (top_old+1)%_param->_size_queue[context];
-		  
-		  reg_stack [context][top_new]._val     = true;  // New address
-		  reg_stack [context][top_new]._predict = false; // No speculative
-		  reg_stack [context][top_new]._miss    = false;
-		  reg_stack [context][top_new]._address = PORT_READ(in_DECOD_ADDRESS_PUSH [i]);
-		  
-		  // Test if full : if true, then icrease the bottom (erase the most old stack)
-		  if (reg_NB_ELT[context]==_param->_size_queue[context])
-		    reg_BOTTOM [context] = (bottom_old+1)%_param->_size_queue[context];
-		  // A new data is write : the stack is not empty
-		  if (reg_NB_ELT[context]< _param->_size_queue[context])
-		    reg_NB_ELT[context]++;
-		}
-	      else
-		{
-		  // pop
-// 		  top_new = (top_old==0)?(_param->_size_queue[context]-1):(top_old-1);
-
-		  //reg_stack [context][top_new]._val     = ;
-		  //reg_stack [context][top_new]._predict = ;
-		  //reg_stack [context][top_new]._miss    = ;
-		  //reg_stack [context][top_new]._address = ; 
-		  
-		  // the stack is empty
-		  if (reg_NB_ELT[context]>0)
-		    {
-		      top_new = (top_old==0)?(_param->_size_queue[context]-1):(top_old-1);
-		      reg_NB_ELT[context] --;
-		    }
-		}
-	      
-	      reg_TOP [context] = top_new;
-	      
-	      log_printf(TRACE,Return_Address_Stack,FUNCTION," * after");
-	      log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_top     : %d",reg_TOP    [context]);
-	      log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_bottom  : %d",reg_BOTTOM [context]);
-	      log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_nb_elt  : %d",reg_NB_ELT [context]);
-
+// 	      Tptr_t     bottom_old = reg_BOTTOM [context];
+// 	      Tptr_t     bottom_new = bottom_old;
+	      Tptr_t     nb_elt_old = reg_NB_ELT [context];
+	      Tptr_t     nb_elt_new = nb_elt_old;
+
+	      log_printf(TRACE,Return_Address_Stack,FUNCTION,"    * context : %d",context);
+
+	      log_printf(TRACE,Return_Address_Stack,FUNCTION,"    * before");
+              log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_predict_top     : %d",top_old);
+//            log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_predict_bottom  : %d",bottom_old);
+              log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_predict_nb_elt  : %d",nb_elt_old);
+
+              // Test if push
+              if (push)
+                {
+                  log_printf(TRACE,Return_Address_Stack,FUNCTION,"    * push (call procedure)");
+                  
+                  // push : increase the top (circular)
+                  top_new = (top_old+1)%_param->_size_queue[context];
+                  
+                  // Write new value in Queue
+                  reg_stack [context][top_new]._address = PORT_READ(in_DECOD_ADDRESS_PUSH [i]);
+                  
+                  // Test if full
+                  //   -> is full, the push erase the oldest value in stack, also nb_elt is the same
+                  //   -> is not full, increase nb_elt
+//                   if (nb_elt_old==_param->_size_queue[context])
+//                     bottom_new = (bottom_old+1)%_param->_size_queue[context];
+//                   else
+//                     nb_elt_new ++;
+                  if (nb_elt_old!=_param->_size_queue[context])
+                    nb_elt_new ++;
+                }
+              else
+                {
+                  // pop
+                  log_printf(TRACE,Return_Address_Stack,FUNCTION,"    * pop (return procedure)");
+                  
+                  // Test if the stack is empty
+                  if (nb_elt_old>0)
+                    {
+                      top_new = (top_old==0)?(_param->_size_queue[context]-1):(top_old-1);
+                      nb_elt_new --;
+                    }
+                  // no else : can't pop
+                }
+              
+              // Write new pointer
+              reg_TOP    [context] = top_new;
+//            reg_BOTTOM [context] = bottom_new;
+              reg_NB_ELT [context] = nb_elt_new;
+              
+              log_printf(TRACE,Return_Address_Stack,FUNCTION,"    * after");
+              log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_predict_top     : %d",top_new);
+//            log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_predict_bottom  : %d",bottom_new);
+              log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_predict_nb_elt  : %d",nb_elt_new);
+              
 	      // have previous miss of ifetch ?
 	      // 2 miss : 
 	      //   1) miss predict : is very limited (local at context), can be update very quickly
 	      //   2) miss decod   : result is in commit stage ... 
-	      if (miss)
-		{
-		  reg_PREDICT_BOTTOM [context] = reg_BOTTOM [context];
-		  reg_PREDICT_TOP    [context] = reg_TOP    [context];
-		  reg_PREDICT_NB_ELT [context] = reg_NB_ELT [context];
+
+              // manage by Update_Fetch_Prediction_Table and Update_Prediction_Table
+              // Note : 
+              //   if decod miss : ifetch can have predict call and return branchement. Also, the head of decod can be false
+
+// 	      Tcontrol_t miss       = PORT_READ(in_DECOD_MISS_PREDICTION [i]);
+
+// 	      if (miss)
+// 		{
+// 		  reg_PREDICT_BOTTOM [context] = reg_BOTTOM [context];
+// 		  reg_PREDICT_TOP    [context] = reg_TOP    [context];
+// 		  reg_PREDICT_NB_ELT [context] = reg_NB_ELT [context];
 		  
-		  // Scan full assoc !!!
-		  for (uint32_t j=0; j<_param->_size_queue [context]; j++)
-		    // Test if this slot is tagged with "predict" : if true, tagged as miss
-		    if (reg_stack [context][j]._predict)
-		      {
-			reg_stack [context][j]._predict = false;
-			reg_stack [context][j]._miss    = true;
-		      }
-		}
+// 		  // Scan full assoc !!!
+// 		  for (uint32_t j=0; j<_param->_size_queue [context]; j++)
+// 		    // Test if this slot is tagged with "predict" : if true, tagged as miss
+// 		    if (reg_stack [context][j]._predict)
+// 		      {
+// 			reg_stack [context][j]._predict = false;
+// 			reg_stack [context][j]._miss    = true;
+// 		      }
+// 		}
 	    }
 
@@ -207,42 +226,160 @@
 	  if (PORT_READ(in_UPDATE_VAL [i]) and internal_UPDATE_ACK [i])
 	    {
-	      throw ERRORMORPHEO(FUNCTION,"Fonction à implémenter !!!!!!!!!!!!");
-	      
-
-// 	      Tcontrol_t miss   = PORT_READ(in_UPDATE_MISS_PREDICTION [i]);
-// 	      // 
-// 	      if (miss)
-// 		{
-// 		  Tcontrol_t context = (_param->_have_port_context_id)?PORT_READ(in_UPDATE_CONTEXT_ID [i]):0;
-// 		  Tcontrol_t ifetch  = PORT_READ(in_UPDATE_PREDICTION_IFETCH [i]);
-// 		  Tcontrol_t push    = PORT_READ(in_UPDATE_PUSH             [i]);
-// 		  Tcontrol_t flush   = PORT_READ(in_UPDATE_FLUSH            [i]);
-// 		  Tptr_t     index   = PORT_READ(in_UPDATE_INDEX            [i]);
-// 		  Taddress_t address = PORT_READ(in_UPDATE_ADDRESS          [i]);
-		  
-// 		  if (push)
-// 		    {
-// // 		      // push
-// // 		      top_new = (top_old+1)%_param->_size_queue[context];
-		      
-// // 		      reg_stack [context][index]._val     = true;
-// // 		      reg_stack [context][index]._predict = false;
-// // 		      reg_stack [context][index]._miss    = false;
-// // 		      reg_stack [context][index]._address = PORT_READ(in_UPDATE_ADDRESS [i]);
-
-// 		    }
-// 		  else
-// 		    {
-// // 		    //reg_stack [context][top_new]._val     = ;
-// // 		    //reg_stack [context][top_new]._predict = ;
-// // 		    //reg_stack [context][top_new]._miss    = ;
-// // 		    //reg_stack [context][top_new]._address = ; 
-// 		    }
-		  
-// // // 		  // Mouais bof .......
-// // // 		  reg_PREDICT_TOP [context] = index;
-// 		}
+	      log_printf(TRACE,Return_Address_Stack,FUNCTION,"  * UPDATE [%d] : Transaction",i);
+
+              Tcontext_t context_id        = (_param->_have_port_context_id)?PORT_READ(in_UPDATE_CONTEXT_ID [i]):0;
+              Tcontrol_t flush             = PORT_READ(in_UPDATE_FLUSH             [i]);
+
+	      log_printf(TRACE,Return_Address_Stack,FUNCTION,"    * context_id        : %d",context_id);
+	      log_printf(TRACE,Return_Address_Stack,FUNCTION,"    * flush             : %d",flush     );
+              
+              // An miss prediction on call/return = Return Address Stack is corrupted.
+              if (flush)
+                {
+                  // All pointer is set at 0
+                  reg_TOP    [context_id] = 0;
+//                reg_BOTTOM [context_id] = 0;
+                  reg_NB_ELT [context_id] = 0;
+                  
+                  reg_PREDICT_TOP    [context_id] = 0;
+//                reg_PREDICT_BOTTOM [context_id] = 0;
+                  reg_PREDICT_NB_ELT [context_id] = 0;
+                }
+              else
+                {
+                  // if miss_prediction -> restore queue
+                  // else, the prediction is correct
+                  Tcontrol_t miss_prediction   = PORT_READ(in_UPDATE_MISS_PREDICTION   [i]);
+
+                  log_printf(TRACE,Return_Address_Stack,FUNCTION,"    * miss_prediction   : %d",miss_prediction);
+
+#ifdef DEBUG_TEST
+                  Tptr_t     index             = PORT_READ(in_UPDATE_INDEX             [i]);
+                  Tcontrol_t prediction_ifetch = PORT_READ(in_UPDATE_PREDICTION_IFETCH [i]);
+                  log_printf(TRACE,Return_Address_Stack,FUNCTION,"    * index             : %d",index);
+                  log_printf(TRACE,Return_Address_Stack,FUNCTION,"    * prediction_ifetch : %d",prediction_ifetch);
+
+//                   if (prediction_ifetch)
+//                     {
+//                       if (index != reg_PREDICT_TOP [context_id])
+//                         throw ERRORMORPHEO(FUNCTION,_("Index is different of predict_top"));
+//                     }
+//                   else
+//                     {
+//                       if (index != reg_TOP [context_id])
+//                         throw ERRORMORPHEO(FUNCTION,_("Index is different of top"));
+//                     }
+                  
+#endif
+                  if (miss_prediction)
+                    {
+                      Tcontrol_t push              = PORT_READ(in_UPDATE_PUSH              [i]);
+                      log_printf(TRACE,Return_Address_Stack,FUNCTION,"    * push              : %d",push);
+#ifndef DEBUG_TEST
+                      Tptr_t     index             = PORT_READ(in_UPDATE_INDEX             [i]);
+                      Tcontrol_t prediction_ifetch = PORT_READ(in_UPDATE_PREDICTION_IFETCH [i]);
+                      log_printf(TRACE,Return_Address_Stack,FUNCTION,"    * index             : %d",index);
+                      log_printf(TRACE,Return_Address_Stack,FUNCTION,"    * prediction_ifetch : %d",prediction_ifetch);
+#endif
+
+
+                      Tptr_t     top_old    = (prediction_ifetch)?reg_PREDICT_TOP    [context_id]:reg_TOP    [context_id];
+                      Tptr_t     top_new    = top_old;
+
+//                    Tptr_t     bottom_old = (prediction_ifetch)?reg_PREDICT_BOTTOM [context_id]:reg_BOTTOM [context_id];
+//                    Tptr_t     bottom_new = bottom_old;
+
+                      Tptr_t     nb_elt_old = (prediction_ifetch)?reg_PREDICT_NB_ELT [context_id]:reg_NB_ELT [context_id];
+                      Tptr_t     nb_elt_new = nb_elt_old;
+                      
+                      log_printf(TRACE,Return_Address_Stack,FUNCTION,"    * before");
+                      if (prediction_ifetch)
+                        {
+                          log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_predict_top     : %d",top_old);
+//                        log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_predict_bottom  : %d",bottom_old);
+                          log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_predict_nb_elt  : %d",nb_elt_old);
+                        }
+                      else
+                        {
+                          log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_top     : %d",top_old);
+//                        log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_bottom  : %d",bottom_old);
+                          log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_nb_elt  : %d",nb_elt_old);
+                        }
+
+                      // if previous is push, pop the value
+                      // else is previous is pop, push the poped value
+                      if (push)
+                        {
+                          // previous is push, now must be pop
+
+                          // Test if the stack is empty
+                          if (nb_elt_old>0) // ??
+                            {
+                              top_new = (top_old==0)?(_param->_size_queue[context_id]-1):(top_old-1);
+                              nb_elt_new --;
+                            }
+                        }
+                      else
+                        {
+                          // previous is pop, now must be push
+                          Taddress_t address           = PORT_READ(in_UPDATE_ADDRESS           [i]);
+
+                          // push : increase the top (circular)
+//                        if (nb_elt_old==_param->_size_queue[context_id])
+//                          bottom_new = (bottom_old+1)%_param->_size_queue[context_id];
+//                        else
+//                          nb_elt_new ++;
+
+                          if (nb_elt_old!=_param->_size_queue[context_id])
+                            nb_elt_new ++;
+
+                          top_new = index;
+                          
+                          reg_stack [context_id][index]._address = address;
+                        }
+
+                      log_printf(TRACE,Return_Address_Stack,FUNCTION,"    * after");
+
+                      if (prediction_ifetch)
+                        {
+                          log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_predict_top     : %d",top_new);
+//                        log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_predict_bottom  : %d",bottom_new);
+                          log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_predict_nb_elt  : %d",nb_elt_new);
+
+                          reg_PREDICT_TOP    [context_id] = top_new   ;
+//                        reg_PREDICT_BOTTOM [context_id] = bottom_new;
+                          reg_PREDICT_NB_ELT [context_id] = nb_elt_new;
+                        }
+                      else
+                        {
+                          log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_top     : %d",top_new);
+//                        log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_bottom  : %d",bottom_new);
+                          log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_nb_elt  : %d",nb_elt_new);
+
+                          reg_TOP            [context_id] = top_new   ;
+//                        reg_BOTTOM         [context_id] = bottom_new;
+                          reg_NB_ELT         [context_id] = nb_elt_new;
+                        }
+                    }
+                }
 	    }
       }
+
+#if defined(DEBUG_Return_Address_Stack) and DEBUG>=DEBUG_TRACE
+    log_printf(TRACE,Return_Address_Stack,FUNCTION,"  * Dump RAS");
+    for (uint32_t i=0; i<_param->_nb_context; ++i)
+      {
+        log_printf(TRACE,Return_Address_Stack,FUNCTION,"    * Return Address Stack [%d]",i);
+        log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_TOP            : %d",reg_TOP            [i]);
+//      log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_BOTTOM         : %d",reg_BOTTOM         [i]);
+        log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_NB_ELT         : %d",reg_NB_ELT         [i]);
+        log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_PREDICT_TOP    : %d",reg_PREDICT_TOP    [i]);
+//      log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_PREDICT_BOTTOM : %d",reg_PREDICT_BOTTOM [i]);
+        log_printf(TRACE,Return_Address_Stack,FUNCTION,"      * reg_PREDICT_NB_ELT : %d",reg_PREDICT_NB_ELT [i]);
+
+        for (uint32_t j=0; j<_param->_size_queue[i]; ++j)
+          log_printf(TRACE,Return_Address_Stack,FUNCTION,"      [%d] %.8x (%.8x)",j,reg_stack [i][j]._address,reg_stack [i][j]._address<<2);
+      }
+#endif
 
 #if defined(STATISTICS) or defined(VHDL_TESTBENCH)
@@ -250,5 +387,5 @@
 #endif
 
-    log_printf(FUNC,Return_Address_Stack,FUNCTION,"End");
+    log_end(Return_Address_Stack,FUNCTION);
   };
 
