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

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

Add :

  • Execute_loop (must be test systemC)
  • Prediction
    • Direction : predifined scheme
    • Branch Target Buffer
  • iFetch_unit
    • ifetch_queue
    • pc management
  • Decod_unit
    • coming soon : support for custom operation
  • Rename_unit
    • RAT
    • Free_list
    • Dependence RAW check
    • Load store unit pointer
  • New Environnement (hierarchy_memory will remove in a next version)


Modif :

  • Manage Custom Operation
  • All component in execute_loop to use the new statistics management

Not Finish :

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