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

Last change on this file since 2 was 2, checked in by kane, 17 years ago

Import Morpheo

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