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

Last change on this file since 15 was 15, checked in by rosiere, 17 years ago

Interface normalisé
Début du banc de registres multi niveaux

File size: 7.2 KB
Line 
1/*
2 * $Id$
3 *
4 * [ Description ]
5 *
6 * Test
7 */
8
9#define NB_ITERATION 1024
10
11#include "Behavioural/Stage_1_Ifetch/Predictor/Meta_Predictor/Two_Level_Branch_Predictor/Pattern_History_Table/SelfTest/include/test.h"
12#include "Include/Test.h"
13
14void test (string name,
15           morpheo::behavioural::stage_1_ifetch::predictor::meta_predictor::two_level_branch_predictor::pattern_history_table::Parameters param)
16{
17  cout << "<" << name << "> : Simulation SystemC" << endl;
18
19  try 
20    {
21      cout << param.print(1);
22      param.test();
23    }
24  catch (morpheo::ErrorMorpheo & error)
25    {
26      cout << "<" << name << "> : " <<  error.what ();
27      return;
28    }
29  catch (...)
30    {
31      cerr << "<" << name << "> : This test must generate a error" << endl;
32      exit (EXIT_FAILURE);
33    }
34  Pattern_History_Table * _Pattern_History_Table = new Pattern_History_Table (name.c_str(),
35#ifdef STATISTICS
36                                             morpheo::behavioural::Parameters_Statistics(5,50),
37#endif
38                                             param);
39 
40#ifdef SYSTEMC
41  /*********************************************************************
42   * Déclarations des signaux
43   *********************************************************************/
44  sc_clock                                 CLOCK ("clock", 1.0, 0.5);
45  sc_signal<Tcontrol_t>                    NRESET;
46
47  sc_signal<Tcontrol_t>                    PREDICT_VAL               [param._nb_prediction];
48  sc_signal<Tcontrol_t>                    PREDICT_ACK               [param._nb_prediction];
49  sc_signal<Taddress_t>                    PREDICT_ADDRESS           [param._nb_prediction];
50  sc_signal<Thistory_t>                    PREDICT_HISTORY           [param._nb_prediction];
51                                                                     
52  sc_signal<Tcontrol_t>                    BRANCH_COMPLETE_VAL       [param._nb_branch_complete];
53  sc_signal<Tcontrol_t>                    BRANCH_COMPLETE_ACK       [param._nb_branch_complete];
54  sc_signal<Taddress_t>                    BRANCH_COMPLETE_ADDRESS   [param._nb_branch_complete];
55  sc_signal<Thistory_t>                    BRANCH_COMPLETE_HISTORY   [param._nb_branch_complete];
56  sc_signal<Tcontrol_t>                    BRANCH_COMPLETE_DIRECTION [param._nb_branch_complete];
57 
58  /********************************************************
59   * Instanciation
60   ********************************************************/
61 
62  cout << "<" << name << "> Instanciation of _Pattern_History_Table" << endl;
63 
64  (*(_Pattern_History_Table->in_CLOCK))        (CLOCK);
65  (*(_Pattern_History_Table->in_NRESET))       (NRESET);
66
67  for (uint32_t i=0; i<param._nb_prediction; i++)
68    {
69      (*(_Pattern_History_Table-> in_PREDICT_VAL     [i]))        (PREDICT_VAL     [i]);
70      (*(_Pattern_History_Table->out_PREDICT_ACK     [i]))        (PREDICT_ACK     [i]);
71      (*(_Pattern_History_Table-> in_PREDICT_ADDRESS [i]))        (PREDICT_ADDRESS [i]);
72      (*(_Pattern_History_Table->out_PREDICT_HISTORY [i]))        (PREDICT_HISTORY [i]);
73    }
74
75  for (uint32_t i=0; i<param._nb_branch_complete; i++)
76    {
77      (*(_Pattern_History_Table-> in_BRANCH_COMPLETE_VAL       [i]))        (BRANCH_COMPLETE_VAL       [i]);
78      (*(_Pattern_History_Table->out_BRANCH_COMPLETE_ACK       [i]))        (BRANCH_COMPLETE_ACK       [i]);
79      (*(_Pattern_History_Table-> in_BRANCH_COMPLETE_ADDRESS   [i]))        (BRANCH_COMPLETE_ADDRESS   [i]);
80      (*(_Pattern_History_Table-> in_BRANCH_COMPLETE_HISTORY   [i]))        (BRANCH_COMPLETE_HISTORY   [i]);
81      (*(_Pattern_History_Table-> in_BRANCH_COMPLETE_DIRECTION [i]))        (BRANCH_COMPLETE_DIRECTION [i]);
82    }
83
84  /********************************************************
85   * Simulation - Begin
86   ********************************************************/
87
88  cout << "<" << name << "> Start Simulation ............" << endl;
89  // Initialisation
90
91  srand(0);
92  //srand(TIME(NULL));
93
94  sc_start(0);
95  _Pattern_History_Table->vhdl_testbench_label("Initialisation");
96  cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Initialisation" << endl;
97 
98  NRESET.write(1);
99
100  for (uint32_t i=0; i<param._nb_prediction; i++)
101    PREDICT_VAL         [i].write(0);
102  for (uint32_t i=0; i<param._nb_branch_complete; i++)
103    BRANCH_COMPLETE_VAL [i].write(0);
104
105  // Initialisation of Register
106  uint32_t   num_port_branch_complete = 0;
107  uint32_t   num_port_predict         = 0;
108  Taddress_t address                  = 0;
109  Thistory_t history_max              = (1<<param._size_counter)-1;
110  Thistory_t history                  = 0;
111  Tcontrol_t direction                = 0;
112
113  while (address<param._nb_counter)
114    {
115      BRANCH_COMPLETE_VAL       [0].write(1);
116      BRANCH_COMPLETE_ADDRESS   [0].write(address);
117      BRANCH_COMPLETE_HISTORY   [0].write(0);
118      BRANCH_COMPLETE_DIRECTION [0].write(0);
119
120      sc_start(1);
121     
122      if (BRANCH_COMPLETE_ACK[0].read()==1)
123        address++;
124    }
125 
126  BRANCH_COMPLETE_VAL     [0].write(0);
127  sc_start(0);
128
129  _Pattern_History_Table->vhdl_testbench_label("Loop of Test");
130  cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Loop of Test" << endl;
131
132  for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++)
133    {
134      _Pattern_History_Table->vhdl_testbench_label("Iteration "+toString(iteration));
135      num_port_branch_complete = rand() % param._nb_branch_complete;
136      num_port_predict         = rand() % param._nb_prediction     ;
137      address                  = rand() % param._nb_counter        ;
138      history                  = rand() % (1<<param._size_counter) ;
139      direction                = rand() % 2;
140
141      cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} ["+toString(num_port_branch_complete)+"]" << endl
142           << hex
143           << " - address     : " << address   << endl
144           << " - history old : " << history   << endl
145           << " - direction   : " << direction << endl;
146
147      BRANCH_COMPLETE_VAL       [num_port_branch_complete].write(1);
148      BRANCH_COMPLETE_ADDRESS   [num_port_branch_complete].write(address);
149      BRANCH_COMPLETE_HISTORY   [num_port_branch_complete].write(history);
150      BRANCH_COMPLETE_DIRECTION [num_port_branch_complete].write(direction);
151
152      // Wait Ack
153      do
154        {
155          sc_start(1);
156        }
157      while (BRANCH_COMPLETE_ACK[num_port_branch_complete].read()!=1);
158
159      BRANCH_COMPLETE_VAL     [num_port_branch_complete].write(0);
160      PREDICT_VAL             [num_port_predict        ].write(1);
161      PREDICT_ADDRESS         [num_port_predict        ].write(address);
162     
163      history                  = (direction==1)?((history<history_max)?history+1:history):((history>0)?history-1:history);
164     
165      // Wait Ack
166      do
167        {
168          sc_start(1);
169        }
170      while (PREDICT_ACK        [num_port_predict        ].read()!=1);
171
172      PREDICT_VAL             [num_port_predict        ].write(0);
173
174      cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} ["+toString(num_port_predict)+"]" << endl
175           << " - history new : " << PREDICT_HISTORY [num_port_predict].read() << endl
176           << dec;
177
178      TEST(Thistory_t,PREDICT_HISTORY [num_port_predict].read(),history);
179    }
180
181  /********************************************************
182   * Simulation - End
183   ********************************************************/
184
185  cout << "<" << name << "> ............ Stop Simulation" << endl;
186
187#endif
188
189  delete _Pattern_History_Table;
190}
Note: See TracBrowser for help on using the repository browser.