source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Stage_1_Ifetch/Predictor/Meta_Predictor/Two_Level_Branch_Predictor/Two_Level_Branch_Predictor_Glue/SelfTest/src/test.cpp @ 2

Last change on this file since 2 was 2, checked in by kane, 17 years ago

Import Morpheo

File size: 9.8 KB
Line 
1/*
2 * $Id$
3 *
4 * [ Description ]
5 *
6 * Test
7 */
8
9#define NB_ITERATION 64
10
11#include "Behavioural/Stage_1_Ifetch/Predictor/Meta_Predictor/Two_Level_Branch_Predictor/Two_Level_Branch_Predictor_Glue/SelfTest/include/test.h"
12#include "Include/BitManipulation.h"
13#include "Include/Test.h"
14
15void test (string name,
16           morpheo::behavioural::stage_1_ifetch::predictor::meta_predictor::two_level_branch_predictor::two_level_branch_predictor_glue::Parameters param)
17{
18  cout << "<" << name << "> : Simulation SystemC" << endl;
19
20  try 
21    {
22      cout << param.print(1);
23      param.test();
24    }
25  catch (morpheo::ErrorMorpheo & error)
26    {
27      cout << "<" << name << "> : " <<  error.what ();
28      return;
29    }
30  catch (...)
31    {
32      cerr << "<" << name << "> : This test must generate a error" << endl;
33      exit (EXIT_FAILURE);
34    }
35  Two_Level_Branch_Predictor_Glue * _Two_Level_Branch_Predictor_Glue = new Two_Level_Branch_Predictor_Glue (name.c_str(),
36#ifdef STATISTICS
37                                             morpheo::behavioural::Parameters_Statistics(5,50),
38#endif
39                                             param);
40 
41#ifdef SYSTEMC
42  /*********************************************************************
43   * Déclarations des signaux
44   *********************************************************************/
45  sc_clock                                 CLOCK ("clock", 1.0, 0.5);
46
47  sc_signal<Tcontrol_t>                    PREDICT_BHT_ACK             [param._nb_prediction];
48  sc_signal<Tcontrol_t>                    PREDICT_PHT_ACK             [param._nb_prediction];
49  sc_signal<Tcontrol_t>                    PREDICT_ACK                 [param._nb_prediction];
50                                           
51  sc_signal<Taddress_t>                    PREDICT_ADDRESS             [param._nb_prediction];
52  sc_signal<Tbht_history_t>                PREDICT_BHT_HISTORY         [param._nb_prediction];
53  sc_signal<Taddress_t>                    PREDICT_BHT_ADDRESS         [param._nb_prediction];
54  sc_signal<Taddress_t>                    PREDICT_PHT_ADDRESS         [param._nb_prediction];
55                                           
56  sc_signal<Tcontrol_t>                    BRANCH_COMPLETE_BHT_ACK     [param._nb_branch_complete];
57  sc_signal<Tcontrol_t>                    BRANCH_COMPLETE_PHT_ACK     [param._nb_branch_complete];
58  sc_signal<Tcontrol_t>                    BRANCH_COMPLETE_ACK         [param._nb_branch_complete];
59  sc_signal<Taddress_t>                    BRANCH_COMPLETE_ADDRESS     [param._nb_branch_complete];
60  sc_signal<Tbht_history_t>                BRANCH_COMPLETE_BHT_HISTORY [param._nb_branch_complete];
61  sc_signal<Taddress_t>                    BRANCH_COMPLETE_BHT_ADDRESS [param._nb_branch_complete];
62  sc_signal<Taddress_t>                    BRANCH_COMPLETE_PHT_ADDRESS [param._nb_branch_complete];
63 
64  /********************************************************
65   * Instanciation
66   ********************************************************/
67 
68  cout << "<" << name << "> Instanciation of _Two_Level_Branch_Predictor_Glue" << endl;
69 
70#if defined(STATISTICS) or defined(VHDL_TESTBENCH)
71  (*(_Two_Level_Branch_Predictor_Glue->in_CLOCK))        (CLOCK);
72#endif
73
74  for (uint32_t i=0; i<param._nb_prediction; i++)
75    {
76      if (param._have_bht)
77        {
78      (*(_Two_Level_Branch_Predictor_Glue-> in_PREDICT_BHT_ACK             [i])) (PREDICT_BHT_ACK             [i]);
79      (*(_Two_Level_Branch_Predictor_Glue->out_PREDICT_BHT_ADDRESS         [i])) (PREDICT_BHT_ADDRESS         [i]);
80        }
81      if (param._have_bht and param._have_pht)
82      (*(_Two_Level_Branch_Predictor_Glue-> in_PREDICT_BHT_HISTORY         [i])) (PREDICT_BHT_HISTORY         [i]);
83      if (param._have_pht)
84        {
85      (*(_Two_Level_Branch_Predictor_Glue-> in_PREDICT_PHT_ACK             [i])) (PREDICT_PHT_ACK             [i]);
86      (*(_Two_Level_Branch_Predictor_Glue->out_PREDICT_PHT_ADDRESS         [i])) (PREDICT_PHT_ADDRESS         [i]);
87        }
88      (*(_Two_Level_Branch_Predictor_Glue->out_PREDICT_ACK                 [i])) (PREDICT_ACK                 [i]);
89      (*(_Two_Level_Branch_Predictor_Glue-> in_PREDICT_ADDRESS             [i])) (PREDICT_ADDRESS             [i]);
90    }
91  for (uint32_t i=0; i<param._nb_branch_complete; i++)
92    {
93      if (param._have_bht)
94        {
95      (*(_Two_Level_Branch_Predictor_Glue-> in_BRANCH_COMPLETE_BHT_ACK     [i])) (BRANCH_COMPLETE_BHT_ACK     [i]);
96      (*(_Two_Level_Branch_Predictor_Glue->out_BRANCH_COMPLETE_BHT_ADDRESS [i])) (BRANCH_COMPLETE_BHT_ADDRESS [i]);
97        }
98      if (param._have_bht and param._have_pht)
99      (*(_Two_Level_Branch_Predictor_Glue-> in_BRANCH_COMPLETE_BHT_HISTORY [i])) (BRANCH_COMPLETE_BHT_HISTORY [i]);
100
101      if (param._have_pht)
102        {
103      (*(_Two_Level_Branch_Predictor_Glue-> in_BRANCH_COMPLETE_PHT_ACK     [i])) (BRANCH_COMPLETE_PHT_ACK     [i]);
104      (*(_Two_Level_Branch_Predictor_Glue->out_BRANCH_COMPLETE_PHT_ADDRESS [i])) (BRANCH_COMPLETE_PHT_ADDRESS [i]);
105        }
106      (*(_Two_Level_Branch_Predictor_Glue->out_BRANCH_COMPLETE_ACK         [i])) (BRANCH_COMPLETE_ACK         [i]);
107      (*(_Two_Level_Branch_Predictor_Glue-> in_BRANCH_COMPLETE_ADDRESS     [i])) (BRANCH_COMPLETE_ADDRESS     [i]);
108    }
109
110  /********************************************************
111   * Simulation - Begin
112   ********************************************************/
113
114  cout << "<" << name << "> Start Simulation ............" << endl;
115  // Initialisation
116
117  Tcontrol_t predict_bht_ack;
118  Tcontrol_t predict_pht_ack;
119
120  Tcontrol_t branch_complete_bht_ack;
121  Tcontrol_t branch_complete_pht_ack;
122 
123  srand(0);
124  //srand(time(NULL));
125
126  sc_start(0);
127  _Two_Level_Branch_Predictor_Glue->vhdl_testbench_label("Initialisation");
128  cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Initialisation" << endl;
129
130
131  _Two_Level_Branch_Predictor_Glue->vhdl_testbench_label("Test ack");
132  cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Test ack" << endl;
133
134  for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++)
135    {
136      _Two_Level_Branch_Predictor_Glue->vhdl_testbench_label("Iteration "+toString(iteration));
137
138      // Branch History Table
139      if (param._have_bht)
140        {
141          predict_bht_ack         = (rand()%2)!=0;
142          branch_complete_bht_ack = (rand()%2)!=0;
143
144        }
145      else
146        {
147          predict_bht_ack         = 1;
148          branch_complete_bht_ack = 1;
149        }
150
151      // Pattern History Table
152      if (param._have_pht)
153        {
154          predict_pht_ack         = (rand()%2)!=0;
155          branch_complete_pht_ack = (rand()%2)!=0;
156        }
157      else
158        {
159          predict_pht_ack         = 1;
160          branch_complete_pht_ack = 1;
161        }
162     
163      for (uint32_t i=0; i<param._nb_prediction;      i++)
164        {
165          PREDICT_BHT_ACK         [i] .write(predict_bht_ack);
166          PREDICT_PHT_ACK         [i] .write(predict_pht_ack);
167        }
168     
169      for (uint32_t i=0; i<param._nb_branch_complete; i++)
170        {
171          BRANCH_COMPLETE_BHT_ACK [i] .write(branch_complete_bht_ack);
172          BRANCH_COMPLETE_PHT_ACK [i] .write(branch_complete_pht_ack);
173        }
174     
175      sc_start(0);
176
177      // Test result
178      for (uint32_t i=0; i<param._nb_prediction;      i++)
179        TEST(Tcontrol_t,(predict_pht_ack & predict_bht_ack),PREDICT_ACK [i].read());
180
181      for (uint32_t i=0; i<param._nb_branch_complete;      i++)
182        TEST(Tcontrol_t,(branch_complete_pht_ack & branch_complete_bht_ack),BRANCH_COMPLETE_ACK [i].read());
183
184      sc_start(1);
185    }
186
187  Taddress_t     predict_address;
188  Tbht_history_t predict_bht_history;
189  Taddress_t     branch_complete_address;
190  Tbht_history_t branch_complete_bht_history;
191
192
193  _Two_Level_Branch_Predictor_Glue->vhdl_testbench_label("Test address");
194  cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Test address" << endl;
195
196  for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++)
197    {
198      _Two_Level_Branch_Predictor_Glue->vhdl_testbench_label("Iteration "+toString(iteration));
199     
200      predict_address             = rand()%(1<<param._size_address    );
201      predict_bht_history         = 0;
202      branch_complete_address     = rand()%(1<<param._size_address    );
203      branch_complete_bht_history = 0;
204
205      for (uint32_t i=0; i<param._nb_prediction; i++)
206        PREDICT_ADDRESS         [i].write (predict_address);
207      for (uint32_t i=0; i<param._nb_branch_complete; i++)
208        BRANCH_COMPLETE_ADDRESS [i].write (branch_complete_address);
209
210      // Branch History Table
211      if (param._have_bht and param._have_pht)
212        {
213          predict_bht_history         = rand()%(1<<param._bht_size_history);
214          branch_complete_bht_history = rand()%(1<<param._bht_size_history);
215         
216          for (uint32_t i=0; i<param._nb_prediction; i++)
217            PREDICT_BHT_HISTORY         [i].write(predict_bht_history);
218          for (uint32_t i=0; i<param._nb_branch_complete; i++)
219            BRANCH_COMPLETE_BHT_HISTORY [i].write(branch_complete_bht_history);
220        }
221
222      sc_start(0);
223
224      // Branch History Table
225      if (param._have_bht)
226        {
227          for (uint32_t i=0; i<param._nb_prediction; i++)
228            TEST(Taddress_t,PREDICT_BHT_ADDRESS [i].read(),(predict_address & gen_mask<Taddress_t>(param._bht_size_address)));
229
230          for (uint32_t i=0; i<param._nb_branch_complete; i++)
231            TEST(Taddress_t,BRANCH_COMPLETE_BHT_ADDRESS [i].read(),(branch_complete_address & gen_mask<Taddress_t>(param._bht_size_address)));
232        }
233
234      // Pattern History Table
235      if (param._have_pht)
236        {
237          uint32_t shift = (param._have_bht==false)?0:(param._pht_size_address_shift);
238
239          for (uint32_t i=0; i<param._nb_prediction; i++)
240            TEST(Taddress_t,PREDICT_PHT_ADDRESS [i].read(),(((predict_address << shift) xor predict_bht_history) & gen_mask<Taddress_t>(param._pht_size_address)));
241          for (uint32_t i=0; i<param._nb_branch_complete; i++)
242            TEST(Taddress_t,BRANCH_COMPLETE_PHT_ADDRESS [i].read(), (((branch_complete_address << shift) xor branch_complete_bht_history) & gen_mask<Taddress_t>(param._pht_size_address)));
243        }
244
245      sc_start(1);       
246    }
247  /********************************************************
248   * Simulation - End
249   ********************************************************/
250
251  cout << "<" << name << "> ............ Stop Simulation" << endl;
252
253#endif
254
255  delete _Two_Level_Branch_Predictor_Glue;
256}
Note: See TracBrowser for help on using the repository browser.