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 78)
+++ trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/SelfTest/src/test.cpp	(revision 81)
@@ -11,6 +11,6 @@
 #include "Behavioural/include/Allocation.h"
 
-#define NB_ITERATION  1024
-#define CYCLE_MAX     (128*NB_ITERATION)
+#define NB_ITERATION  16
+#define CYCLE_MAX     (1024*NB_ITERATION)
 
 #define LABEL(str...)							\
@@ -21,23 +21,21 @@
   } while(0)
 
-#define SC_START(cycle_offset)                                                       \
-  do									             \
-    {									             \
-      /*cout << "SC_START (begin)" << endl;*/				             \
-									             \
-      uint32_t cycle_current = static_cast<uint32_t>(sc_simulation_time());          \
-      if (cycle_offset != 0)						             \
-	{								             \
-	  cout << "##########[ cycle "<< cycle_current+cycle_offset << " ]" << endl; \
-	}								             \
-									             \
-      if (cycle_current > CYCLE_MAX)					             \
-	{								             \
-	  TEST_KO("Maximal cycles Reached");				             \
-	}								             \
-									             \
-      sc_start(cycle_offset);						             \
-									             \
-      /*cout << "SC_START (end  )" << endl;*/				             \
+#define SC_START(cycle_offset)						\
+  do									\
+    {									\
+      uint32_t cycle_current = static_cast<uint32_t>(sc_simulation_time()); \
+      if (cycle_offset != 0)						\
+	{								\
+	  cout << "##########[ cycle "<< cycle_current+cycle_offset << " ]"; \
+	  cout << " (" << __LINE__ << ")" << endl;			\
+	}								\
+      									\
+      if (cycle_current > CYCLE_MAX)					\
+	{								\
+	  TEST_KO("Maximal cycles Reached");				\
+	}								\
+      									\
+      sc_start(cycle_offset);						\
+      									\
     } while(0)
 
@@ -90,4 +88,5 @@
   ALLOC1_SC_SIGNAL( in_UPDATE_ADDRESS        ," in_UPDATE_ADDRESS        ",Taddress_t,_param->_nb_inst_update );
   ALLOC1_SC_SIGNAL( in_UPDATE_MISS_PREDICTION," in_UPDATE_MISS_PREDICTION",Tcontrol_t,_param->_nb_inst_update );
+  ALLOC1_SC_SIGNAL( in_UPDATE_PREDICTION_IFETCH," in_UPDATE_PREDICTION_IFETCH",Tcontrol_t,_param->_nb_inst_update );
   
   /********************************************************
@@ -127,4 +126,5 @@
   INSTANCE1_SC_SIGNAL(_Return_Address_Stack, in_UPDATE_ADDRESS        ,_param->_nb_inst_update );
   INSTANCE1_SC_SIGNAL(_Return_Address_Stack, in_UPDATE_MISS_PREDICTION,_param->_nb_inst_update );
+  INSTANCE1_SC_SIGNAL(_Return_Address_Stack, in_UPDATE_PREDICTION_IFETCH,_param->_nb_inst_update );
 
   msg(_("<%s> : Start Simulation ............\n"),name.c_str());
@@ -157,5 +157,276 @@
       LABEL("Iteration %d",iteration);
 
-      SC_START(1);
+      if (1)
+	{
+	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 (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);
+
+      }
     }
 
@@ -195,4 +466,6 @@
   delete []  in_UPDATE_INDEX         ;
   delete []  in_UPDATE_ADDRESS       ;
+  delete []  in_UPDATE_MISS_PREDICTION;
+  delete []  in_UPDATE_PREDICTION_IFETCH;
 
 #endif
