source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_OOO_Engine/OOO_Engine/Rename_unit/Load_Store_pointer_unit/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: 16.0 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  256
10#define CYCLE_MAX     (128*NB_ITERATION)
11
12#include "Behavioural/Core/Multi_OOO_Engine/OOO_Engine/Rename_unit/Load_Store_pointer_unit/SelfTest/include/test.h"
13#include "Common/include/Test.h"
14#include "Common/include/Max.h"
15#include "Behavioural/include/Allocation.h"
16#include <list>
17
18class request_t
19{
20public : Tcontext_t   _front_end_id         ;
21public : Tcontext_t   _context_id           ;
22public : Ttype_t      _type                 ;
23public : Toperation_t _operation            ;
24public : Tlsq_ptr_t   _store_queue_ptr_write;
25public : Tlsq_ptr_t   _load_queue_ptr_write ;
26 
27public : request_t (Tcontext_t   front_end_id         ,
28                    Tcontext_t   context_id           ,
29                    Ttype_t      type                 ,
30                    Toperation_t operation            ,
31                    Tlsq_ptr_t   store_queue_ptr_write,
32                    Tlsq_ptr_t   load_queue_ptr_write )
33  {
34    _front_end_id          = front_end_id         ;
35    _context_id            = context_id           ;
36    _type                  = type                 ;
37    _operation             = operation            ;
38    _store_queue_ptr_write = store_queue_ptr_write;
39    _load_queue_ptr_write  = load_queue_ptr_write ;
40  } 
41};
42
43void test (string name,
44           morpheo::behavioural::core::multi_ooo_engine::ooo_engine::rename_unit::load_store_pointer_unit::Parameters * _param)
45{
46  msg(_("<%s> : Simulation SystemC.\n"),name.c_str());
47
48#ifdef STATISTICS
49  morpheo::behavioural::Parameters_Statistics * _parameters_statistics = new morpheo::behavioural::Parameters_Statistics (5,50);
50#endif
51
52  Tusage_t _usage = USE_ALL;
53
54//   _usage = usage_unset(_usage,USE_SYSTEMC              );
55//   _usage = usage_unset(_usage,USE_VHDL                 );
56//   _usage = usage_unset(_usage,USE_VHDL_TESTBENCH       );
57//   _usage = usage_unset(_usage,USE_VHDL_TESTBENCH_ASSERT);
58//   _usage = usage_unset(_usage,USE_POSITION             );
59   _usage = usage_unset(_usage,USE_STATISTICS           );
60//   _usage = usage_unset(_usage,USE_INFORMATION          );
61
62  Load_Store_pointer_unit * _Load_Store_pointer_unit = new Load_Store_pointer_unit
63    (name.c_str(),
64#ifdef STATISTICS
65     _parameters_statistics,
66#endif
67     _param,
68     _usage);
69 
70#ifdef SYSTEMC
71  /*********************************************************************
72   * Déclarations des signaux
73   *********************************************************************/
74  string rename;
75
76  sc_clock              *  in_CLOCK  = new sc_clock ("clock", 1.0, 0.5);         
77  sc_signal<Tcontrol_t> *  in_NRESET = new sc_signal<Tcontrol_t> ("NRESET");
78
79  ALLOC1_SC_SIGNAL( in_INSERT_VAL                  ," in_INSERT_VAL                  ",Tcontrol_t  ,_param->_nb_inst_insert);
80  ALLOC1_SC_SIGNAL(out_INSERT_ACK                  ,"out_INSERT_ACK                  ",Tcontrol_t  ,_param->_nb_inst_insert);
81  ALLOC1_SC_SIGNAL( in_INSERT_FRONT_END_ID         ," in_INSERT_FRONT_END_ID         ",Tcontext_t  ,_param->_nb_inst_insert);
82  ALLOC1_SC_SIGNAL( in_INSERT_CONTEXT_ID           ," in_INSERT_CONTEXT_ID           ",Tcontext_t  ,_param->_nb_inst_insert);
83  ALLOC1_SC_SIGNAL( in_INSERT_TYPE                 ," in_INSERT_TYPE                 ",Ttype_t     ,_param->_nb_inst_insert);
84  ALLOC1_SC_SIGNAL( in_INSERT_OPERATION            ," in_INSERT_OPERATION            ",Toperation_t,_param->_nb_inst_insert);
85  ALLOC1_SC_SIGNAL(out_INSERT_STORE_QUEUE_PTR_WRITE,"out_INSERT_STORE_QUEUE_PTR_WRITE",Tlsq_ptr_t  ,_param->_nb_inst_insert);
86  ALLOC1_SC_SIGNAL(out_INSERT_LOAD_QUEUE_PTR_WRITE ,"out_INSERT_LOAD_QUEUE_PTR_WRITE ",Tlsq_ptr_t  ,_param->_nb_inst_insert);
87  ALLOC1_SC_SIGNAL( in_RETIRE_VAL                  ," in_RETIRE_VAL                  ",Tcontrol_t  ,_param->_nb_inst_retire);
88  ALLOC1_SC_SIGNAL(out_RETIRE_ACK                  ,"out_RETIRE_ACK                  ",Tcontrol_t  ,_param->_nb_inst_retire);
89  ALLOC1_SC_SIGNAL( in_RETIRE_FRONT_END_ID         ," in_RETIRE_FRONT_END_ID         ",Tcontext_t  ,_param->_nb_inst_retire);
90  ALLOC1_SC_SIGNAL( in_RETIRE_CONTEXT_ID           ," in_RETIRE_CONTEXT_ID           ",Tcontext_t  ,_param->_nb_inst_retire);
91//   ALLOC1_SC_SIGNAL( in_RETIRE_TYPE                 ," in_RETIRE_TYPE                 ",Ttype_t     ,_param->_nb_inst_retire);
92//   ALLOC1_SC_SIGNAL( in_RETIRE_OPERATION            ," in_RETIRE_OPERATION            ",Toperation_t,_param->_nb_inst_retire);
93  ALLOC1_SC_SIGNAL( in_RETIRE_USE_STORE_QUEUE      ," in_RETIRE_USE_STORE_QUEUE      ",Tcontrol_t  ,_param->_nb_inst_retire);
94  ALLOC1_SC_SIGNAL( in_RETIRE_USE_LOAD_QUEUE       ," in_RETIRE_USE_LOAD_QUEUE       ",Tcontrol_t  ,_param->_nb_inst_retire);
95  ALLOC1_SC_SIGNAL( in_RETIRE_STORE_QUEUE_PTR_WRITE," in_RETIRE_STORE_QUEUE_PTR_WRITE",Tlsq_ptr_t  ,_param->_nb_inst_retire);
96  ALLOC1_SC_SIGNAL( in_RETIRE_LOAD_QUEUE_PTR_WRITE ," in_RETIRE_LOAD_QUEUE_PTR_WRITE ",Tlsq_ptr_t  ,_param->_nb_inst_retire);
97 
98  /********************************************************
99   * Instanciation
100   ********************************************************/
101 
102  msg(_("<%s> : Instanciation of _Load_Store_pointer_unit.\n"),name.c_str());
103
104  (*(_Load_Store_pointer_unit->in_CLOCK))        (*(in_CLOCK));
105  (*(_Load_Store_pointer_unit->in_NRESET))       (*(in_NRESET));
106
107  INSTANCE1_SC_SIGNAL(_Load_Store_pointer_unit, in_INSERT_VAL                  ,_param->_nb_inst_insert);
108  INSTANCE1_SC_SIGNAL(_Load_Store_pointer_unit,out_INSERT_ACK                  ,_param->_nb_inst_insert);
109  if (_param->_have_port_front_end_id)
110  INSTANCE1_SC_SIGNAL(_Load_Store_pointer_unit, in_INSERT_FRONT_END_ID         ,_param->_nb_inst_insert);
111  if (_param->_have_port_context_id)
112  INSTANCE1_SC_SIGNAL(_Load_Store_pointer_unit, in_INSERT_CONTEXT_ID           ,_param->_nb_inst_insert);
113  INSTANCE1_SC_SIGNAL(_Load_Store_pointer_unit, in_INSERT_TYPE                 ,_param->_nb_inst_insert);
114  INSTANCE1_SC_SIGNAL(_Load_Store_pointer_unit, in_INSERT_OPERATION            ,_param->_nb_inst_insert);
115  INSTANCE1_SC_SIGNAL(_Load_Store_pointer_unit,out_INSERT_STORE_QUEUE_PTR_WRITE,_param->_nb_inst_insert);
116  if (_param->_have_port_load_queue_ptr)
117  INSTANCE1_SC_SIGNAL(_Load_Store_pointer_unit,out_INSERT_LOAD_QUEUE_PTR_WRITE ,_param->_nb_inst_insert);
118
119  INSTANCE1_SC_SIGNAL(_Load_Store_pointer_unit, in_RETIRE_VAL                  ,_param->_nb_inst_retire);
120  INSTANCE1_SC_SIGNAL(_Load_Store_pointer_unit,out_RETIRE_ACK                  ,_param->_nb_inst_retire);
121  if (_param->_have_port_front_end_id)
122  INSTANCE1_SC_SIGNAL(_Load_Store_pointer_unit, in_RETIRE_FRONT_END_ID         ,_param->_nb_inst_retire);
123  if (_param->_have_port_context_id)
124  INSTANCE1_SC_SIGNAL(_Load_Store_pointer_unit, in_RETIRE_CONTEXT_ID           ,_param->_nb_inst_retire);
125//   INSTANCE1_SC_SIGNAL(_Load_Store_pointer_unit, in_RETIRE_TYPE                 ,_param->_nb_inst_retire);
126//   INSTANCE1_SC_SIGNAL(_Load_Store_pointer_unit, in_RETIRE_OPERATION            ,_param->_nb_inst_retire);
127  INSTANCE1_SC_SIGNAL(_Load_Store_pointer_unit, in_RETIRE_USE_STORE_QUEUE      ,_param->_nb_inst_retire);
128  INSTANCE1_SC_SIGNAL(_Load_Store_pointer_unit, in_RETIRE_USE_LOAD_QUEUE       ,_param->_nb_inst_retire);
129  INSTANCE1_SC_SIGNAL(_Load_Store_pointer_unit, in_RETIRE_STORE_QUEUE_PTR_WRITE,_param->_nb_inst_retire);
130  if (_param->_have_port_load_queue_ptr)
131  INSTANCE1_SC_SIGNAL(_Load_Store_pointer_unit, in_RETIRE_LOAD_QUEUE_PTR_WRITE ,_param->_nb_inst_retire);
132
133  msg(_("<%s> : Start Simulation ............\n"),name.c_str());
134   
135  Time * _time = new Time();
136
137  /********************************************************
138   * Simulation - Begin
139   ********************************************************/
140
141  // Initialisation
142
143  const uint32_t seed = 0;
144//const uint32_t seed = static_cast<uint32_t>(time(NULL));
145
146  srand(seed);
147
148  const  int32_t percent_transaction_insert = 75;
149  const  int32_t percent_transaction_retire = 75;
150 
151  Ttype_t      type     [2];
152  type [0] = TYPE_MEMORY;
153  type [1] = TYPE_ALU;
154
155  Toperation_t operation[2];
156  operation [0] = OPERATION_MEMORY_LOAD_8_Z;
157  operation [1] = OPERATION_MEMORY_STORE_32;
158 
159  list<request_t> rob;
160  list<request_t>::iterator it;
161
162  Tlsq_ptr_t _STORE_QUEUE_PTR_WRITE [_param->_nb_load_store_queue];
163  bool       _STORE_QUEUE_USE       [_param->_nb_load_store_queue][max<uint32_t>(_param->_size_store_queue,_param->_nb_load_store_queue)];
164  Tlsq_ptr_t _STORE_QUEUE_NB_USE    [_param->_nb_load_store_queue];
165  Tlsq_ptr_t _LOAD_QUEUE_PTR_WRITE  [_param->_nb_load_store_queue];
166  bool       _LOAD_QUEUE_USE        [_param->_nb_load_store_queue][max<uint32_t>(_param->_size_load_queue,_param->_nb_load_store_queue)];
167
168  for (uint32_t i=0; i<_param->_nb_load_store_queue; i++)
169    {
170      _STORE_QUEUE_PTR_WRITE [i] = 0;
171      _STORE_QUEUE_NB_USE    [i] = 0;
172      _LOAD_QUEUE_PTR_WRITE  [i] = 0;
173
174      for (uint32_t j=0; j<max<uint32_t>(_param->_size_store_queue,_param->_nb_load_store_queue); j++)
175        _STORE_QUEUE_USE       [i][j] = false;
176      for (uint32_t j=0; j<max<uint32_t>(_param->_size_load_queue,_param->_nb_load_store_queue); j++)
177        _LOAD_QUEUE_USE        [i][j] = false;
178    }
179
180  SC_START(0);
181  LABEL("Initialisation");
182
183  LABEL("Reset");
184  in_NRESET->write(0);
185  SC_START(5);
186  in_NRESET->write(1); 
187
188  LABEL("Loop of Test");
189
190  for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++)
191    {
192      LABEL("Iteration %d",iteration);
193
194      for (uint32_t i=0; i<_param->_nb_inst_insert; i++)
195        {
196          in_INSERT_VAL          [i] ->write((rand()%100)<percent_transaction_insert);
197          Tcontext_t front_end_id = rand()%_param->_nb_front_end;
198          in_INSERT_FRONT_END_ID [i] ->write(front_end_id);
199          in_INSERT_CONTEXT_ID   [i] ->write(rand()%_param->_nb_context[front_end_id]);
200          in_INSERT_TYPE         [i] ->write(type     [rand()%2]);
201          in_INSERT_OPERATION    [i] ->write(operation[rand()%2]);
202        }
203     
204      it = rob.begin();
205      for (uint32_t i=0; i<_param->_nb_inst_retire; i++)
206        {
207          in_RETIRE_VAL          [i] ->write(((rand()%100)<percent_transaction_retire) and (i< rob.size()));
208         
209          if (i< rob.size())
210            {
211              in_RETIRE_FRONT_END_ID          [i]->write(it->_front_end_id         );
212              in_RETIRE_CONTEXT_ID            [i]->write(it->_context_id           );
213//            in_RETIRE_TYPE                  [i]->write(it->_type                 );
214//            in_RETIRE_OPERATION             [i]->write(it->_operation            );
215              in_RETIRE_USE_STORE_QUEUE       [i]->write((it->_type == TYPE_MEMORY) and     is_operation_memory_store(it->_operation));
216              in_RETIRE_USE_LOAD_QUEUE        [i]->write((it->_type == TYPE_MEMORY) and not is_operation_memory_store(it->_operation));
217              in_RETIRE_STORE_QUEUE_PTR_WRITE [i]->write(it->_store_queue_ptr_write);
218              in_RETIRE_LOAD_QUEUE_PTR_WRITE  [i]->write(it->_load_queue_ptr_write );
219             
220              it++;
221            }
222        }
223     
224      SC_START(0);
225
226      it = rob.begin();
227      for (uint32_t i=0; i<_param->_nb_inst_retire; i++)
228        {
229          bool pop = false;
230          if (in_RETIRE_VAL[i]->read())
231            {
232              if (not (in_RETIRE_USE_STORE_QUEUE [i]->read() or
233                       in_RETIRE_USE_LOAD_QUEUE  [i]->read()))
234                TEST(Tcontrol_t, out_RETIRE_ACK[i]->read(),true);
235             
236              if (out_RETIRE_ACK[i]->read())
237                {
238                  pop = true;
239
240                  LABEL("RETIRE[%d] Transaction accepted",i);
241                  if (it->_type == TYPE_MEMORY)
242                    {
243                      LABEL(" * Type MEMORY");
244                      if (is_operation_memory_store(it->_operation))
245                        {
246                          LABEL("   * Operation STORE");
247                          uint32_t lsq = _param->_link_load_store_unit_with_thread[it->_front_end_id][it->_context_id];
248                          uint32_t ptr = it->_store_queue_ptr_write;
249                         
250                          LABEL("     * lsq : %d",lsq);
251                          LABEL("     * ptr : %d",ptr);
252
253                          _STORE_QUEUE_NB_USE    [lsq]      --;
254                          _STORE_QUEUE_USE       [lsq][ptr] = false;
255                        }
256                      else
257                        {
258                          LABEL("   * Operation LOAD");
259                          uint32_t lsq = _param->_link_load_store_unit_with_thread[it->_front_end_id][it->_context_id];
260                          uint32_t ptr = it->_load_queue_ptr_write;
261
262                          LABEL("     * lsq : %d",lsq);
263                          LABEL("     * ptr : %d",ptr);
264                         
265                          _LOAD_QUEUE_USE       [lsq][ptr] = false;
266                        }
267                    }
268                  it = rob.erase(it);
269                }
270            }
271
272          if ((pop == false) and (i< rob.size()))
273            it++;
274        }
275
276      for (uint32_t i=0; i<_param->_nb_inst_insert; i++)
277        if (in_INSERT_VAL[i]->read())
278          {
279            if (in_INSERT_TYPE [i]->read() != TYPE_MEMORY)
280              TEST(Tcontrol_t, out_INSERT_ACK[i]->read(),true);
281
282            if (out_INSERT_ACK[i]->read())
283              {
284                rob.push_back(request_t( in_INSERT_FRONT_END_ID          [i]->read(),
285                                         in_INSERT_CONTEXT_ID            [i]->read(),
286                                         in_INSERT_TYPE                  [i]->read(),
287                                         in_INSERT_OPERATION             [i]->read(),
288                                        out_INSERT_STORE_QUEUE_PTR_WRITE [i]->read(),
289                                        out_INSERT_LOAD_QUEUE_PTR_WRITE  [i]->read()));
290
291                LABEL("INSERT[%d] Transaction accepted",i);
292
293                if (in_INSERT_TYPE [i]->read() == TYPE_MEMORY)
294                  {
295                    LABEL(" * Type MEMORY");
296                    if (is_operation_memory_store(in_INSERT_OPERATION [i]->read()))
297                      {
298                        LABEL("   * Operation STORE");
299                        uint32_t lsq = _param->_link_load_store_unit_with_thread[in_INSERT_FRONT_END_ID[i]->read()][in_INSERT_CONTEXT_ID[i]->read()];
300                        uint32_t ptr = _STORE_QUEUE_PTR_WRITE [lsq];
301
302                        LABEL("     * lsq : %d",lsq);
303                        LABEL("     * ptr : %d",ptr);
304                       
305                        TEST(bool      , _STORE_QUEUE_USE       [lsq][ptr], false);
306                        TEST(Tlsq_ptr_t, out_INSERT_STORE_QUEUE_PTR_WRITE [i]->read(),ptr                         );
307                        TEST(Tlsq_ptr_t, out_INSERT_LOAD_QUEUE_PTR_WRITE  [i]->read(),_LOAD_QUEUE_PTR_WRITE  [lsq]);
308                        TEST(bool      ,static_cast<uint32_t>(_STORE_QUEUE_NB_USE [lsq]+1)<_param->_size_store_queue[lsq], true);
309                       
310                        _STORE_QUEUE_PTR_WRITE [lsq]      = (ptr+1)%_param->_size_store_queue[lsq];
311                        _STORE_QUEUE_NB_USE    [lsq]      ++;
312                        _STORE_QUEUE_USE       [lsq][ptr] = true;
313                      }
314                    else
315                      {
316                        LABEL("   * Operation LOAD");
317                        uint32_t lsq = _param->_link_load_store_unit_with_thread[in_INSERT_FRONT_END_ID[i]->read()][in_INSERT_CONTEXT_ID[i]->read()];
318                        uint32_t ptr = _LOAD_QUEUE_PTR_WRITE [lsq];
319                       
320                        LABEL("     * lsq : %d",lsq);
321                        LABEL("     * ptr : %d",ptr);
322
323                        TEST(bool      , _LOAD_QUEUE_USE       [lsq][ptr], false);
324                        TEST(Tlsq_ptr_t, out_INSERT_STORE_QUEUE_PTR_WRITE [i]->read(),_STORE_QUEUE_PTR_WRITE  [lsq]);
325                        TEST(Tlsq_ptr_t, out_INSERT_LOAD_QUEUE_PTR_WRITE  [i]->read(),ptr                         );
326                       
327                        _LOAD_QUEUE_PTR_WRITE [lsq]      = (ptr+1)%_param->_size_load_queue[lsq];
328                        _LOAD_QUEUE_USE       [lsq][ptr] = true;
329                      }
330                  }
331              }
332          }
333
334
335    for (uint32_t i=0; i<_param->_nb_load_store_queue; i++)
336      {
337        std::string str;
338
339        LABEL("LOAD_STORE_QUEUE [%d]",i);
340
341        LABEL(" * STORE_QUEUE_PTR_WRITE : %d",_STORE_QUEUE_PTR_WRITE [i]);
342        LABEL(" * STORE_QUEUE_NB_USE    : %d",_STORE_QUEUE_NB_USE    [i]);
343
344        str = "";
345        for (uint32_t j=0; j<_param->_size_store_queue[i]; j++)
346          str += toString(_STORE_QUEUE_USE [i][j]) + " ";
347        LABEL(" * %s",str.c_str());
348       
349        LABEL(" * LOAD_QUEUE_PTR_WRITE  : %d",_LOAD_QUEUE_PTR_WRITE [i]);
350
351        str = "";
352        for (uint32_t j=0; j<_param->_size_load_queue[i]; j++)
353          str += toString(_LOAD_QUEUE_USE [i][j]) + " ";
354        LABEL(" * %s",str.c_str());
355      }
356
357
358      SC_START(1);
359    }
360
361  /********************************************************
362   * Simulation - End
363   ********************************************************/
364
365  TEST_OK ("End of Simulation");
366  delete _time;
367
368  msg(_("<%s> : ............ Stop Simulation\n"),name.c_str());
369
370  delete in_CLOCK;
371  delete in_NRESET;
372
373  delete []  in_INSERT_VAL                  ;
374  delete [] out_INSERT_ACK                  ;
375  delete []  in_INSERT_FRONT_END_ID         ;
376  delete []  in_INSERT_CONTEXT_ID           ;
377  delete []  in_INSERT_TYPE                 ;
378  delete []  in_INSERT_OPERATION            ;
379  delete [] out_INSERT_STORE_QUEUE_PTR_WRITE;
380  delete [] out_INSERT_LOAD_QUEUE_PTR_WRITE ;
381  delete []  in_RETIRE_VAL                  ;
382  delete [] out_RETIRE_ACK                  ;
383  delete []  in_RETIRE_FRONT_END_ID         ;
384  delete []  in_RETIRE_CONTEXT_ID           ;
385//   delete []  in_RETIRE_TYPE                 ;
386//   delete []  in_RETIRE_OPERATION            ;
387  delete []  in_RETIRE_USE_STORE_QUEUE      ;
388  delete []  in_RETIRE_USE_LOAD_QUEUE       ;
389  delete []  in_RETIRE_STORE_QUEUE_PTR_WRITE;
390  delete []  in_RETIRE_LOAD_QUEUE_PTR_WRITE ;
391 
392#endif
393
394  delete _Load_Store_pointer_unit;
395#ifdef STATISTICS
396  delete _parameters_statistics;
397#endif
398}
Note: See TracBrowser for help on using the repository browser.