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

Last change on this file since 45 was 45, checked in by rosiere, 17 years ago
  • Documentation : specification d'un cache de donnée non bloquant
  • Modification de l'aborescence
File size: 11.8 KB
Line 
1/*
2 * $Id$
3 *
4 * [ Description ]
5 *
6 * Test
7 */
8
9#define NB_ITERATION 512
10
11#include "Behavioural/Stage_1_Ifetch/Predictor/Meta_Predictor/Two_Level_Branch_Predictor/SelfTest/include/test.h"
12#include "Common/include/Test.h"
13#include "Common/include/BitManipulation.h"
14void test (string name,
15           morpheo::behavioural::stage_1_ifetch::predictor::meta_predictor::two_level_branch_predictor::Parameters param)
16{
17  cout << "<" << name << "> : Simulation SystemC" << endl;
18
19  Two_Level_Branch_Predictor * _Two_Level_Branch_Predictor = new Two_Level_Branch_Predictor (name.c_str(),
20#ifdef STATISTICS
21                                             morpheo::behavioural::Parameters_Statistics(5,50),
22#endif
23                                             param);
24 
25#ifdef SYSTEMC
26
27  /*********************************************************************
28   * Déclarations des signaux
29   *********************************************************************/
30  sc_clock                              *  CLOCK;
31  sc_signal<Tcontrol_t>                 *  NRESET;
32
33  sc_signal<Tcontrol_t>                 *  PREDICT_VAL                 [param._nb_prediction];
34  sc_signal<Tcontrol_t>                 *  PREDICT_ACK                 [param._nb_prediction];
35  sc_signal<Taddress_t>                 *  PREDICT_ADDRESS             [param._nb_prediction];
36  sc_signal<Tbht_history_t>             *  PREDICT_BHT_HISTORY         [param._nb_prediction];
37  sc_signal<Tpht_history_t>             *  PREDICT_PHT_HISTORY         [param._nb_prediction];
38                                         
39  sc_signal<Tcontrol_t>                 *  BRANCH_COMPLETE_VAL         [param._nb_branch_complete];
40  sc_signal<Tcontrol_t>                 *  BRANCH_COMPLETE_ACK         [param._nb_branch_complete];
41  sc_signal<Taddress_t>                 *  BRANCH_COMPLETE_ADDRESS     [param._nb_branch_complete];
42  sc_signal<Tbht_history_t>             *  BRANCH_COMPLETE_BHT_HISTORY [param._nb_branch_complete];
43  sc_signal<Tpht_history_t>             *  BRANCH_COMPLETE_PHT_HISTORY [param._nb_branch_complete];
44  sc_signal<Tcontrol_t>                 *  BRANCH_COMPLETE_DIRECTION   [param._nb_branch_complete];
45
46  // Rename signal
47
48  string rename;
49
50  CLOCK  = new sc_clock              ("clock", 1.0, 0.5);
51  NRESET = new sc_signal<Tcontrol_t> ("NRESET");
52
53  for (uint32_t i=0; i<param._nb_prediction; i++)
54    {
55      rename = "PREDICT_VAL_"        +toString(i);
56      PREDICT_VAL                 [i] = new sc_signal<Tcontrol_t>     (rename.c_str());
57      rename = "PREDICT_ACK_"        +toString(i);
58      PREDICT_ACK                 [i] = new sc_signal<Tcontrol_t>     (rename.c_str());
59      rename = "PREDICT_ADDRESS_"    +toString(i);
60      PREDICT_ADDRESS             [i] = new sc_signal<Taddress_t>     (rename.c_str());
61      rename = "PREDICT_BHT_HISTORY_"+toString(i);
62      PREDICT_BHT_HISTORY         [i] = new sc_signal<Tbht_history_t> (rename.c_str());
63      rename = "PREDICT_PHT_HISTORY_"+toString(i);
64      PREDICT_PHT_HISTORY         [i] = new sc_signal<Tpht_history_t> (rename.c_str());
65    }
66 
67  for (uint32_t i=0; i<param._nb_branch_complete; i++)
68    {
69      rename = "BRANCH_COMPLETE_VAL_"        +toString(i);
70      BRANCH_COMPLETE_VAL         [i] = new sc_signal<Tcontrol_t>     (rename.c_str());
71      rename = "BRANCH_COMPLETE_ACK_"        +toString(i);
72      BRANCH_COMPLETE_ACK         [i] = new sc_signal<Tcontrol_t>     (rename.c_str());
73      rename = "BRANCH_COMPLETE_ADDRESS_"    +toString(i);
74      BRANCH_COMPLETE_ADDRESS     [i] = new sc_signal<Taddress_t>     (rename.c_str());
75      rename = "BRANCH_COMPLETE_BHT_HISTORY_"+toString(i);
76      BRANCH_COMPLETE_BHT_HISTORY [i] = new sc_signal<Tbht_history_t> (rename.c_str());
77      rename = "BRANCH_COMPLETE_PHT_HISTORY_"+toString(i);
78      BRANCH_COMPLETE_PHT_HISTORY [i] = new sc_signal<Tpht_history_t> (rename.c_str());
79      rename = "BRANCH_COMPLETE_DIRECTION_"  +toString(i);
80      BRANCH_COMPLETE_DIRECTION   [i] = new sc_signal<Tcontrol_t>     (rename.c_str());
81    }
82
83  /********************************************************
84   * Instanciation
85   ********************************************************/
86 
87  cout << "<" << name << "> Instanciation of _Two_Level_Branch_Predictor" << endl;
88 
89  (*(_Two_Level_Branch_Predictor->in_CLOCK ))        (*(CLOCK ));
90  (*(_Two_Level_Branch_Predictor->in_NRESET))        (*(NRESET));
91 
92  for (uint32_t i=0; i<param._nb_prediction; i++)
93    {
94      (*(_Two_Level_Branch_Predictor-> in_PREDICT_VAL                 [i])) (*(PREDICT_VAL                  [i]));
95      (*(_Two_Level_Branch_Predictor->out_PREDICT_ACK                 [i])) (*(PREDICT_ACK                  [i]));
96      (*(_Two_Level_Branch_Predictor-> in_PREDICT_ADDRESS             [i])) (*(PREDICT_ADDRESS              [i]));
97      if (param._have_bht)                                                                                     
98      (*(_Two_Level_Branch_Predictor->out_PREDICT_BHT_HISTORY         [i])) (*(PREDICT_BHT_HISTORY          [i]));
99      if (param._have_pht)
100      (*(_Two_Level_Branch_Predictor->out_PREDICT_PHT_HISTORY         [i])) (*(PREDICT_PHT_HISTORY          [i]));
101    }
102
103    for (uint32_t i=0; i<param._nb_branch_complete; i++)
104      {
105        (*(_Two_Level_Branch_Predictor-> in_BRANCH_COMPLETE_VAL         [i])) (*(BRANCH_COMPLETE_VAL          [i]));
106        (*(_Two_Level_Branch_Predictor->out_BRANCH_COMPLETE_ACK         [i])) (*(BRANCH_COMPLETE_ACK          [i]));
107        (*(_Two_Level_Branch_Predictor-> in_BRANCH_COMPLETE_ADDRESS     [i])) (*(BRANCH_COMPLETE_ADDRESS      [i]));
108        if (param._have_bht)                                                                                   
109        (*(_Two_Level_Branch_Predictor-> in_BRANCH_COMPLETE_BHT_HISTORY [i])) (*(BRANCH_COMPLETE_BHT_HISTORY  [i]));
110        if (param._have_pht)                                                                                   
111        (*(_Two_Level_Branch_Predictor-> in_BRANCH_COMPLETE_PHT_HISTORY [i])) (*(BRANCH_COMPLETE_PHT_HISTORY  [i]));
112        (*(_Two_Level_Branch_Predictor-> in_BRANCH_COMPLETE_DIRECTION   [i])) (*(BRANCH_COMPLETE_DIRECTION    [i]));
113      }
114
115  /********************************************************
116   * Simulation - Begin
117   ********************************************************/
118
119  cout << "<" << name << "> Start Simulation ............" << endl;
120  // Initialisation
121
122  const uint32_t seed = 0;
123//const uint32_t seed = static_cast<uint32_t>(time(NULL));
124
125  srand(seed);
126
127  const uint32_t   num_port_predict         = rand()%param._nb_prediction;
128  const uint32_t   num_port_branch_complete = rand()%param._nb_branch_complete;
129  const Taddress_t address                  = rand()%param._size_address;
130        Tcontrol_t direction;
131
132  sc_start(0);
133
134  NRESET->write(0);
135  sc_start(5);
136  NRESET->write(1);
137
138  for (uint32_t i=0; i<param._nb_prediction; i++)
139    PREDICT_VAL                  [i]->write(0);
140  for (uint32_t i=0; i<param._nb_branch_complete; i++)
141    BRANCH_COMPLETE_VAL          [i]->write(0);
142
143  cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Initialisation" << endl;
144
145  // Step 1
146  BRANCH_COMPLETE_VAL          [num_port_branch_complete]->write(1);
147  BRANCH_COMPLETE_DIRECTION    [num_port_branch_complete]->write(0);
148
149  if (param._have_pht)                                                                                 
150    {
151      // Step 1.1 -> pattern_history_table
152
153      // Step 1.1.1 compute number of group.
154      uint32_t size_address_shift=0;
155
156      if (param._have_bht)
157        size_address_shift=param._param_two_level_branch_predictor_glue->_pht_size_address_shift;
158
159      uint32_t nb_group        = (1<<size_address_shift);
160      uint32_t nb_reg_by_group = (1<<(param._pht_size_address-size_address_shift));
161
162//       cout << "pht_size_address           : " << param._pht_size_address << endl;
163//       cout << "size_address_shift         : " << size_address_shift << endl;
164//       cout << "nb_group                   : " << nb_group           << endl;
165//       cout << "nb_reg_by_group            : " << nb_reg_by_group    << endl;
166
167      cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Init pht" << endl;
168     
169      BRANCH_COMPLETE_PHT_HISTORY  [num_port_branch_complete]->write(0);
170
171      // Step 1.1.2 for all group ...
172      for (uint32_t i=0; i<nb_group; i++)
173        {
174          if (param._have_bht)
175            BRANCH_COMPLETE_BHT_HISTORY  [num_port_branch_complete]->write(i);
176
177          for (uint32_t j=0; j<nb_reg_by_group; j++)
178            {
179              cout << "j : " << j << " on " << nb_reg_by_group << endl;
180              BRANCH_COMPLETE_ADDRESS [num_port_branch_complete]->write(j);
181
182              sc_start(1);
183
184              // wait ackwolegde
185              while (BRANCH_COMPLETE_ACK [num_port_branch_complete] -> read() == 0)
186                {
187                  sc_start(1);
188                }
189            }
190        }
191    }
192
193  if (param._have_bht)                                                                                 
194    {
195      // Step 1.2 -> branch_history_table
196      BRANCH_COMPLETE_BHT_HISTORY  [num_port_branch_complete]->write(0);
197     
198      cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Init bht" << endl;
199     
200      for (uint32_t i=0; i<param._bht_nb_shifter; i++)
201        {
202          BRANCH_COMPLETE_ADDRESS [num_port_branch_complete]->write(i);
203
204          sc_start(1);
205        }
206
207      // wait ackwolegde
208      while (BRANCH_COMPLETE_ACK [num_port_branch_complete] -> read() == 0)
209        {
210          sc_start(1);
211        }
212    }
213
214  // Step 2
215  BRANCH_COMPLETE_VAL          [num_port_branch_complete]->write(0);
216  PREDICT_ADDRESS              [num_port_predict        ]->write(address);
217  BRANCH_COMPLETE_ADDRESS      [num_port_branch_complete]->write(address);
218
219  cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Loop of Test" << endl
220       << " * predict_address : " << hex << address << dec << endl;
221 
222  // A lot of prediction
223  Tbht_history_t bht_history = 0;
224  Tpht_history_t pht_history [1<<param._bht_size_shifter];
225 
226  for (uint32_t i=0; i<static_cast<uint32_t>(1<<param._bht_size_shifter); i++)
227    pht_history [i] = 0;
228
229  for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++)
230    {
231      cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Predict          : bht_history " << bht_history << " - pht_history " << pht_history[bht_history] << endl; 
232
233
234      // Ask a new prediction
235      PREDICT_VAL                  [num_port_predict        ]->write(1);
236
237      sc_start(1);
238
239      // wait ackwolegde
240      while (PREDICT_ACK [num_port_predict] -> read() == 0)
241        {
242          sc_start(1);
243        }
244      PREDICT_ACK                  [num_port_predict        ]->write(0);
245
246      sc_start(0);
247
248      // Test
249      cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Predict (Test)   : " << endl; 
250      if (param._have_bht)
251        {
252          cout << "\tbht_history " << PREDICT_BHT_HISTORY[num_port_predict]->read() << endl;
253          TEST(Tbht_history_t,bht_history             ,PREDICT_BHT_HISTORY[num_port_predict]->read());
254        }
255      if (param._have_pht)
256        {
257          cout << "\tpht_history " << PREDICT_PHT_HISTORY[num_port_predict]->read() << endl;
258          TEST(Tpht_history_t,pht_history[bht_history],PREDICT_PHT_HISTORY[num_port_predict]->read());
259        }
260
261      // update
262      direction = ((rand()%2)==1);
263
264      BRANCH_COMPLETE_VAL          [num_port_branch_complete]->write(1);
265      if (param._have_bht)
266      BRANCH_COMPLETE_BHT_HISTORY  [num_port_branch_complete]->write(bht_history             );
267
268
269      if (param._have_pht)
270      BRANCH_COMPLETE_PHT_HISTORY  [num_port_branch_complete]->write(pht_history[bht_history]);
271      BRANCH_COMPLETE_DIRECTION    [num_port_branch_complete]->write(direction);
272
273      if (param._have_pht)
274      if (direction == 0)
275        {
276          if (pht_history[bht_history] > 0)
277            pht_history[bht_history] --;
278        }
279      else
280        {
281          if (pht_history[bht_history] < (static_cast<Tpht_history_t>(1<<param._pht_size_counter)-1))
282            pht_history[bht_history] ++;
283        }
284
285      if (param._have_bht)
286      bht_history              = (((bht_history) << 1) | direction) & gen_mask<Tbht_history_t>(param._bht_size_shifter);
287
288      sc_start(1);
289
290      // wait ackwolegde
291      while (BRANCH_COMPLETE_ACK [num_port_branch_complete] -> read() == 0)
292        {
293          sc_start(1);
294        }
295      BRANCH_COMPLETE_VAL          [num_port_branch_complete]->write(0);
296    }
297
298  /********************************************************
299   * Simulation - End
300   ********************************************************/
301
302  cout << "<" << name << "> ............ Stop Simulation" << endl;
303
304#endif
305
306  delete _Two_Level_Branch_Predictor;
307}
Note: See TracBrowser for help on using the repository browser.