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

Last change on this file since 88 was 88, checked in by rosiere, 16 years ago

Almost complete design
with Test and test platform

  • Property svn:keywords set to Id
File size: 12.8 KB
Line 
1/*
2 * $Id: test.cpp 88 2008-12-10 18:31:39Z rosiere $
3 *
4 * [ Description ]
5 *
6 * Test
7 */
8
9#define NB_ITERATION  1024
10#define CYCLE_MAX     (128*NB_ITERATION)
11
12#include "Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Direction/Direction_Glue/SelfTest/include/test.h"
13#include "Common/include/Test.h"
14#include "Common/include/BitManipulation.h"
15#include "Behavioural/include/Allocation.h"
16
17void test (string name,
18           morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::direction::direction_glue::Parameters * _param)
19{
20  msg(_("<%s> : Simulation SystemC.\n"),name.c_str());
21
22#ifdef STATISTICS
23  morpheo::behavioural::Parameters_Statistics * _parameters_statistics = new morpheo::behavioural::Parameters_Statistics (5,50);
24#endif
25
26  Tusage_t _usage = USE_ALL;
27
28//   _usage = usage_unset(_usage,USE_SYSTEMC              );
29//   _usage = usage_unset(_usage,USE_VHDL                 );
30//   _usage = usage_unset(_usage,USE_VHDL_TESTBENCH       );
31//   _usage = usage_unset(_usage,USE_VHDL_TESTBENCH_ASSERT);
32//   _usage = usage_unset(_usage,USE_POSITION             );
33//   _usage = usage_unset(_usage,USE_STATISTICS           );
34//   _usage = usage_unset(_usage,USE_INFORMATION          );
35
36  Direction_Glue * _Direction_Glue = new Direction_Glue
37    (name.c_str(),
38#ifdef STATISTICS
39     _parameters_statistics,
40#endif
41     _param,
42     _usage);
43 
44#ifdef SYSTEMC
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_SRC          ," in_PREDICT_ADDRESS_SRC          ",Taddress_t,_param->_nb_inst_predict);
56  ALLOC1_SC_SIGNAL( in_PREDICT_STATIC               ," in_PREDICT_STATIC               ",Tcontrol_t,_param->_nb_inst_predict);
57  ALLOC1_SC_SIGNAL( in_PREDICT_LAST_TAKE            ," in_PREDICT_LAST_TAKE            ",Tcontrol_t,_param->_nb_inst_predict);
58  ALLOC1_SC_SIGNAL(out_PREDICT_HISTORY              ,"out_PREDICT_HISTORY              ",Thistory_t,_param->_nb_inst_predict);
59  ALLOC1_SC_SIGNAL(out_PREDICT_DIRECTION            ,"out_PREDICT_DIRECTION            ",Tcontrol_t,_param->_nb_inst_predict);
60  ALLOC1_SC_SIGNAL(out_PREDICT_PREDICTOR_VAL        ,"out_PREDICT_PREDICTOR_VAL        ",Tcontrol_t,_param->_nb_inst_predict);
61  ALLOC1_SC_SIGNAL( in_PREDICT_PREDICTOR_ACK        ," in_PREDICT_PREDICTOR_ACK        ",Tcontrol_t,_param->_nb_inst_predict);
62  ALLOC1_SC_SIGNAL(out_PREDICT_PREDICTOR_ADDRESS_SRC,"out_PREDICT_PREDICTOR_ADDRESS_SRC",Taddress_t,_param->_nb_inst_predict);
63  ALLOC1_SC_SIGNAL( in_PREDICT_PREDICTOR_HISTORY    ," in_PREDICT_PREDICTOR_HISTORY    ",Thistory_t,_param->_nb_inst_predict);
64  ALLOC1_SC_SIGNAL( in_PREDICT_PREDICTOR_DIRECTION  ," in_PREDICT_PREDICTOR_DIRECTION  ",Tcontrol_t,_param->_nb_inst_predict);
65  ALLOC1_SC_SIGNAL( in_UPDATE_VAL                   ," in_UPDATE_VAL                   ",Tcontrol_t,_param->_nb_inst_update);
66  ALLOC1_SC_SIGNAL(out_UPDATE_ACK                   ,"out_UPDATE_ACK                   ",Tcontrol_t,_param->_nb_inst_update);
67  ALLOC1_SC_SIGNAL( in_UPDATE_ADDRESS               ," in_UPDATE_ADDRESS               ",Taddress_t,_param->_nb_inst_update);
68  ALLOC1_SC_SIGNAL( in_UPDATE_HISTORY               ," in_UPDATE_HISTORY               ",Thistory_t,_param->_nb_inst_update);
69  ALLOC1_SC_SIGNAL( in_UPDATE_DIRECTION             ," in_UPDATE_DIRECTION             ",Tcontrol_t,_param->_nb_inst_update);
70  ALLOC1_SC_SIGNAL(out_UPDATE_PREDICTOR_VAL         ,"out_UPDATE_PREDICTOR_VAL         ",Tcontrol_t,_param->_nb_inst_update);
71  ALLOC1_SC_SIGNAL( in_UPDATE_PREDICTOR_ACK         ," in_UPDATE_PREDICTOR_ACK         ",Tcontrol_t,_param->_nb_inst_update);
72  ALLOC1_SC_SIGNAL(out_UPDATE_PREDICTOR_ADDRESS     ,"out_UPDATE_PREDICTOR_ADDRESS     ",Taddress_t,_param->_nb_inst_update);
73  ALLOC1_SC_SIGNAL(out_UPDATE_PREDICTOR_HISTORY     ,"out_UPDATE_PREDICTOR_HISTORY     ",Thistory_t,_param->_nb_inst_update);
74  ALLOC1_SC_SIGNAL(out_UPDATE_PREDICTOR_DIRECTION   ,"out_UPDATE_PREDICTOR_DIRECTION   ",Tcontrol_t,_param->_nb_inst_update);
75
76  /********************************************************
77   * Instanciation
78   ********************************************************/
79 
80  msg(_("<%s> : Instanciation of _Direction_Glue.\n"),name.c_str());
81
82  (*(_Direction_Glue->in_CLOCK))        (*(in_CLOCK));
83  (*(_Direction_Glue->in_NRESET))       (*(in_NRESET));
84
85  INSTANCE1_SC_SIGNAL(_Direction_Glue, in_PREDICT_VAL                  ,_param->_nb_inst_predict);
86  INSTANCE1_SC_SIGNAL(_Direction_Glue,out_PREDICT_ACK                  ,_param->_nb_inst_predict);
87  INSTANCE1_SC_SIGNAL(_Direction_Glue, in_PREDICT_ADDRESS_SRC          ,_param->_nb_inst_predict);
88  INSTANCE1_SC_SIGNAL(_Direction_Glue, in_PREDICT_STATIC               ,_param->_nb_inst_predict);
89  INSTANCE1_SC_SIGNAL(_Direction_Glue, in_PREDICT_LAST_TAKE            ,_param->_nb_inst_predict);
90  if (_param->_have_port_history)
91  INSTANCE1_SC_SIGNAL(_Direction_Glue,out_PREDICT_HISTORY              ,_param->_nb_inst_predict);
92  INSTANCE1_SC_SIGNAL(_Direction_Glue,out_PREDICT_DIRECTION            ,_param->_nb_inst_predict);
93  if (_param->_have_component_meta_predictor)
94    {
95  INSTANCE1_SC_SIGNAL(_Direction_Glue,out_PREDICT_PREDICTOR_VAL        ,_param->_nb_inst_predict);
96  INSTANCE1_SC_SIGNAL(_Direction_Glue, in_PREDICT_PREDICTOR_ACK        ,_param->_nb_inst_predict);
97  INSTANCE1_SC_SIGNAL(_Direction_Glue,out_PREDICT_PREDICTOR_ADDRESS_SRC,_param->_nb_inst_predict);
98  if (_param->_have_port_history)
99  INSTANCE1_SC_SIGNAL(_Direction_Glue, in_PREDICT_PREDICTOR_HISTORY    ,_param->_nb_inst_predict);
100  INSTANCE1_SC_SIGNAL(_Direction_Glue, in_PREDICT_PREDICTOR_DIRECTION  ,_param->_nb_inst_predict);
101    }
102
103  INSTANCE1_SC_SIGNAL(_Direction_Glue, in_UPDATE_VAL                   ,_param->_nb_inst_update );
104  INSTANCE1_SC_SIGNAL(_Direction_Glue,out_UPDATE_ACK                   ,_param->_nb_inst_update );
105  INSTANCE1_SC_SIGNAL(_Direction_Glue, in_UPDATE_ADDRESS               ,_param->_nb_inst_update );
106  if (_param->_have_port_history)
107  INSTANCE1_SC_SIGNAL(_Direction_Glue, in_UPDATE_HISTORY               ,_param->_nb_inst_update );
108  INSTANCE1_SC_SIGNAL(_Direction_Glue, in_UPDATE_DIRECTION             ,_param->_nb_inst_update );
109  if (_param->_have_component_meta_predictor)
110    {
111  INSTANCE1_SC_SIGNAL(_Direction_Glue,out_UPDATE_PREDICTOR_VAL         ,_param->_nb_inst_update );
112  INSTANCE1_SC_SIGNAL(_Direction_Glue, in_UPDATE_PREDICTOR_ACK         ,_param->_nb_inst_update );
113  INSTANCE1_SC_SIGNAL(_Direction_Glue,out_UPDATE_PREDICTOR_ADDRESS     ,_param->_nb_inst_update );
114  if (_param->_have_port_history)
115  INSTANCE1_SC_SIGNAL(_Direction_Glue,out_UPDATE_PREDICTOR_HISTORY     ,_param->_nb_inst_update );
116  INSTANCE1_SC_SIGNAL(_Direction_Glue,out_UPDATE_PREDICTOR_DIRECTION   ,_param->_nb_inst_update );
117    }
118
119  msg(_("<%s> : Start Simulation ............\n"),name.c_str());
120   
121  Time * _time = new Time();
122
123  /********************************************************
124   * Simulation - Begin
125   ********************************************************/
126
127  // Initialisation
128
129  const uint32_t seed = 0;
130//const uint32_t seed = static_cast<uint32_t>(time(NULL));
131
132  srand(seed);
133
134  SC_START(0);
135  LABEL("Initialisation");
136
137  LABEL("Reset");
138  in_NRESET->write(0);
139  SC_START(5);
140  in_NRESET->write(1); 
141
142  LABEL("Loop of Test");
143
144  for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++)
145    {
146      LABEL("Iteration %d",iteration);
147
148      for (uint32_t i=0; i<_param->_nb_inst_predict; i++)
149        {
150          in_PREDICT_VAL                 [i]->write(rand()%2);
151          in_PREDICT_ADDRESS_SRC         [i]->write(range<Taddress_t>(rand(),_param->_size_instruction_address));
152          in_PREDICT_STATIC              [i]->write(rand()%2);
153          in_PREDICT_LAST_TAKE           [i]->write(rand()%2);
154          in_PREDICT_PREDICTOR_ACK       [i]->write(rand()%2);
155          in_PREDICT_PREDICTOR_HISTORY   [i]->write(range<Thistory_t>(rand(),_param->_size_history));
156          in_PREDICT_PREDICTOR_DIRECTION [i]->write(rand()%2);
157        }
158
159      for (uint32_t i=0; i<_param->_nb_inst_update; i++)
160        {
161          in_UPDATE_VAL                  [i]->write(rand()%2);
162          in_UPDATE_ADDRESS              [i]->write(range<Taddress_t>(rand(),_param->_size_instruction_address));
163          in_UPDATE_HISTORY              [i]->write(range<Thistory_t>(rand(),_param->_size_history));
164          in_UPDATE_DIRECTION            [i]->write(rand()%2);
165          in_UPDATE_PREDICTOR_ACK        [i]->write(rand()%2);
166        }
167
168      SC_START(0);
169
170      for (uint32_t i=0; i<_param->_nb_inst_predict; i++)
171        {
172          switch (_param->_predictor_scheme)
173            {
174            case PREDICTOR_NEVER_TAKE  :
175              {
176                TEST(Tcontrol_t,out_PREDICT_ACK                   [i]->read(), 1);
177                TEST(Tcontrol_t,out_PREDICT_DIRECTION             [i]->read(), 0);
178                break;
179              }
180            case PREDICTOR_ALWAYS_TAKE :
181              {
182                TEST(Tcontrol_t,out_PREDICT_ACK                   [i]->read(), 1);
183                TEST(Tcontrol_t,out_PREDICT_DIRECTION             [i]->read(), 1);
184                break;
185              }
186            case PREDICTOR_STATIC      :
187              {
188                TEST(Tcontrol_t,out_PREDICT_ACK                   [i]->read(), 1);
189                TEST(Tcontrol_t,out_PREDICT_DIRECTION             [i]->read(), in_PREDICT_STATIC               [i]->read());
190                break;
191              }
192            case PREDICTOR_LAST_TAKE   :
193              {
194                TEST(Tcontrol_t,out_PREDICT_DIRECTION             [i]->read(), in_PREDICT_LAST_TAKE            [i]->read());
195                break;
196              }
197            case PREDICTOR_COUNTER     :
198            case PREDICTOR_LOCAL       :
199            case PREDICTOR_GLOBAL      :
200            case PREDICTOR_META        :
201            case PREDICTOR_CUSTOM      :
202              {
203                TEST(Tcontrol_t,out_PREDICT_ACK                   [i]->read(), in_PREDICT_PREDICTOR_ACK        [i]->read());
204                TEST(Thistory_t,out_PREDICT_HISTORY               [i]->read(), in_PREDICT_PREDICTOR_HISTORY    [i]->read());
205                TEST(Tcontrol_t,out_PREDICT_DIRECTION             [i]->read(), in_PREDICT_PREDICTOR_DIRECTION  [i]->read());
206                TEST(Tcontrol_t,out_PREDICT_PREDICTOR_VAL         [i]->read(), in_PREDICT_VAL                  [i]->read());
207                TEST(Taddress_t,out_PREDICT_PREDICTOR_ADDRESS_SRC [i]->read(), in_PREDICT_ADDRESS_SRC          [i]->read());
208               
209                break;
210              }
211            default :
212              {
213                break;
214              }
215            }
216        }
217
218      for (uint32_t i=0; i<_param->_nb_inst_update; i++)
219        {
220
221
222          switch (_param->_predictor_scheme)
223            {
224            case PREDICTOR_COUNTER     :
225            case PREDICTOR_LOCAL       :
226            case PREDICTOR_GLOBAL      :
227            case PREDICTOR_META        :
228            case PREDICTOR_CUSTOM      :
229              {
230                TEST(Tcontrol_t,out_UPDATE_ACK                 [i]->read(), in_UPDATE_PREDICTOR_ACK [i]->read());
231                TEST(Tcontrol_t,out_UPDATE_PREDICTOR_VAL       [i]->read(), in_UPDATE_VAL           [i]->read());
232                TEST(Taddress_t,out_UPDATE_PREDICTOR_ADDRESS   [i]->read(), in_UPDATE_ADDRESS       [i]->read());
233                TEST(Thistory_t,out_UPDATE_PREDICTOR_HISTORY   [i]->read(), in_UPDATE_HISTORY       [i]->read());
234                TEST(Tcontrol_t,out_UPDATE_PREDICTOR_DIRECTION [i]->read(), in_UPDATE_DIRECTION     [i]->read());
235               
236                break;
237              }
238            case PREDICTOR_NEVER_TAKE  :
239            case PREDICTOR_ALWAYS_TAKE :
240            case PREDICTOR_STATIC      :
241            case PREDICTOR_LAST_TAKE   :
242            default :
243              {
244                TEST(Tcontrol_t,out_UPDATE_ACK                 [i]->read(), 1);
245
246                break;
247              }
248            }
249        }
250
251      SC_START(1);
252    }
253
254  /********************************************************
255   * Simulation - End
256   ********************************************************/
257
258  TEST_OK ("End of Simulation");
259  delete _time;
260
261  msg(_("<%s> : ............ Stop Simulation\n"),name.c_str());
262
263  delete in_CLOCK;
264  delete in_NRESET;
265
266  delete []  in_PREDICT_VAL                  ;
267  delete [] out_PREDICT_ACK                  ;
268  delete []  in_PREDICT_ADDRESS_SRC          ;
269  delete []  in_PREDICT_STATIC               ;
270  delete []  in_PREDICT_LAST_TAKE            ;
271  delete [] out_PREDICT_HISTORY              ;
272  delete [] out_PREDICT_DIRECTION            ;
273  delete [] out_PREDICT_PREDICTOR_VAL        ;
274  delete []  in_PREDICT_PREDICTOR_ACK        ;
275  delete [] out_PREDICT_PREDICTOR_ADDRESS_SRC;
276  delete []  in_PREDICT_PREDICTOR_HISTORY    ;
277  delete []  in_PREDICT_PREDICTOR_DIRECTION  ;
278  delete []  in_UPDATE_VAL                   ;
279  delete [] out_UPDATE_ACK                   ;
280  delete []  in_UPDATE_ADDRESS               ;
281  delete []  in_UPDATE_HISTORY               ;
282  delete []  in_UPDATE_DIRECTION             ;
283  delete [] out_UPDATE_PREDICTOR_VAL         ;
284  delete []  in_UPDATE_PREDICTOR_ACK         ;
285  delete [] out_UPDATE_PREDICTOR_ADDRESS     ;
286  delete [] out_UPDATE_PREDICTOR_HISTORY     ;
287  delete [] out_UPDATE_PREDICTOR_DIRECTION   ;
288#endif
289
290  delete _Direction_Glue;
291#ifdef STATISTICS
292  delete _parameters_statistics;
293#endif
294}
Note: See TracBrowser for help on using the repository browser.