source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Ifetch_unit/Ifetch_queue/SelfTest/src/test.cpp @ 84

Last change on this file since 84 was 82, checked in by rosiere, 16 years ago
  • support locale (now must "just" translate)
  • update all component with new test format
  • update all component with usage
  • New component : decod queue and prediction_unit
  • Property svn:keywords set to Id
File size: 15.7 KB
Line 
1/*
2 * $Id: test.cpp 82 2008-05-01 16:48:45Z rosiere $
3 *
4 * [ Description ]
5 *
6 * Test
7 */
8
9#define NB_ITERATION  1
10#define CYCLE_MAX     (2048*NB_ITERATION)
11
12#include "Behavioural/Core/Multi_Front_end/Front_end/Ifetch_unit/Ifetch_queue/SelfTest/include/test.h"
13#include "Common/include/Test.h"
14#include "Behavioural/include/Allocation.h"
15#include <list>
16#include <set>
17
18class entry_t
19{
20public : uint32_t           _cycle;
21public : Tpacket_t          _packet;
22public : Tgeneral_address_t _addr;
23
24public : entry_t (uint32_t           cycle,
25                  Tpacket_t          packet,
26                  Tgeneral_address_t addr  )
27  {
28    _cycle  = cycle ;
29    _packet = packet;
30    _addr   = addr  ;
31  }
32};
33
34void test (string name,
35           morpheo::behavioural::core::multi_front_end::front_end::ifetch_unit::ifetch_queue::Parameters * _param)
36{
37  msg(_("<%s> : Simulation SystemC.\n"),name.c_str());
38
39#ifdef STATISTICS
40  morpheo::behavioural::Parameters_Statistics * _parameters_statistics = new morpheo::behavioural::Parameters_Statistics (5,1000);
41#endif
42
43  Ifetch_queue * _Ifetch_queue = new Ifetch_queue
44    (name.c_str(),
45#ifdef STATISTICS
46     _parameters_statistics,
47#endif
48     _param,
49     USE_ALL);
50 
51#ifdef SYSTEMC
52  /*********************************************************************
53   * Déclarations des signaux
54   *********************************************************************/
55  string rename;
56
57  sc_clock              *  in_CLOCK  = new sc_clock ("clock", 1.0, 0.5);         
58  sc_signal<Tcontrol_t> *  in_NRESET = new sc_signal<Tcontrol_t> ("NRESET");
59
60  ALLOC_SC_SIGNAL ( in_ADDRESS_VAL                        ," in_ADDRESS_VAL                        ",Tcontrol_t           );
61  ALLOC_SC_SIGNAL (out_ADDRESS_ACK                        ,"out_ADDRESS_ACK                        ",Tcontrol_t           );
62  ALLOC_SC_SIGNAL (out_ADDRESS_IFETCH_QUEUE_ID            ,"out_ADDRESS_IFETCH_QUEUE_ID            ",Tifetch_queue_ptr_t  );
63  ALLOC1_SC_SIGNAL( in_ADDRESS_INSTRUCTION_ENABLE         ," in_ADDRESS_INSTRUCTION_ENABLE         ",Tcontrol_t           ,_param->_nb_instruction);
64  ALLOC_SC_SIGNAL ( in_ADDRESS_INSTRUCTION_ADDRESS        ," in_ADDRESS_INSTRUCTION_ADDRESS        ",Tgeneral_address_t   );
65  ALLOC_SC_SIGNAL ( in_ADDRESS_INST_IFETCH_PTR            ," in_ADDRESS_INST_IFETCH_PTR            ",Tinst_ifetch_ptr_t   );
66  ALLOC_SC_SIGNAL ( in_ADDRESS_BRANCH_STATE               ," in_ADDRESS_BRANCH_STATE               ",Tbranch_state_t      );
67  ALLOC_SC_SIGNAL ( in_ADDRESS_BRANCH_UPDATE_PREDICTION_ID," in_ADDRESS_BRANCH_UPDATE_PREDICTION_ID",Tprediction_ptr_t    );
68  ALLOC1_SC_SIGNAL(out_DECOD_VAL                          ,"out_DECOD_VAL                          ",Tcontrol_t           ,_param->_nb_instruction);
69  ALLOC1_SC_SIGNAL( in_DECOD_ACK                          ," in_DECOD_ACK                          ",Tcontrol_t           ,_param->_nb_instruction);
70  ALLOC1_SC_SIGNAL(out_DECOD_INSTRUCTION                  ,"out_DECOD_INSTRUCTION                  ",Tinstruction_t       ,_param->_nb_instruction);
71  ALLOC_SC_SIGNAL (out_DECOD_ADDRESS                      ,"out_DECOD_ADDRESS                      ",Tgeneral_address_t   );
72  ALLOC_SC_SIGNAL (out_DECOD_INST_IFETCH_PTR              ,"out_DECOD_INST_IFETCH_PTR              ",Tinst_ifetch_ptr_t   );
73  ALLOC_SC_SIGNAL (out_DECOD_BRANCH_STATE                 ,"out_DECOD_BRANCH_STATE                 ",Tbranch_state_t      );
74  ALLOC_SC_SIGNAL (out_DECOD_BRANCH_UPDATE_PREDICTION_ID  ,"out_DECOD_BRANCH_UPDATE_PREDICTION_ID  ",Tprediction_ptr_t    );
75  ALLOC_SC_SIGNAL (out_DECOD_EXCEPTION                    ,"out_DECOD_EXCEPTION                    ",Tprediction_ptr_t    );
76  ALLOC_SC_SIGNAL ( in_ICACHE_RSP_VAL                     ," in_ICACHE_RSP_VAL                     ",Tcontrol_t           );
77  ALLOC_SC_SIGNAL (out_ICACHE_RSP_ACK                     ,"out_ICACHE_RSP_ACK                     ",Tcontrol_t           );
78  ALLOC_SC_SIGNAL ( in_ICACHE_RSP_PACKET_ID               ," in_ICACHE_RSP_PACKET_ID               ",Tpacket_t            );
79  ALLOC1_SC_SIGNAL( in_ICACHE_RSP_INSTRUCTION             ," in_ICACHE_RSP_INSTRUCTION             ",Ticache_instruction_t,_param->_nb_instruction);
80  ALLOC_SC_SIGNAL ( in_ICACHE_RSP_ERROR                   ," in_ICACHE_RSP_ERROR                   ",Ticache_error_t      );
81  ALLOC_SC_SIGNAL ( in_EVENT_RESET_VAL                    ," in_EVENT_RESET_VAL                    ",Tcontrol_t           );
82  ALLOC_SC_SIGNAL (out_EVENT_RESET_ACK                    ,"out_EVENT_RESET_ACK                    ",Tcontrol_t           );
83 
84  /********************************************************
85   * Instanciation
86   ********************************************************/
87 
88  msg(_("<%s> : Instanciation of _Ifetch_queue.\n"),name.c_str());
89
90  (*(_Ifetch_queue->in_CLOCK))        (*(in_CLOCK));
91  (*(_Ifetch_queue->in_NRESET))       (*(in_NRESET));
92
93  INSTANCE_SC_SIGNAL (_Ifetch_queue, in_ADDRESS_VAL                        );
94  INSTANCE_SC_SIGNAL (_Ifetch_queue,out_ADDRESS_ACK                        );
95  if (_param->_have_port_queue_ptr)
96  INSTANCE_SC_SIGNAL (_Ifetch_queue,out_ADDRESS_IFETCH_QUEUE_ID            );
97  INSTANCE1_SC_SIGNAL(_Ifetch_queue, in_ADDRESS_INSTRUCTION_ENABLE         ,_param->_nb_instruction);
98  INSTANCE_SC_SIGNAL (_Ifetch_queue, in_ADDRESS_INSTRUCTION_ADDRESS        );
99  if (_param->_have_port_instruction_ptr)
100  INSTANCE_SC_SIGNAL (_Ifetch_queue, in_ADDRESS_INST_IFETCH_PTR            );
101  INSTANCE_SC_SIGNAL (_Ifetch_queue, in_ADDRESS_BRANCH_STATE               );
102  if (_param->_have_port_branch_update_prediction_id)
103  INSTANCE_SC_SIGNAL (_Ifetch_queue, in_ADDRESS_BRANCH_UPDATE_PREDICTION_ID);
104  INSTANCE1_SC_SIGNAL(_Ifetch_queue,out_DECOD_VAL                          ,_param->_nb_instruction);
105  INSTANCE1_SC_SIGNAL(_Ifetch_queue, in_DECOD_ACK                          ,_param->_nb_instruction);
106  INSTANCE1_SC_SIGNAL(_Ifetch_queue,out_DECOD_INSTRUCTION                  ,_param->_nb_instruction);
107  INSTANCE_SC_SIGNAL (_Ifetch_queue,out_DECOD_ADDRESS                      );
108  if (_param->_have_port_instruction_ptr)
109  INSTANCE_SC_SIGNAL (_Ifetch_queue,out_DECOD_INST_IFETCH_PTR              );
110  INSTANCE_SC_SIGNAL (_Ifetch_queue,out_DECOD_BRANCH_STATE                 );
111  if (_param->_have_port_branch_update_prediction_id)
112  INSTANCE_SC_SIGNAL (_Ifetch_queue,out_DECOD_BRANCH_UPDATE_PREDICTION_ID  );
113  INSTANCE_SC_SIGNAL (_Ifetch_queue,out_DECOD_EXCEPTION                    );
114  INSTANCE_SC_SIGNAL (_Ifetch_queue, in_ICACHE_RSP_VAL                     );
115  INSTANCE_SC_SIGNAL (_Ifetch_queue,out_ICACHE_RSP_ACK                     );
116  if (_param->_have_port_queue_ptr)
117  INSTANCE_SC_SIGNAL (_Ifetch_queue, in_ICACHE_RSP_PACKET_ID               );
118  INSTANCE1_SC_SIGNAL(_Ifetch_queue, in_ICACHE_RSP_INSTRUCTION             ,_param->_nb_instruction);
119  INSTANCE_SC_SIGNAL (_Ifetch_queue, in_ICACHE_RSP_ERROR                   );
120  INSTANCE_SC_SIGNAL (_Ifetch_queue, in_EVENT_RESET_VAL                    );
121  INSTANCE_SC_SIGNAL (_Ifetch_queue,out_EVENT_RESET_ACK                    );
122
123  msg(_("<%s> : Start Simulation ............\n"),name.c_str());
124   
125  Time * _time = new Time();
126
127  /********************************************************
128   * Simulation - Begin
129   ********************************************************/
130
131  // Initialisation
132
133  const uint32_t seed = 0;
134//const uint32_t seed = static_cast<uint32_t>(time(NULL));
135
136  srand(seed);
137
138  const  int32_t percent_transaction_address     = 75;
139  const  int32_t percent_transaction_decod       = 75;
140  const  int32_t percent_transaction_event_reset = 10;
141  const  int32_t percent_icache_hit              = 100;
142  const  int32_t icache_miss_penality            = 10;
143
144  SC_START(0);
145  LABEL("Initialisation");
146
147  LABEL("Reset");
148  in_NRESET->write(0);
149  SC_START(5);
150  in_NRESET->write(1); 
151
152  LABEL("Loop of Test");
153
154  list<Tgeneral_data_t> list_wait_decod;
155  list<entry_t>         list_req_icache;
156 
157  Tgeneral_data_t modulo_iberr = 23;
158  Tinstruction_t  xor_inst     = 0xdeadbeef;
159  Tgeneral_data_t address;
160  for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++)
161    {
162      LABEL("Iteration %d",iteration);
163
164      int32_t nb_request_in  = 64;
165      int32_t nb_request_out = 64;
166
167      address      = 0x100;
168
169      list_wait_decod.clear();
170
171      while ((nb_request_in  > 0) and
172             (nb_request_out > 0))
173        {
174          // =====
175          // ===== ADDRESS
176          // =====
177          in_ADDRESS_VAL                         ->write((nb_request_in  > 0) and ((rand()%100)<percent_transaction_address));
178          in_ADDRESS_INSTRUCTION_ADDRESS         ->write(address);
179          uint32_t nb_inst_enable = (rand() % _param->_nb_instruction);
180          for (uint32_t i=0; i<_param->_nb_instruction; i++)
181          in_ADDRESS_INSTRUCTION_ENABLE [i]      ->write(i<=nb_inst_enable);
182          if (_param->_have_port_instruction_ptr)
183          in_ADDRESS_INST_IFETCH_PTR             ->write(address%_param->_nb_instruction);
184          in_ADDRESS_BRANCH_STATE                ->write(address%SIZE_BRANCH_STATE);
185          if (_param->_have_port_branch_update_prediction_id)
186          in_ADDRESS_BRANCH_UPDATE_PREDICTION_ID ->write(address%_param->_size_branch_update_prediction);
187
188          // =====
189          // ===== DECOD
190          // =====
191          for (uint32_t i=0; i<_param->_nb_instruction; i++)
192            in_DECOD_ACK [i]->write(0);
193          for (uint32_t i=0; i<_param->_nb_instruction; i++)
194            {
195              if ((rand()%100)>percent_transaction_decod)
196                break;
197              in_DECOD_ACK [i]->write(1);
198            }
199
200          // =====
201          // ===== ICACHE_RSP
202          // =====
203          Tcontrol_t icache_rsp_val = not list_req_icache.empty() and (list_req_icache.front()._cycle == 0);
204
205//        LABEL("Test ICACHE_RSP :");
206//        LABEL(" * list_req_icache.empty()        : %d",list_req_icache.empty());
207//        if (not list_req_icache.empty())
208//        LABEL(" * list_req_icache.front()._cycle : %d",list_req_icache.front()._cycle);
209
210          in_ICACHE_RSP_VAL->write(icache_rsp_val);
211
212          if (icache_rsp_val)
213            {
214              for (uint32_t i=0; i<_param->_nb_instruction; i++)
215                in_ICACHE_RSP_INSTRUCTION [i]->write((list_req_icache.front()._addr + 4*i)^xor_inst);
216              in_ICACHE_RSP_PACKET_ID ->write(list_req_icache.front()._packet);
217              in_ICACHE_RSP_ERROR     ->write(((list_req_icache.front()._addr % modulo_iberr)==0)?ICACHE_ERROR_BUS_ERROR:ICACHE_ERROR_NONE);
218            }
219
220          // =====
221          // ===== EVENT_RESET
222          // =====
223          in_EVENT_RESET_VAL->write((rand()%100)<percent_transaction_event_reset);
224
225          // ----------------------------------------------
226          // ----------------------------------------------
227          // ----------------------------------------------
228          SC_START(0);
229          // ----------------------------------------------
230          // ----------------------------------------------
231          // ----------------------------------------------
232
233          // =====
234          // ===== ADDRESS
235          // =====
236          if ( in_ADDRESS_VAL->read() and
237              out_ADDRESS_ACK->read())
238            {
239              LABEL("ADDRESS             : transaction accepted");
240              LABEL("  * address         : %.8x",address);
241             
242              list_wait_decod.push_back(address);
243//            list_req_icache.insert(, entry_t((_param->_have_port_queue_ptr)?out_ADDRESS_IFETCH_QUEUE_ID->read():0,address));
244
245              uint32_t cycle = ((rand()%100)<percent_icache_hit)?1:icache_miss_penality;
246              LABEL("  * cycle           : %d",cycle);
247
248              list<entry_t>::iterator it;
249              for (it=list_req_icache.begin(); it != list_req_icache.end(); it++)
250                if (cycle < it->_cycle)
251                  break;
252
253              LABEL("  * list_req_icache : %d",list_req_icache.size());
254              list_req_icache.insert(it,entry_t(cycle,(_param->_have_port_queue_ptr)?out_ADDRESS_IFETCH_QUEUE_ID->read():0,address));
255              LABEL("  * list_req_icache : %d",list_req_icache.size());       
256              address += 4*_param->_nb_instruction;
257            }
258
259          // =====
260          // ===== DECOD
261          // =====
262          bool have_decod_transaction = false;
263          uint32_t nb_decod_keep = 0;
264          for (uint32_t i=0; i<_param->_nb_instruction; i++)
265            {
266              if (out_DECOD_VAL [i]->read())
267                {
268                  LABEL("DECOD_VAL [%d]       ",i);
269                  nb_decod_keep ++;
270                 
271                  if (in_DECOD_ACK [i]->read())
272                    {
273                      LABEL("DECOD_ACK [%d]       ",i);
274
275                      have_decod_transaction = true;
276                      nb_decod_keep --;
277
278                      TEST(bool           , list_wait_decod.empty()  , false);
279                      TEST(Tinstruction_t , out_DECOD_INSTRUCTION[i]->read(), (list_wait_decod.front()+4*i)^xor_inst);
280                    }
281                }
282            }
283
284          if (have_decod_transaction)
285            {
286
287              Tgeneral_data_t addr = list_wait_decod.front();
288
289              LABEL("DECOD               : transaction accepted");
290              LABEL("  * address         : %.8x",addr);
291             
292              TEST(Tgeneral_data_t   ,out_DECOD_ADDRESS                    ->read(), addr);
293              TEST(Tbranch_state_t   ,out_DECOD_BRANCH_STATE               ->read(),addr%SIZE_BRANCH_STATE);
294              if (_param->_have_port_instruction_ptr)
295              TEST(Tinst_ifetch_ptr_t,out_DECOD_INST_IFETCH_PTR            ->read(),addr%_param->_nb_instruction);
296              if (_param->_have_port_branch_update_prediction_id)
297              TEST(Tprediction_ptr_t ,out_DECOD_BRANCH_UPDATE_PREDICTION_ID->read(),addr%_param->_size_branch_update_prediction);
298              if ((addr % modulo_iberr) == 0)
299              TEST(Texception_t      ,out_DECOD_EXCEPTION                  ->read(),EXCEPTION_IFETCH_BUS_ERROR);
300              else
301              TEST(Texception_t      ,out_DECOD_EXCEPTION                  ->read(),EXCEPTION_IFETCH_NONE     );
302
303              // all is decod
304              LABEL("  * nb_decod_keep   : %d",nb_decod_keep);
305              if (nb_decod_keep == 0)
306                {
307                  LABEL("  * decod all bundle");
308                  list_wait_decod.pop_front();
309                  nb_request_out --;
310                }
311            }
312
313          // =====
314          // ===== ICACHE_RSP
315          // =====
316          if (  in_ICACHE_RSP_VAL->read() and
317               out_ICACHE_RSP_ACK->read())
318            {
319              LABEL("ICACHE_RSP          : transaction accepted");
320              LABEL("  * address         : %.8x",list_req_icache.front()._addr);
321              LABEL("  * list_req_icache : %d",list_req_icache.size());
322              list_req_icache.pop_front();
323              LABEL("  * list_req_icache : %d",list_req_icache.size());
324
325            }
326
327          // =====
328          // ===== EVENT_RESET
329          // =====
330          if ( in_EVENT_RESET_VAL->read() and
331              out_EVENT_RESET_ACK->read() )
332            {
333              LABEL("EVENT_RESET         : transaction accepted");
334              list_wait_decod.clear();
335            }
336
337          SC_START(1);
338
339          for (list<entry_t>::iterator it=list_req_icache.begin(); it != list_req_icache.end(); it++)
340            {
341              LABEL("ICACHE : %d %d %.8x",it->_cycle, it->_packet, it->_addr);
342              if (it->_cycle > 0)
343                it->_cycle --;
344            }
345        }
346    }
347
348  /********************************************************
349   * Simulation - End
350   ********************************************************/
351
352  TEST_OK ("End of Simulation");
353  delete _time;
354
355  msg(_("<%s> : ............ Stop Simulation\n"),name.c_str());
356
357  delete in_CLOCK;
358  delete in_NRESET;
359  delete     in_ADDRESS_VAL                        ;
360  delete    out_ADDRESS_ACK                        ;
361  delete    out_ADDRESS_IFETCH_QUEUE_ID            ;
362  delete []  in_ADDRESS_INSTRUCTION_ENABLE         ;
363  delete     in_ADDRESS_INSTRUCTION_ADDRESS        ;
364  delete     in_ADDRESS_INST_IFETCH_PTR            ;
365  delete     in_ADDRESS_BRANCH_STATE               ;
366  delete     in_ADDRESS_BRANCH_UPDATE_PREDICTION_ID;
367  delete [] out_DECOD_VAL                          ;
368  delete []  in_DECOD_ACK                          ;
369  delete [] out_DECOD_INSTRUCTION                  ;
370  delete    out_DECOD_ADDRESS                      ;
371  delete    out_DECOD_INST_IFETCH_PTR              ;
372  delete    out_DECOD_BRANCH_STATE                 ;
373  delete    out_DECOD_BRANCH_UPDATE_PREDICTION_ID  ;
374  delete    out_DECOD_EXCEPTION                    ;
375  delete     in_ICACHE_RSP_VAL                     ;
376  delete    out_ICACHE_RSP_ACK                     ;
377  delete     in_ICACHE_RSP_PACKET_ID               ;
378  delete []  in_ICACHE_RSP_INSTRUCTION             ;
379  delete     in_ICACHE_RSP_ERROR                   ;
380  delete     in_EVENT_RESET_VAL                    ;
381  delete    out_EVENT_RESET_ACK                    ;
382
383#endif
384
385  delete _Ifetch_queue;
386#ifdef STATISTICS
387  delete _parameters_statistics;
388#endif
389}
Note: See TracBrowser for help on using the repository browser.