source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Direction/Meta_Predictor/Two_Level_Branch_Predictor/SelfTest/src/test.cpp @ 111

Last change on this file since 111 was 111, checked in by rosiere, 15 years ago

1) Decod_queue : multi implementation (one_fifo, multi_fifo)
2) Issue_queue : multi implementation (in_order, out_of_order)
3) Direction : Add Meta predictor
4) Context_State : re add Branch_complete, More priority to Load miss (is not speculative)
5) Return_Address_Stack : update reg_PREDICT pointer on decod miss prediction
6) UPT : Fix bug in multi event
7) Prediction_glue : in read_stack case, insert in UPT pc_next
8) Rename select : when rob have an event (need flush), read_r{a,b,c} and write_r{d,e} is set at 0

  • Property svn:keywords set to Id
File size: 9.8 KB
Line 
1/*
2 * $Id: test.cpp 111 2009-02-27 18:37:40Z rosiere $
3 *
4 * [ Description ]
5 *
6 * Test
7 */
8
9#include "Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Direction/Meta_Predictor/Two_Level_Branch_Predictor/SelfTest/include/test.h"
10#include "Behavioural/include/Allocation.h"
11
12void test (string name,
13           morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::direction::meta_predictor::two_level_branch_predictor::Parameters * _param)
14{
15  msg(_("<%s> : Simulation SystemC.\n"),name.c_str());
16
17  if (setlocale (LC_ALL, "") == NULL)
18    msg(_("setlocale ko.\n"));
19
20#ifdef STATISTICS
21  morpheo::behavioural::Parameters_Statistics * _parameters_statistics = new morpheo::behavioural::Parameters_Statistics (5,CYCLE_MAX);
22#endif
23
24  Tusage_t _usage = USE_ALL;
25
26//   _usage = usage_unset(_usage,USE_SYSTEMC              );
27//   _usage = usage_unset(_usage,USE_VHDL                 );
28//   _usage = usage_unset(_usage,USE_VHDL_TESTBENCH       );
29//   _usage = usage_unset(_usage,USE_VHDL_TESTBENCH_ASSERT);
30//   _usage = usage_unset(_usage,USE_POSITION             );
31//   _usage = usage_unset(_usage,USE_STATISTICS           );
32//   _usage = usage_unset(_usage,USE_INFORMATION          );
33
34  Two_Level_Branch_Predictor * _Two_Level_Branch_Predictor = new Two_Level_Branch_Predictor
35    (name.c_str(),
36#ifdef STATISTICS
37     _parameters_statistics,
38#endif
39     _param,
40     _usage);
41 
42#ifdef SYSTEMC
43  if (usage_is_set(_usage,USE_SYSTEMC))
44    {
45  /*********************************************************************
46   * Déclarations des signaux
47   *********************************************************************/
48  string rename;
49
50  sc_clock              *  in_CLOCK  = new sc_clock ("clock", 1.0, 0.5);         
51  sc_signal<Tcontrol_t> *  in_NRESET = new sc_signal<Tcontrol_t> ("NRESET");
52
53  ALLOC1_SC_SIGNAL( in_PREDICT_VAL          ," in_PREDICT_VAL          ",Tcontrol_t,_param->_nb_inst_predict);
54  ALLOC1_SC_SIGNAL(out_PREDICT_ACK          ,"out_PREDICT_ACK          ",Tcontrol_t,_param->_nb_inst_predict);
55  ALLOC1_SC_SIGNAL( in_PREDICT_ADDRESS      ," in_PREDICT_ADDRESS      ",Taddress_t,_param->_nb_inst_predict);
56  ALLOC1_SC_SIGNAL(out_PREDICT_DIRECTION    ,"out_PREDICT_DIRECTION    ",Tcontrol_t,_param->_nb_inst_predict);
57  ALLOC1_SC_SIGNAL(out_PREDICT_HISTORY      ,"out_PREDICT_HISTORY      ",Thistory_t,_param->_nb_inst_predict);
58  ALLOC1_SC_SIGNAL( in_PREDICT_DIRECTION_VAL," in_PREDICT_DIRECTION_VAL",Tcontrol_t,_param->_nb_inst_predict);
59  ALLOC1_SC_SIGNAL( in_PREDICT_DIRECTION    ," in_PREDICT_DIRECTION    ",Tcontrol_t,_param->_nb_inst_predict);
60 
61  ALLOC1_SC_SIGNAL( in_UPDATE_VAL           ," in_UPDATE_VAL           ",Tcontrol_t,_param->_nb_inst_update);
62  ALLOC1_SC_SIGNAL(out_UPDATE_ACK           ,"out_UPDATE_ACK           ",Tcontrol_t,_param->_nb_inst_update);
63  ALLOC1_SC_SIGNAL( in_UPDATE_ADDRESS       ," in_UPDATE_ADDRESS       ",Taddress_t,_param->_nb_inst_update);
64  ALLOC1_SC_SIGNAL( in_UPDATE_HISTORY       ," in_UPDATE_HISTORY       ",Thistory_t,_param->_nb_inst_update);
65  ALLOC1_SC_SIGNAL( in_UPDATE_DIRECTION     ," in_UPDATE_DIRECTION     ",Tcontrol_t,_param->_nb_inst_update);
66  ALLOC1_SC_SIGNAL( in_UPDATE_MISS          ," in_UPDATE_MISS          ",Tcontrol_t,_param->_nb_inst_update);
67 
68  /********************************************************
69   * Instanciation
70   ********************************************************/
71 
72  msg(_("<%s> : Instanciation of _Two_Level_Branch_Predictor.\n"),name.c_str());
73
74  (*(_Two_Level_Branch_Predictor->in_CLOCK))        (*(in_CLOCK));
75  (*(_Two_Level_Branch_Predictor->in_NRESET))       (*(in_NRESET));
76
77  INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor, in_PREDICT_VAL          ,_param->_nb_inst_predict);
78  INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor,out_PREDICT_ACK          ,_param->_nb_inst_predict);
79  INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor, in_PREDICT_ADDRESS      ,_param->_nb_inst_predict);
80  INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor,out_PREDICT_DIRECTION    ,_param->_nb_inst_predict);
81  INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor,out_PREDICT_HISTORY      ,_param->_nb_inst_predict);
82  if (_param->_update_on_prediction)
83    {
84  INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor, in_PREDICT_DIRECTION_VAL,_param->_nb_inst_predict);
85  INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor, in_PREDICT_DIRECTION    ,_param->_nb_inst_predict);
86    }
87
88  INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor, in_UPDATE_VAL           ,_param->_nb_inst_update);
89  INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor,out_UPDATE_ACK           ,_param->_nb_inst_update);
90  INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor, in_UPDATE_ADDRESS       ,_param->_nb_inst_update);
91  INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor, in_UPDATE_HISTORY       ,_param->_nb_inst_update);
92  INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor, in_UPDATE_DIRECTION     ,_param->_nb_inst_update);
93  if (_param->_update_on_prediction)
94  INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor, in_UPDATE_MISS          ,_param->_nb_inst_update);
95
96  msg(_("<%s> : Start Simulation ............\n"),name.c_str());
97   
98  Time * _time = new Time();
99
100  /********************************************************
101   * Simulation - Begin
102   ********************************************************/
103
104  // Initialisation
105
106  const uint32_t seed = 0;
107//const uint32_t seed = static_cast<uint32_t>(time(NULL));
108
109  srand(seed);
110
111  const  int32_t percent_transaction_predict = 75;
112  const  int32_t percent_transaction_update  = 75;
113
114  SC_START(0);
115  LABEL("Initialisation");
116
117  for (uint32_t i=0; i<_param->_nb_inst_predict; ++i)
118    in_PREDICT_VAL [i]->write(0);
119  for (uint32_t i=0; i<_param->_nb_inst_update; ++i)
120    in_UPDATE_VAL [i]->write(0);
121
122  LABEL("Reset");
123  in_NRESET->write(0);
124  SC_START(5);
125  in_NRESET->write(1); 
126
127  LABEL("Loop of Test");
128 
129  Thistory_t bht;
130  Thistory_t pht [_param->_pht_size_bank];
131 
132  for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++)
133    {
134      LABEL("Iteration %d",iteration);
135
136      uint32_t bht_num_reg  = (_param->_have_bht)?(rand()%_param->_bht_nb_shifter):0;
137      uint32_t pht_num_bank = (_param->_have_pht)?(rand()%_param->_pht_nb_bank   ):0;
138
139      LABEL("  * bht_num_reg  : %d",bht_num_reg );
140      LABEL("  * pht_num_bank : %d",pht_num_bank);
141
142      {
143        LABEL("Init BHT and PHT");
144
145        bht = 0;
146        for (uint32_t i=0; i<_param->_pht_size_bank; ++i)
147          pht [i] = 0;
148       
149        uint32_t port = rand()%_param->_nb_inst_update;
150
151        if (_param->_have_bht)
152          {       
153            bool find = false;
154            while (not find)
155              {
156                bool val = ((rand()%2)<percent_transaction_update);
157                in_UPDATE_VAL       [port]->write(val);
158                in_UPDATE_DIRECTION [port]->write(0);
159               
160                if (_param->_update_on_prediction)
161                  in_UPDATE_MISS      [port]->write(1); // miss
162                in_UPDATE_HISTORY   [port]->write(0);
163                in_UPDATE_ADDRESS   [port]->write(bht_num_reg);
164               
165                SC_START(0);
166               
167                if (val and out_UPDATE_ACK [port]->read())
168                  {
169                    LABEL("UPDATE[%d] - Transaction accepted",port);
170                    find = true;
171                  }
172               
173                SC_START(1);
174              }
175            in_UPDATE_VAL [port]->write(0);
176          }
177
178        if (_param->_have_pht)
179          {       
180            for (uint32_t i=0; i<_param->_pht_size_bank; ++i)
181              {
182                bool find = false;
183               
184                while (not find)
185                  {
186                    bool val = ((rand()%2)<percent_transaction_update);
187                    in_UPDATE_VAL       [port]->write(val);
188                    in_UPDATE_DIRECTION [port]->write(0);
189                   
190                    if (_param->_update_on_prediction)
191                      in_UPDATE_MISS      [port]->write(1); // miss
192                    in_UPDATE_HISTORY   [port]->write(i<<_param->_bht_history_rshift);
193                    in_UPDATE_ADDRESS   [port]->write(pht_num_bank<<_param->_pht_address_bank_rshift);
194                   
195                    SC_START(0);
196                   
197                    if (val and out_UPDATE_ACK [port]->read())
198                      {
199                        LABEL("UPDATE[%d] - Transaction accepted",port);
200                        find = true;
201                      }
202                   
203                    SC_START(1);
204                  }
205                in_UPDATE_VAL [port]->write(0);
206              }
207          }
208      }
209
210//       if (1)
211//         {
212//           LABEL("Saturation all PHT");
213         
214//         }
215
216      SC_START(1);
217    }
218
219  /********************************************************
220   * Simulation - End
221   ********************************************************/
222
223  TEST_OK ("End of Simulation");
224  delete _time;
225
226  msg(_("<%s> : ............ Stop Simulation\n"),name.c_str());
227
228  delete in_CLOCK;
229  delete in_NRESET;
230
231  DELETE1_SC_SIGNAL( in_PREDICT_VAL          ,_param->_nb_inst_predict);
232  DELETE1_SC_SIGNAL(out_PREDICT_ACK          ,_param->_nb_inst_predict);
233  DELETE1_SC_SIGNAL( in_PREDICT_ADDRESS      ,_param->_nb_inst_predict);
234  DELETE1_SC_SIGNAL(out_PREDICT_DIRECTION    ,_param->_nb_inst_predict);
235  DELETE1_SC_SIGNAL(out_PREDICT_HISTORY      ,_param->_nb_inst_predict);
236  DELETE1_SC_SIGNAL( in_PREDICT_DIRECTION_VAL,_param->_nb_inst_predict);
237  DELETE1_SC_SIGNAL( in_PREDICT_DIRECTION    ,_param->_nb_inst_predict);
238
239  DELETE1_SC_SIGNAL( in_UPDATE_VAL           ,_param->_nb_inst_update);
240  DELETE1_SC_SIGNAL(out_UPDATE_ACK           ,_param->_nb_inst_update);
241  DELETE1_SC_SIGNAL( in_UPDATE_ADDRESS       ,_param->_nb_inst_update);
242  DELETE1_SC_SIGNAL( in_UPDATE_HISTORY       ,_param->_nb_inst_update);
243  DELETE1_SC_SIGNAL( in_UPDATE_DIRECTION     ,_param->_nb_inst_update);
244  DELETE1_SC_SIGNAL( in_UPDATE_MISS          ,_param->_nb_inst_update);
245    }
246#endif
247
248  delete _Two_Level_Branch_Predictor;
249#ifdef STATISTICS
250  delete _parameters_statistics;
251#endif
252}
Note: See TracBrowser for help on using the repository browser.