source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Stage_1_Ifetch/Predictor/Meta_Predictor/Meta_Predictor_Glue/SelfTest/src/test.cpp @ 5

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

Ajout du composant Meta_Predictor

File size: 26.7 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/Meta_Predictor_Glue/SelfTest/include/test.h"
12#include "Include/Test.h"
13
14void test (string name,
15           morpheo::behavioural::stage_1_ifetch::predictor::meta_predictor::meta_predictor_glue::Parameters _param)
16{
17  cout << "<" << name << "> : Simulation SystemC" << endl;
18
19  Meta_Predictor_Glue * _Meta_Predictor_Glue = new Meta_Predictor_Glue (name.c_str(),
20#ifdef STATISTICS
21                                                                        morpheo::behavioural::Parameters_Statistics(5,50),
22#endif
23                                                                        _param);
24 
25#ifdef SYSTEMC
26  /*********************************************************************
27   * Déclarations des signaux
28   *********************************************************************/
29  sc_clock                         * CLOCK;
30
31    // Interface Predict
32  sc_signal<Tcontrol_t>           ** PREDICT_PREDICTOR_0_ACK                ;
33  sc_signal<Tcontrol_t>           ** PREDICT_PREDICTOR_1_ACK                ;
34  sc_signal<Tcontrol_t>           ** PREDICT_PREDICTOR_2_ACK                ;
35  sc_signal<Tcontrol_t>           ** PREDICT_ACK                            ;
36
37  sc_signal<Tbht_history_t>       ** PREDICT_PREDICTOR_0_BHT_HISTORY        ;
38  sc_signal<Tpht_history_t>       ** PREDICT_PREDICTOR_0_PHT_HISTORY        ;
39  sc_signal<Tbht_history_t>       ** PREDICT_PREDICTOR_1_BHT_HISTORY        ;
40  sc_signal<Tpht_history_t>       ** PREDICT_PREDICTOR_1_PHT_HISTORY        ;
41  sc_signal<Tbht_history_t>       ** PREDICT_PREDICTOR_2_BHT_HISTORY        ;
42  sc_signal<Tpht_history_t>       ** PREDICT_PREDICTOR_2_PHT_HISTORY        ;
43  sc_signal<Thistory_t>           ** PREDICT_HISTORY                        ;
44  sc_signal<Tcontrol_t>           ** PREDICT_DIRECTION                      ;
45
46    // Interface Branch_complete
47  sc_signal<Tcontrol_t>           ** BRANCH_COMPLETE_VAL                    ;
48  sc_signal<Tcontrol_t>           ** BRANCH_COMPLETE_PREDICTOR_2_VAL        ;
49
50  sc_signal<Tcontrol_t>           ** BRANCH_COMPLETE_PREDICTOR_0_ACK        ;
51  sc_signal<Tcontrol_t>           ** BRANCH_COMPLETE_PREDICTOR_1_ACK        ;
52  sc_signal<Tcontrol_t>           ** BRANCH_COMPLETE_PREDICTOR_2_ACK        ;
53  sc_signal<Tcontrol_t>           ** BRANCH_COMPLETE_ACK                    ;
54
55  sc_signal<Tbht_history_t>       ** BRANCH_COMPLETE_PREDICTOR_0_BHT_HISTORY;
56  sc_signal<Tpht_history_t>       ** BRANCH_COMPLETE_PREDICTOR_0_PHT_HISTORY;
57  sc_signal<Tbht_history_t>       ** BRANCH_COMPLETE_PREDICTOR_1_BHT_HISTORY;
58  sc_signal<Tpht_history_t>       ** BRANCH_COMPLETE_PREDICTOR_1_PHT_HISTORY;
59  sc_signal<Tbht_history_t>       ** BRANCH_COMPLETE_PREDICTOR_2_BHT_HISTORY;
60  sc_signal<Tpht_history_t>       ** BRANCH_COMPLETE_PREDICTOR_2_PHT_HISTORY;
61  sc_signal<Thistory_t>           ** BRANCH_COMPLETE_HISTORY                ;
62  sc_signal<Tcontrol_t>           ** BRANCH_COMPLETE_DIRECTION              ;
63  sc_signal<Tcontrol_t>           ** BRANCH_COMPLETE_PREDICTOR_2_DIRECTION  ;
64  string rename;
65
66#if defined(STATISTICS) or defined(VHDL_TESTBENCH)
67  CLOCK                                  = new sc_clock ("clock", 1.0, 0.5);
68#endif 
69
70    // Interface Predict
71
72    PREDICT_PREDICTOR_0_ACK         = new sc_signal<Tcontrol_t>     * [_param._nb_prediction     ];
73    PREDICT_PREDICTOR_1_ACK         = new sc_signal<Tcontrol_t>     * [_param._nb_prediction     ];
74    PREDICT_PREDICTOR_2_ACK         = new sc_signal<Tcontrol_t>     * [_param._nb_prediction     ];
75    PREDICT_ACK                     = new sc_signal<Tcontrol_t>     * [_param._nb_prediction     ];
76    PREDICT_PREDICTOR_0_BHT_HISTORY = new sc_signal<Tbht_history_t> * [_param._nb_prediction     ];
77    PREDICT_PREDICTOR_0_PHT_HISTORY = new sc_signal<Tpht_history_t> * [_param._nb_prediction     ];
78    PREDICT_PREDICTOR_1_BHT_HISTORY = new sc_signal<Tbht_history_t> * [_param._nb_prediction     ];
79    PREDICT_PREDICTOR_1_PHT_HISTORY = new sc_signal<Tpht_history_t> * [_param._nb_prediction     ];
80    PREDICT_PREDICTOR_2_BHT_HISTORY = new sc_signal<Tbht_history_t> * [_param._nb_prediction     ];
81    PREDICT_PREDICTOR_2_PHT_HISTORY = new sc_signal<Tpht_history_t> * [_param._nb_prediction     ];
82    PREDICT_HISTORY                 = new sc_signal<Thistory_t>     * [_param._nb_prediction     ];
83    PREDICT_DIRECTION               = new sc_signal<Tcontrol_t>     * [_param._nb_prediction     ];
84
85    for (uint32_t i=0; i<_param._nb_prediction; i++)
86      {
87        rename = "PREDICT_PREDICTOR_0_ACK_"          +toString(i);
88        PREDICT_PREDICTOR_0_ACK                   [i] = new sc_signal<Tcontrol_t>     (rename.c_str());
89        rename = "PREDICT_PREDICTOR_1_ACK_"          +toString(i);
90        PREDICT_PREDICTOR_1_ACK                   [i] = new sc_signal<Tcontrol_t>     (rename.c_str());
91        rename = "PREDICT_PREDICTOR_2_ACK_"          +toString(i);
92        PREDICT_PREDICTOR_2_ACK                   [i] = new sc_signal<Tcontrol_t>     (rename.c_str());
93        rename = "PREDICT_ACK_"                    +toString(i);
94        PREDICT_ACK                               [i] = new sc_signal<Tcontrol_t>     (rename.c_str());
95        rename = "PREDICT_PREDICTOR_0_BHT_HISTORY_"+toString(i);
96        PREDICT_PREDICTOR_0_BHT_HISTORY           [i] = new sc_signal<Tbht_history_t> (rename.c_str());
97        rename = "PREDICT_PREDICTOR_0_PHT_HISTORY_"+toString(i);
98        PREDICT_PREDICTOR_0_PHT_HISTORY           [i] = new sc_signal<Tpht_history_t> (rename.c_str());
99        rename = "PREDICT_PREDICTOR_1_BHT_HISTORY_"+toString(i);
100        PREDICT_PREDICTOR_1_BHT_HISTORY           [i] = new sc_signal<Tbht_history_t> (rename.c_str());
101        rename = "PREDICT_PREDICTOR_1_PHT_HISTORY_"+toString(i);
102        PREDICT_PREDICTOR_1_PHT_HISTORY           [i] = new sc_signal<Tpht_history_t> (rename.c_str());
103        rename = "PREDICT_PREDICTOR_2_BHT_HISTORY_"+toString(i);
104        PREDICT_PREDICTOR_2_BHT_HISTORY           [i] = new sc_signal<Tbht_history_t> (rename.c_str());
105        rename = "PREDICT_PREDICTOR_2_PHT_HISTORY_"+toString(i);
106        PREDICT_PREDICTOR_2_PHT_HISTORY           [i] = new sc_signal<Tpht_history_t> (rename.c_str());
107        rename = "PREDICT_HISTORY_"                +toString(i);
108        PREDICT_HISTORY                           [i] = new sc_signal<Thistory_t>     (rename.c_str());
109        rename = "PREDICT_DIRECTION_"              +toString(i);
110        PREDICT_DIRECTION                         [i] = new sc_signal<Tcontrol_t>     (rename.c_str());
111      }
112
113    // Interface Branch_complete
114    BRANCH_COMPLETE_VAL                     = new sc_signal<Tcontrol_t>     * [_param._nb_branch_complete     ];
115    BRANCH_COMPLETE_PREDICTOR_2_VAL         = new sc_signal<Tcontrol_t>     * [_param._nb_branch_complete     ];
116    BRANCH_COMPLETE_PREDICTOR_0_ACK         = new sc_signal<Tcontrol_t>     * [_param._nb_branch_complete     ];
117    BRANCH_COMPLETE_PREDICTOR_1_ACK         = new sc_signal<Tcontrol_t>     * [_param._nb_branch_complete     ];
118    BRANCH_COMPLETE_PREDICTOR_2_ACK         = new sc_signal<Tcontrol_t>     * [_param._nb_branch_complete     ];
119    BRANCH_COMPLETE_ACK                     = new sc_signal<Tcontrol_t>     * [_param._nb_branch_complete     ];
120    BRANCH_COMPLETE_PREDICTOR_0_BHT_HISTORY = new sc_signal<Tbht_history_t> * [_param._nb_branch_complete     ];
121    BRANCH_COMPLETE_PREDICTOR_0_PHT_HISTORY = new sc_signal<Tpht_history_t> * [_param._nb_branch_complete     ];
122    BRANCH_COMPLETE_PREDICTOR_1_BHT_HISTORY = new sc_signal<Tbht_history_t> * [_param._nb_branch_complete     ];
123    BRANCH_COMPLETE_PREDICTOR_1_PHT_HISTORY = new sc_signal<Tpht_history_t> * [_param._nb_branch_complete     ];
124    BRANCH_COMPLETE_PREDICTOR_2_BHT_HISTORY = new sc_signal<Tbht_history_t> * [_param._nb_branch_complete     ];
125    BRANCH_COMPLETE_PREDICTOR_2_PHT_HISTORY = new sc_signal<Tpht_history_t> * [_param._nb_branch_complete     ];
126    BRANCH_COMPLETE_HISTORY                 = new sc_signal<Thistory_t>     * [_param._nb_branch_complete     ];
127    BRANCH_COMPLETE_DIRECTION               = new sc_signal<Tcontrol_t>     * [_param._nb_branch_complete     ];
128    BRANCH_COMPLETE_PREDICTOR_2_DIRECTION   = new sc_signal<Tcontrol_t>     * [_param._nb_branch_complete     ];
129
130    for (uint32_t i=0; i<_param._nb_branch_complete; i++)
131      {
132        rename = "BRANCH_COMPLETE_VAL_"                      +toString(i);
133        BRANCH_COMPLETE_VAL                               [i] = new sc_signal<Tcontrol_t>     (rename.c_str());
134        rename = "BRANCH_COMPLETE_PREDICTOR_2_VAL_"          +toString(i);
135        BRANCH_COMPLETE_PREDICTOR_2_VAL                   [i] = new sc_signal<Tcontrol_t>     (rename.c_str());
136        rename = "BRANCH_COMPLETE_PREDICTOR_0_ACK_"          +toString(i);
137        BRANCH_COMPLETE_PREDICTOR_0_ACK                   [i] = new sc_signal<Tcontrol_t>     (rename.c_str());
138        rename = "BRANCH_COMPLETE_PREDICTOR_1_ACK_"          +toString(i);
139        BRANCH_COMPLETE_PREDICTOR_1_ACK                   [i] = new sc_signal<Tcontrol_t>     (rename.c_str());
140        rename = "BRANCH_COMPLETE_PREDICTOR_2_ACK_"          +toString(i);
141        BRANCH_COMPLETE_PREDICTOR_2_ACK                   [i] = new sc_signal<Tcontrol_t>     (rename.c_str());
142        rename = "BRANCH_COMPLETE_ACK_"                    +toString(i);
143        BRANCH_COMPLETE_ACK                               [i] = new sc_signal<Tcontrol_t>     (rename.c_str());
144        rename = "BRANCH_COMPLETE_PREDICTOR_0_BHT_HISTORY_"+toString(i);
145        BRANCH_COMPLETE_PREDICTOR_0_BHT_HISTORY           [i] = new sc_signal<Tbht_history_t> (rename.c_str());
146        rename = "BRANCH_COMPLETE_PREDICTOR_0_PHT_HISTORY_"+toString(i);
147        BRANCH_COMPLETE_PREDICTOR_0_PHT_HISTORY           [i] = new sc_signal<Tpht_history_t> (rename.c_str());
148        rename = "BRANCH_COMPLETE_PREDICTOR_1_BHT_HISTORY_"+toString(i);
149        BRANCH_COMPLETE_PREDICTOR_1_BHT_HISTORY           [i] = new sc_signal<Tbht_history_t> (rename.c_str());
150        rename = "BRANCH_COMPLETE_PREDICTOR_1_PHT_HISTORY_"+toString(i);
151        BRANCH_COMPLETE_PREDICTOR_1_PHT_HISTORY           [i] = new sc_signal<Tpht_history_t> (rename.c_str());
152        rename = "BRANCH_COMPLETE_PREDICTOR_2_BHT_HISTORY_"+toString(i);
153        BRANCH_COMPLETE_PREDICTOR_2_BHT_HISTORY           [i] = new sc_signal<Tbht_history_t> (rename.c_str());
154        rename = "BRANCH_COMPLETE_PREDICTOR_2_PHT_HISTORY_"+toString(i);
155        BRANCH_COMPLETE_PREDICTOR_2_PHT_HISTORY           [i] = new sc_signal<Tpht_history_t> (rename.c_str());
156        rename = "BRANCH_COMPLETE_HISTORY_"                +toString(i);
157        BRANCH_COMPLETE_HISTORY                           [i] = new sc_signal<Thistory_t>     (rename.c_str());
158        rename = "BRANCH_COMPLETE_DIRECTION_"              +toString(i);
159        BRANCH_COMPLETE_DIRECTION                         [i] = new sc_signal<Tcontrol_t>     (rename.c_str());
160        rename = "BRANCH_COMPLETE_PREDICTOR_2_DIRECTION_"  +toString(i);
161        BRANCH_COMPLETE_PREDICTOR_2_DIRECTION             [i] = new sc_signal<Tcontrol_t>     (rename.c_str());
162      }
163
164  /********************************************************
165   * Instanciation
166   ********************************************************/
167 
168  cout << "<" << name << "> Instanciation of _Meta_Predictor_Glue" << endl;
169 
170#if defined(STATISTICS) or defined(VHDL_TESTBENCH)
171  (*(_Meta_Predictor_Glue->in_CLOCK))        (*(CLOCK));
172#endif
173
174    // Interface Predict
175    for (uint32_t i=0; i<_param._nb_prediction; i++)
176      {
177        if (_param._have_meta_predictor)
178          {
179        (*(_Meta_Predictor_Glue-> in_PREDICT_PREDICTOR_0_ACK                 [i])) (*(PREDICT_PREDICTOR_0_ACK                 [i]));
180        (*(_Meta_Predictor_Glue-> in_PREDICT_PREDICTOR_1_ACK                 [i])) (*(PREDICT_PREDICTOR_1_ACK                 [i]));
181          }                                                                                                                   
182        (*(_Meta_Predictor_Glue-> in_PREDICT_PREDICTOR_2_ACK                 [i])) (*(PREDICT_PREDICTOR_2_ACK                 [i]));
183        (*(_Meta_Predictor_Glue->out_PREDICT_ACK                             [i])) (*(PREDICT_ACK                             [i]));
184        if (_param._have_meta_predictor)
185          {                                                                                                                   
186        if (_param._predictor_0_have_bht)
187        (*(_Meta_Predictor_Glue-> in_PREDICT_PREDICTOR_0_BHT_HISTORY         [i])) (*(PREDICT_PREDICTOR_0_BHT_HISTORY         [i]));
188        if (_param._predictor_0_have_pht)
189        (*(_Meta_Predictor_Glue-> in_PREDICT_PREDICTOR_0_PHT_HISTORY         [i])) (*(PREDICT_PREDICTOR_0_PHT_HISTORY         [i]));
190        if (_param._predictor_1_have_bht)
191        (*(_Meta_Predictor_Glue-> in_PREDICT_PREDICTOR_1_BHT_HISTORY         [i])) (*(PREDICT_PREDICTOR_1_BHT_HISTORY         [i]));
192        if (_param._predictor_1_have_pht)
193        (*(_Meta_Predictor_Glue-> in_PREDICT_PREDICTOR_1_PHT_HISTORY         [i])) (*(PREDICT_PREDICTOR_1_PHT_HISTORY         [i]));
194          }                                                                                                                   
195        if (_param._predictor_2_have_bht)
196        (*(_Meta_Predictor_Glue-> in_PREDICT_PREDICTOR_2_BHT_HISTORY         [i])) (*(PREDICT_PREDICTOR_2_BHT_HISTORY         [i]));
197        if (_param._predictor_2_have_pht)
198        (*(_Meta_Predictor_Glue-> in_PREDICT_PREDICTOR_2_PHT_HISTORY         [i])) (*(PREDICT_PREDICTOR_2_PHT_HISTORY         [i]));
199        (*(_Meta_Predictor_Glue->out_PREDICT_HISTORY                         [i])) (*(PREDICT_HISTORY                         [i]));
200        (*(_Meta_Predictor_Glue->out_PREDICT_DIRECTION                       [i])) (*(PREDICT_DIRECTION                       [i]));
201      }
202
203    // Interface Branch_complete
204   
205    for (uint32_t i=0; i<_param._nb_branch_complete; i++)
206      {
207        if (_param._have_meta_predictor)
208          {
209        (*(_Meta_Predictor_Glue-> in_BRANCH_COMPLETE_VAL                     [i])) (*(BRANCH_COMPLETE_VAL                     [i]));
210        (*(_Meta_Predictor_Glue->out_BRANCH_COMPLETE_PREDICTOR_2_VAL         [i])) (*(BRANCH_COMPLETE_PREDICTOR_2_VAL         [i]));
211
212        (*(_Meta_Predictor_Glue-> in_BRANCH_COMPLETE_PREDICTOR_0_ACK         [i])) (*(BRANCH_COMPLETE_PREDICTOR_0_ACK         [i]));
213        (*(_Meta_Predictor_Glue-> in_BRANCH_COMPLETE_PREDICTOR_1_ACK         [i])) (*(BRANCH_COMPLETE_PREDICTOR_1_ACK         [i]));
214          }                                     
215        (*(_Meta_Predictor_Glue-> in_BRANCH_COMPLETE_PREDICTOR_2_ACK         [i])) (*(BRANCH_COMPLETE_PREDICTOR_2_ACK         [i]));
216        (*(_Meta_Predictor_Glue->out_BRANCH_COMPLETE_ACK                     [i])) (*(BRANCH_COMPLETE_ACK                     [i]));
217                                               
218        if (_param._have_meta_predictor)       
219          {                                     
220        if (_param._predictor_0_have_bht)
221        (*(_Meta_Predictor_Glue->out_BRANCH_COMPLETE_PREDICTOR_0_BHT_HISTORY [i])) (*(BRANCH_COMPLETE_PREDICTOR_0_BHT_HISTORY [i]));
222        if (_param._predictor_0_have_pht)
223        (*(_Meta_Predictor_Glue->out_BRANCH_COMPLETE_PREDICTOR_0_PHT_HISTORY [i])) (*(BRANCH_COMPLETE_PREDICTOR_0_PHT_HISTORY [i]));
224        if (_param._predictor_1_have_bht)
225        (*(_Meta_Predictor_Glue->out_BRANCH_COMPLETE_PREDICTOR_1_BHT_HISTORY [i])) (*(BRANCH_COMPLETE_PREDICTOR_1_BHT_HISTORY [i]));
226        if (_param._predictor_1_have_pht)
227        (*(_Meta_Predictor_Glue->out_BRANCH_COMPLETE_PREDICTOR_1_PHT_HISTORY [i])) (*(BRANCH_COMPLETE_PREDICTOR_1_PHT_HISTORY [i]));
228          }                                     
229        if (_param._predictor_2_have_bht)
230        (*(_Meta_Predictor_Glue->out_BRANCH_COMPLETE_PREDICTOR_2_BHT_HISTORY [i])) (*(BRANCH_COMPLETE_PREDICTOR_2_BHT_HISTORY [i]));
231        if (_param._predictor_2_have_pht)
232        (*(_Meta_Predictor_Glue->out_BRANCH_COMPLETE_PREDICTOR_2_PHT_HISTORY [i])) (*(BRANCH_COMPLETE_PREDICTOR_2_PHT_HISTORY [i]));
233        (*(_Meta_Predictor_Glue-> in_BRANCH_COMPLETE_HISTORY                 [i])) (*(BRANCH_COMPLETE_HISTORY                 [i]));
234        if (_param._have_meta_predictor)       
235          {
236        (*(_Meta_Predictor_Glue-> in_BRANCH_COMPLETE_DIRECTION               [i])) (*(BRANCH_COMPLETE_DIRECTION               [i]));
237        (*(_Meta_Predictor_Glue->out_BRANCH_COMPLETE_PREDICTOR_2_DIRECTION   [i])) (*(BRANCH_COMPLETE_PREDICTOR_2_DIRECTION   [i]));
238          }
239      }
240
241  /********************************************************
242   * Simulation - Begin
243   ********************************************************/
244
245  cout << "<" << name << "> Start Simulation ............" << endl;
246  // Initialisation
247
248  const uint32_t seed = 0;
249//const uint32_t seed = static_cast<uint32_t>(time(NULL));
250
251  srand(seed);
252
253  sc_start(0);
254  _Meta_Predictor_Glue->vhdl_testbench_label("Initialisation");
255  cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Initialisation" << endl;
256 
257  // No need initialisation
258
259  _Meta_Predictor_Glue->vhdl_testbench_label("Loop of Test");
260  cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Loop of Test" << endl;
261 
262  Tcontrol_t     predict_ack                             [_param._nb_prediction];
263  Thistory_t     predict_history                         [_param._nb_prediction];
264  Tcontrol_t     predict_direction                       [_param._nb_prediction];
265               
266  Tcontrol_t     branch_complete_predictor_2_val         [_param._nb_branch_complete];
267  Tcontrol_t     branch_complete_ack                     [_param._nb_branch_complete];
268  Tbht_history_t branch_complete_predictor_0_bht_history [_param._nb_branch_complete];
269  Tpht_history_t branch_complete_predictor_0_pht_history [_param._nb_branch_complete];
270  Tbht_history_t branch_complete_predictor_1_bht_history [_param._nb_branch_complete];
271  Tpht_history_t branch_complete_predictor_1_pht_history [_param._nb_branch_complete];
272  Tbht_history_t branch_complete_predictor_2_bht_history [_param._nb_branch_complete];
273  Tpht_history_t branch_complete_predictor_2_pht_history [_param._nb_branch_complete];
274  Tcontrol_t     branch_complete_predictor_2_direction   [_param._nb_branch_complete];
275
276  uint32_t shift_0 = 0;
277  uint32_t shift_1 = shift_0 + _param._predictor_0_bht_size_shifter;
278  uint32_t shift_2 = shift_1 + _param._predictor_0_pht_size_counter;
279  uint32_t shift_3 = shift_2 + _param._predictor_1_bht_size_shifter;
280  uint32_t shift_4 = shift_3 + _param._predictor_1_pht_size_counter;
281  uint32_t shift_5 = shift_4 + _param._predictor_2_bht_size_shifter;
282//uint32_t shift_6 = shift_5 + _param._predictor_2_pht_size_counter;
283
284  for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++)
285    {
286      _Meta_Predictor_Glue->vhdl_testbench_label("Iteration "+toString(iteration));
287
288      for (uint32_t i=0; i<_param._nb_prediction; i++)
289        {
290          Tcontrol_t     predictor_0_ack        , predictor_1_ack        , predictor_2_ack        ;
291          Tpht_history_t predictor_0_pht_history, predictor_1_pht_history, predictor_2_pht_history;
292          Tbht_history_t predictor_0_bht_history, predictor_1_bht_history, predictor_2_bht_history;
293
294          predictor_0_ack             = not _param._have_meta_predictor or ((rand()%2) != 0);
295          predictor_1_ack             = not _param._have_meta_predictor or ((rand()%2) != 0);
296          predictor_2_ack             =                                    ((rand()%2) != 0);
297          predict_ack             [i] = predictor_0_ack and predictor_1_ack and predictor_2_ack;
298
299          PREDICT_PREDICTOR_0_ACK [i] ->write (predictor_0_ack);
300          PREDICT_PREDICTOR_1_ACK [i] ->write (predictor_1_ack);
301          PREDICT_PREDICTOR_2_ACK [i] ->write (predictor_2_ack);
302                                     
303          predictor_0_bht_history     = rand() % (_param._predictor_0_bht_size_shifter+1);
304          predictor_0_pht_history     = rand() % (_param._predictor_0_pht_size_counter+1);
305          predictor_1_bht_history     = rand() % (_param._predictor_1_bht_size_shifter+1);
306          predictor_1_pht_history     = rand() % (_param._predictor_1_pht_size_counter+1);
307          predictor_2_bht_history     = rand() % (_param._predictor_2_bht_size_shifter+1);
308          predictor_2_pht_history     = rand() % (_param._predictor_2_pht_size_counter+1);
309                                     
310          predict_history         [i] = ( (predictor_0_bht_history << shift_0) |
311                                          (predictor_0_pht_history << shift_1) |
312                                          (predictor_1_bht_history << shift_2) |
313                                          (predictor_1_pht_history << shift_3) |
314                                          (predictor_2_bht_history << shift_4) |
315                                          (predictor_2_pht_history << shift_5) );
316         
317          cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} predict         [" << i << "]" << endl
318               << "       _2_ " << predictor_2_bht_history << " - " << predictor_2_pht_history << endl
319               << "     _/    " << endl
320               << "    | |-1- " << predictor_1_bht_history << " - " << predictor_1_pht_history << endl
321               << "  --| |    " << endl
322               << "    |_|-0- " << predictor_0_bht_history << " - " << predictor_0_pht_history << endl;
323
324
325          Tcontrol_t predict_direction_predictor_2;
326         
327          if (_param._predictor_2_have_pht)
328            predict_direction_predictor_2 = (predictor_2_pht_history & (1<<(_param._predictor_2_pht_size_counter-1))) != 0;
329          else
330            predict_direction_predictor_2 = (predictor_2_bht_history & (1<<(_param._predictor_2_bht_size_shifter-1))) != 0;
331
332          if (_param._have_meta_predictor == false)
333            predict_direction       [i] = predict_direction_predictor_2;
334          else
335            if (predict_direction_predictor_2 == false)
336              if (_param._predictor_0_have_pht)
337                predict_direction       [i] = (predictor_0_pht_history & (1<<(_param._predictor_0_pht_size_counter-1))) != 0;
338              else
339                predict_direction       [i] = (predictor_0_bht_history & (1<<(_param._predictor_0_bht_size_shifter-1))) != 0;
340            else
341              if (_param._predictor_1_have_pht)
342                predict_direction       [i] = (predictor_1_pht_history & (1<<(_param._predictor_1_pht_size_counter-1))) != 0;
343              else
344                predict_direction       [i] = (predictor_1_bht_history & (1<<(_param._predictor_1_bht_size_shifter-1))) != 0;
345
346          PREDICT_PREDICTOR_0_BHT_HISTORY [i]->write(predictor_0_bht_history);
347          PREDICT_PREDICTOR_0_PHT_HISTORY [i]->write(predictor_0_pht_history);
348          PREDICT_PREDICTOR_1_BHT_HISTORY [i]->write(predictor_1_bht_history);
349          PREDICT_PREDICTOR_1_PHT_HISTORY [i]->write(predictor_1_pht_history);
350          PREDICT_PREDICTOR_2_BHT_HISTORY [i]->write(predictor_2_bht_history);
351          PREDICT_PREDICTOR_2_PHT_HISTORY [i]->write(predictor_2_pht_history);
352        }
353
354      for (uint32_t i=0; i<_param._nb_branch_complete; i++)
355        {
356          Tcontrol_t     predictor_0_ack        , predictor_1_ack        , predictor_2_ack        ;
357
358          predictor_0_ack                             = not _param._have_meta_predictor or ((rand()%2) != 0);
359          predictor_1_ack                             = not _param._have_meta_predictor or ((rand()%2) != 0);
360          predictor_2_ack                             =                                    ((rand()%2) != 0);
361          branch_complete_ack                     [i] = predictor_0_ack and predictor_1_ack and predictor_2_ack;
362
363          BRANCH_COMPLETE_PREDICTOR_0_ACK         [i] ->write (predictor_0_ack);
364          BRANCH_COMPLETE_PREDICTOR_1_ACK         [i] ->write (predictor_1_ack);
365          BRANCH_COMPLETE_PREDICTOR_2_ACK         [i] ->write (predictor_2_ack);
366
367          branch_complete_predictor_0_bht_history [i] = rand() % (_param._predictor_0_bht_size_shifter+1);
368          branch_complete_predictor_0_pht_history [i] = rand() % (_param._predictor_0_pht_size_counter+1);
369          branch_complete_predictor_1_bht_history [i] = rand() % (_param._predictor_1_bht_size_shifter+1);
370          branch_complete_predictor_1_pht_history [i] = rand() % (_param._predictor_1_pht_size_counter+1);
371          branch_complete_predictor_2_bht_history [i] = rand() % (_param._predictor_2_bht_size_shifter+1);
372          branch_complete_predictor_2_pht_history [i] = rand() % (_param._predictor_2_pht_size_counter+1);
373               
374          BRANCH_COMPLETE_HISTORY                 [i]->write((branch_complete_predictor_0_bht_history [i] << shift_0) |
375                                                             (branch_complete_predictor_0_pht_history [i] << shift_1) |
376                                                             (branch_complete_predictor_1_bht_history [i] << shift_2) |
377                                                             (branch_complete_predictor_1_pht_history [i] << shift_3) |
378                                                             (branch_complete_predictor_2_bht_history [i] << shift_4) |
379                                                             (branch_complete_predictor_2_pht_history [i] << shift_5) );
380
381          Tcontrol_t direction_0 = ((_param._predictor_0_have_pht)?(branch_complete_predictor_0_pht_history [i] >> (_param._predictor_0_pht_size_counter-1)):(branch_complete_predictor_0_bht_history [i] >> (_param._predictor_0_bht_size_shifter-1)))&1;
382          Tcontrol_t direction_1 = ((_param._predictor_1_have_pht)?(branch_complete_predictor_1_pht_history [i] >> (_param._predictor_1_pht_size_counter-1)):(branch_complete_predictor_1_bht_history [i] >> (_param._predictor_1_bht_size_shifter-1)))&1;
383          Tcontrol_t direction_2 = ((_param._predictor_2_have_pht)?(branch_complete_predictor_2_pht_history [i] >> (_param._predictor_2_pht_size_counter-1)):(branch_complete_predictor_2_bht_history [i] >> (_param._predictor_2_bht_size_shifter-1)))&1;
384
385          Tcontrol_t direction   = ((rand()%2) != 0);
386          Tcontrol_t val         = ((rand()%2) != 0);
387
388          cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} " << endl
389               << "  * val             : " << val << endl
390               << "  * direction_good  : " << direction << endl
391               << "    * direction_0   : " << direction_0 << endl
392               << "    * direction_1   : " << direction_1 << endl
393               << "    * direction_2   : " << direction_2 << endl;
394         
395          BRANCH_COMPLETE_VAL       [i] ->write (val);
396          BRANCH_COMPLETE_DIRECTION [i] ->write (direction);
397         
398          if (val == 0)
399            {
400              branch_complete_predictor_2_val [i] = val;
401            }
402          else
403            {
404              branch_complete_predictor_2_val [i] = (direction_0 xor direction_1);
405              if (direction_2 == 0)
406                if (direction_0 == direction)
407                  branch_complete_predictor_2_direction [i] = 0;
408                else
409                  branch_complete_predictor_2_direction [i] = 1;
410              else
411                if (direction_1 == direction)
412                  branch_complete_predictor_2_direction [i] = 1;
413                else
414                  branch_complete_predictor_2_direction [i] = 0;
415            }
416        }
417
418      sc_start(1);
419
420      for (uint32_t i=0; i<_param._nb_prediction; i++)
421        {
422          TEST(Tcontrol_t    , PREDICT_ACK                             [i]->read(), predict_ack                             [i]);
423          TEST(Tcontrol_t    , PREDICT_HISTORY                         [i]->read(), predict_history                         [i]);
424          TEST(Tcontrol_t    , PREDICT_DIRECTION                       [i]->read(), predict_direction                       [i]);
425        }
426
427      for (uint32_t i=0; i<_param._nb_branch_complete; i++)
428        {
429          TEST(Tcontrol_t    , BRANCH_COMPLETE_ACK                     [i]->read(), branch_complete_ack                     [i]);
430
431        if (_param._have_meta_predictor)       
432          {                                     
433          TEST(Tcontrol_t    , BRANCH_COMPLETE_PREDICTOR_2_VAL         [i]->read(), branch_complete_predictor_2_val         [i]);
434
435          if (branch_complete_predictor_2_val         [i])
436          TEST(Tcontrol_t    , BRANCH_COMPLETE_PREDICTOR_2_DIRECTION   [i]->read(), branch_complete_predictor_2_direction   [i]); 
437
438        if (_param._predictor_0_have_bht)
439          TEST(Tbht_history_t, BRANCH_COMPLETE_PREDICTOR_0_BHT_HISTORY [i]->read(), branch_complete_predictor_0_bht_history [i]);
440        if (_param._predictor_0_have_pht)
441          TEST(Tpht_history_t, BRANCH_COMPLETE_PREDICTOR_0_PHT_HISTORY [i]->read(), branch_complete_predictor_0_pht_history [i]);
442        if (_param._predictor_1_have_bht)
443          TEST(Tbht_history_t, BRANCH_COMPLETE_PREDICTOR_1_BHT_HISTORY [i]->read(), branch_complete_predictor_1_bht_history [i]);
444        if (_param._predictor_1_have_pht)
445          TEST(Tpht_history_t, BRANCH_COMPLETE_PREDICTOR_1_PHT_HISTORY [i]->read(), branch_complete_predictor_1_pht_history [i]);
446          }                                     
447        if (_param._predictor_2_have_bht)
448          TEST(Tbht_history_t, BRANCH_COMPLETE_PREDICTOR_2_BHT_HISTORY [i]->read(), branch_complete_predictor_2_bht_history [i]);
449        if (_param._predictor_2_have_pht)
450          TEST(Tpht_history_t, BRANCH_COMPLETE_PREDICTOR_2_PHT_HISTORY [i]->read(), branch_complete_predictor_2_pht_history [i]);
451        }
452    }
453
454  /********************************************************
455   * Simulation - End
456   ********************************************************/
457
458  cout << "<" << name << "> ............ Stop Simulation" << endl;
459
460#endif
461
462  delete _Meta_Predictor_Glue;
463}
Note: See TracBrowser for help on using the repository browser.