Index: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Prediction_unit_Glue/src/Prediction_unit_Glue_genMealy_decod.cpp
===================================================================
--- trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Prediction_unit_Glue/src/Prediction_unit_Glue_genMealy_decod.cpp	(revision 82)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Prediction_unit_Glue/src/Prediction_unit_Glue_genMealy_decod.cpp	(revision 88)
@@ -22,8 +22,10 @@
   void Prediction_unit_Glue::genMealy_decod (void)
   {
-    log_printf(FUNC,Prediction_unit_Glue,FUNCTION,"Begin");
-
+    log_begin(Prediction_unit_Glue,FUNCTION);
+    log_function(Prediction_unit_Glue,FUNCTION,_name.c_str());
+
+    // Init
     uint32_t   decod_unit = reg_DECOD_PRIORITY;
-
+    
     log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"  * decod_unit : %d",decod_unit);
 
@@ -49,5 +51,5 @@
       if ((port>=_param->_nb_inst_branch_decod) or
 	  (PORT_READ(in_DECOD_VAL [decod_unit][i]) == 0))
-	{
+ 	{
 	  log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"  * DECOD[%d][%d] : not valid",decod_unit,i);
 	  ack [i] = false;
@@ -55,28 +57,33 @@
       else
 	{
-	  Tcontext_t          context               = (_param->_have_port_context_id)?PORT_READ(in_DECOD_CONTEXT_ID [decod_unit][i]):0;
-	  Tbranch_state_t     branch_state          = PORT_READ(in_DECOD_BRANCH_STATE          [decod_unit][i]);
-	  Tcontrol_t          match_inst_ifetch_ptr = PORT_READ(in_DECOD_MATCH_INST_IFETCH_PTR [decod_unit][i]);
-	  Tprediction_ptr_t   depth   = (_param->_have_port_max_depth)?PORT_READ(in_DECOD_BRANCH_UPDATE_PREDICTION_ID [decod_unit][i]):0;
-	  Tcontrol_t          use_btb = false;
-	  Tcontrol_t          use_ras = false;
-	  Tcontrol_t          use_upt = true ;
-	  Tcontrol_t          miss_ifetch    = ( (branch_state == BRANCH_STATE_NONE) or // branch not detected
-						 ((branch_state != BRANCH_STATE_NONE) and (match_inst_ifetch_ptr == 0))); // branch detected, but it's not the good
-	  Tcontrol_t          miss_decod;
+	  Tcontext_t        context               = (_param->_have_port_context_id)?PORT_READ(in_DECOD_CONTEXT_ID [decod_unit][i]):0;
+	  Tbranch_state_t   branch_state          = PORT_READ(in_DECOD_BRANCH_STATE          [decod_unit][i]);
+	  Tcontrol_t        match_inst_ifetch_ptr = PORT_READ(in_DECOD_MATCH_INST_IFETCH_PTR [decod_unit][i]);
+	  Tprediction_ptr_t depth                 = (_param->_have_port_depth)?PORT_READ(in_DECOD_BRANCH_UPDATE_PREDICTION_ID [decod_unit][i]):0;
+	  Tcontrol_t        use_btb               = false;
+	  Tcontrol_t        use_ras               = false;
+	  Tcontrol_t        use_upt               = true ; // always update upt.
+
+          // Ifetch stage made an miss if :
+          //   * branch is previously predict, but it's not the good
+	  Tcontrol_t        miss_ifetch           = ((branch_state != BRANCH_STATE_NONE) and (match_inst_ifetch_ptr == 0));
+          // Decod stage made an miss if :
+          //   * branch was not detected
+          Tcontrol_t        miss_decod            = (branch_state == BRANCH_STATE_NONE);
 
 	  log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"  * DECOD[%d][%d] :     valid",decod_unit,i);
-	  log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * depth   [%d] : %d",i   ,depth);
+	  log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * branch_state          : %d",branch_state);
+	  log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * match_inst_ifetch_ptr : %d",match_inst_ifetch_ptr);
+	  log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * depth                 : [%d] %d",i,depth);
+          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * miss_ifetch           : %d",miss_ifetch);
+          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * miss_decod            : %d",miss_decod);
 
 	  // Test if ifetch have detecte a branch is the packet
-	  if (miss_ifetch)
+	  if (miss_ifetch or miss_decod)
 	    {
-	      log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * miss_ifetch");
-	      log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * state : %d",branch_state);
-	      log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * match : %d",match_inst_ifetch_ptr);
-	      Tbranch_condition_t condition             = PORT_READ(in_DECOD_BRANCH_CONDITION            [decod_unit][i]);
-	      Tcontrol_t          direction             = PORT_READ(in_DECOD_BRANCH_DIRECTION            [decod_unit][i]);
-	      Taddress_t          address_src           = PORT_READ(in_DECOD_ADDRESS_SRC                 [decod_unit][i]);
-	      Taddress_t          address_dest          = PORT_READ(in_DECOD_ADDRESS_DEST                [decod_unit][i]);
+	      Tbranch_condition_t condition    = PORT_READ(in_DECOD_BRANCH_CONDITION            [decod_unit][i]);
+	      Tcontrol_t          direction    = PORT_READ(in_DECOD_BRANCH_DIRECTION            [decod_unit][i]);
+	      Taddress_t          address_src  = PORT_READ(in_DECOD_ADDRESS_SRC                 [decod_unit][i]);
+	      Taddress_t          address_dest = PORT_READ(in_DECOD_ADDRESS_DEST                [decod_unit][i]);
 	      Tcontrol_t          is_accurate;
 
@@ -88,35 +95,38 @@
 		case BRANCH_CONDITION_NONE_WITH_WRITE_STACK             :
 		  {
-		    // Write stack
+		    // l.jal
+                    log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * BRANCH_CONDITION_NONE_WITH_WRITE_STACK");
+
+		    is_accurate = true ;//PORT_READ(in_DECOD_RAS_HIT [port]);
+		    use_ras     = true ;
+
+		    PORT_WRITE(out_DECOD_RAS_PUSH         [port],1);
+		    PORT_WRITE(out_DECOD_RAS_ADDRESS_PUSH [port],address_src+2);
+		    
+		    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");
+
+		    is_accurate = false; // address unknow : in a register
+		    use_ras     = true;
+
+		    PORT_WRITE(out_DECOD_RAS_PUSH         [port],1);
+		    PORT_WRITE(out_DECOD_RAS_ADDRESS_PUSH [port],address_src+2);
+		    
+		    break;
+		  }
+		case BRANCH_CONDITION_READ_STACK                        :
+		  {
+		    // l.jr with rb=r9
+                    log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * BRANCH_CONDITION_READ_STACK");
+
 		    is_accurate = PORT_READ(in_DECOD_RAS_HIT [port]);
-		    miss_decod  = false;
 		    use_ras     = true;
 
-		    PORT_WRITE(out_DECOD_RAS_PUSH         [port],1);
-		    PORT_WRITE(out_DECOD_RAS_ADDRESS_PUSH [port],address_dest);
-		    
-		    break;
-		  }
-
-		case BRANCH_CONDITION_READ_REGISTER_WITH_WRITE_STACK    :
-		  {
-		    // Write stack
-		    is_accurate = false;
-		    miss_decod  = false;
-		    use_ras     = true;
-
-		    PORT_WRITE(out_DECOD_RAS_PUSH         [port],1);
-		    PORT_WRITE(out_DECOD_RAS_ADDRESS_PUSH [port],address_dest);
-		    
-		    break;
-		  }
-		case BRANCH_CONDITION_READ_STACK                        :
-		  {
-		    // Read stack
-		    is_accurate = PORT_READ(in_DECOD_RAS_HIT [port]);
-		    miss_decod  = false;
-		    use_ras     = true;
-
-		    PORT_WRITE(out_DECOD_RAS_PUSH         [port],0);
+		    PORT_WRITE(out_DECOD_RAS_PUSH         [port],0); // POP
 		    address_dest = PORT_READ(in_DECOD_RAS_ADDRESS_POP [port]);
 		    
@@ -125,7 +135,9 @@
 		case BRANCH_CONDITION_READ_REGISTER_WITHOUT_WRITE_STACK :
 		  {
+                    // l.jr with rb!=r9
+                    log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * BRANCH_CONDITION_READ_REGISTER_WITHOUT_WRITE_STACK");
+
 		    //   * READ_REGISTER_WITHOUT_WRITE_STACK : Take but destination is unknow - don't continue
-		    is_accurate = PORT_READ(in_DECOD_RAS_HIT [port]);
-		    miss_decod  = true;
+		    is_accurate = false; // address unknow : in a register
 
 		    break;
@@ -135,8 +147,9 @@
 		case BRANCH_CONDITION_FLAG_SET                          :
 		  {
-		    // No access at the flag
+		    // l.bf, l.bnf
 		    //   * FLAG                              : static direction and destination is know
-		    is_accurate = PORT_READ(in_DECOD_RAS_HIT [port]);
-		    miss_decod  = false;
+                    log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * BRANCH_CONDITION_FLAG");
+
+		    is_accurate = true; // address dest is know
 
 		    break;
@@ -145,16 +158,11 @@
 		case BRANCH_CONDITION_NONE_WITHOUT_WRITE_STACK          :
 		  {
-		    // No access at the flag
-		    //   * NONE_WITHOUT_WRITE_STACK          : take and destination is know
-		    is_accurate = false;
-		    miss_decod  = false;
-		    use_ras     = true;
-
-		    PORT_WRITE(out_DECOD_RAS_PUSH         [port],1);
-		    PORT_WRITE(out_DECOD_RAS_ADDRESS_PUSH [port],address_dest);
-
-		    break;
-		  }
-
+		    // l.j
+                    log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * BRANCH_CONDITION_NONE_WITHOUT_WRITE_STACK");
+
+		    is_accurate = true;
+
+		    break;
+		  }
 		}
 
@@ -180,19 +188,21 @@
 	      if (use_upt)
 		{
-		  PORT_WRITE(out_DECOD_UPT_BTB_ADDRESS_SRC      [port],address_src);
-		  PORT_WRITE(out_DECOD_UPT_BTB_ADDRESS_DEST     [port],address_dest);
-		  PORT_WRITE(out_DECOD_UPT_BTB_CONDITION        [port],condition);
-		  PORT_WRITE(out_DECOD_UPT_BTB_LAST_TAKE        [port],direction);
-		  PORT_WRITE(out_DECOD_UPT_RAS_ADDRESS          [port],PORT_READ(in_DECOD_RAS_ADDRESS_POP [port]));
+		  PORT_WRITE(out_DECOD_UPT_BTB_ADDRESS_SRC [port],address_src);
+		  PORT_WRITE(out_DECOD_UPT_BTB_ADDRESS_DEST[port],address_dest);
+		  PORT_WRITE(out_DECOD_UPT_BTB_CONDITION   [port],condition);
+		  PORT_WRITE(out_DECOD_UPT_BTB_LAST_TAKE   [port],direction);
+		  PORT_WRITE(out_DECOD_UPT_RAS_ADDRESS     [port],PORT_READ(in_DECOD_RAS_ADDRESS_POP [port]));
+		  PORT_WRITE(out_DECOD_UPT_IS_ACCURATE     [port],is_accurate);
 		}
 	    }
-	  else
-	    {
-	      log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * hit");
-
-	      miss_decod = false;
-	      // Hit speculation
-	    }
-	  
+// 	  else
+// 	    {
+//               log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * hit");
+
+// 	      miss_decod = false;
+// 	      // Hit speculation
+// 	    }
+	  
+
 	  // in all case
 	  log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * use_btb : %d",use_btb);
@@ -231,5 +241,5 @@
 	  PORT_WRITE(out_DECOD_UPT_MISS_IFETCH          [port],miss_ifetch); 
 	  PORT_WRITE(out_DECOD_UPT_MISS_DECOD           [port],miss_decod ); 
-	  if (_param->_have_port_max_depth)
+	  if (_param->_have_port_depth)
 	  PORT_WRITE(out_DECOD_UPT_UPDATE_PREDICTION_ID [port],depth);
 	  
@@ -237,4 +247,6 @@
 	}
     
+    // Write output
+
     for (uint32_t i=0; i<_param->_nb_inst_branch_decod; i++)
       {
@@ -251,5 +263,5 @@
 	  PORT_WRITE(out_DECOD_ACK [i][j], ack[j]);
 
-    log_printf(FUNC,Prediction_unit_Glue,FUNCTION,"End");
+    log_end(Prediction_unit_Glue,FUNCTION);
   };
 
