source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Stage_1_Ifetch/Predictor/Meta_Predictor/Two_Level_Branch_Predictor/Pattern_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/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>                    PREDICT_VAL             [param._nb_prediction];
46  sc_signal<Tcontrol_t>                    PREDICT_ACK             [param._nb_prediction];
47  sc_signal<Taddress_t>                    PREDICT_ADDRESS         [param._nb_prediction];
48  sc_signal<Thistory_t>                    PREDICT_HISTORY         [param._nb_prediction];
49                                           
50  sc_signal<Tcontrol_t>                    BRANCH_COMPLETE_VAL     [param._nb_branch_complete];
51  sc_signal<Tcontrol_t>                    BRANCH_COMPLETE_ACK     [param._nb_branch_complete];
52  sc_signal<Taddress_t>                    BRANCH_COMPLETE_ADDRESS [param._nb_branch_complete];
53  sc_signal<Thistory_t>                    BRANCH_COMPLETE_HISTORY [param._nb_branch_complete];
54  sc_signal<Tcontrol_t>                    BRANCH_COMPLETE_HIT     [param._nb_branch_complete];
55 
56  /********************************************************
57   * Instanciation
58   ********************************************************/
59 
60  cout << "<" << name << "> Instanciation of _Pattern_History_Table" << endl;
61 
62  (*(_Pattern_History_Table->in_CLOCK))        (CLOCK);
63
64  for (uint32_t i=0; i<param._nb_prediction; i++)
65    {
66      (*(_Pattern_History_Table-> in_PREDICT_VAL     [i]))        (PREDICT_VAL     [i]);
67      (*(_Pattern_History_Table->out_PREDICT_ACK     [i]))        (PREDICT_ACK     [i]);
68      (*(_Pattern_History_Table-> in_PREDICT_ADDRESS [i]))        (PREDICT_ADDRESS [i]);
69      (*(_Pattern_History_Table->out_PREDICT_HISTORY [i]))        (PREDICT_HISTORY [i]);
70    }
71
72  for (uint32_t i=0; i<param._nb_branch_complete; i++)
73    {
74      (*(_Pattern_History_Table-> in_BRANCH_COMPLETE_VAL     [i]))        (BRANCH_COMPLETE_VAL     [i]);
75      (*(_Pattern_History_Table->out_BRANCH_COMPLETE_ACK     [i]))        (BRANCH_COMPLETE_ACK     [i]);
76      (*(_Pattern_History_Table-> in_BRANCH_COMPLETE_ADDRESS [i]))        (BRANCH_COMPLETE_ADDRESS [i]);
77      (*(_Pattern_History_Table-> in_BRANCH_COMPLETE_HISTORY [i]))        (BRANCH_COMPLETE_HISTORY [i]);
78      (*(_Pattern_History_Table-> in_BRANCH_COMPLETE_HIT     [i]))        (BRANCH_COMPLETE_HIT     [i]);
79    }
80
81  /********************************************************
82   * Simulation - Begin
83   ********************************************************/
84
85  cout << "<" << name << "> Start Simulation ............" << endl;
86  // Initialisation
87
88  srand(0);
89  //srand(TIME(NULL));
90
91  sc_start(0);
92  _Pattern_History_Table->vhdl_testbench_label("Initialisation");
93  cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Initialisation" << endl;
94
95
96  for (uint32_t i=0; i<param._nb_prediction; i++)
97    PREDICT_VAL         [i].write(0);
98  for (uint32_t i=0; i<param._nb_branch_complete; i++)
99    BRANCH_COMPLETE_VAL [i].write(0);
100
101  // Initialisation of Register
102  uint32_t   num_port_branch_complete = 0;
103  uint32_t   num_port_predict         = 0;
104  Taddress_t address                  = 0;
105  Thistory_t history_max              = (1<<param._size_counter)-1;
106  Thistory_t history                  = 0;
107  Tcontrol_t hit                      = 0;
108
109  while (address<param._nb_counter)
110    {
111      BRANCH_COMPLETE_VAL     [0].write(1);
112      BRANCH_COMPLETE_ADDRESS [0].write(address);
113      BRANCH_COMPLETE_HISTORY [0].write(0);
114      BRANCH_COMPLETE_HIT     [0].write(0);
115
116      sc_start(1);
117     
118      if (BRANCH_COMPLETE_ACK[0].read()==1)
119        address++;
120    }
121 
122  BRANCH_COMPLETE_VAL     [0].write(0);
123  sc_start(0);
124
125  _Pattern_History_Table->vhdl_testbench_label("Loop of Test");
126  cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Loop of Test" << endl;
127
128  for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++)
129    {
130      _Pattern_History_Table->vhdl_testbench_label("Iteration "+toString(iteration));
131      num_port_branch_complete = rand() % param._nb_branch_complete;
132      num_port_predict         = rand() % param._nb_prediction     ;
133      address                  = rand() % param._nb_counter        ;
134      history                  = rand() % (1<<param._size_counter) ;
135      hit                      = rand() % 2;
136
137      cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} ["+toString(num_port_branch_complete)+"]" << endl
138           << hex
139           << " - address     : " << address << endl
140           << " - history old : " << history << endl
141           << " - hit         : " << hit     << endl;
142
143      BRANCH_COMPLETE_VAL     [num_port_branch_complete].write(1);
144      BRANCH_COMPLETE_ADDRESS [num_port_branch_complete].write(address);
145      BRANCH_COMPLETE_HISTORY [num_port_branch_complete].write(history);
146      BRANCH_COMPLETE_HIT     [num_port_branch_complete].write(hit);
147
148      // Wait Ack
149      do
150        {
151          sc_start(1);
152        }
153      while (BRANCH_COMPLETE_ACK[num_port_branch_complete].read()!=1);
154
155      BRANCH_COMPLETE_VAL     [num_port_branch_complete].write(0);
156      PREDICT_VAL             [num_port_predict        ].write(1);
157      PREDICT_ADDRESS         [num_port_predict        ].write(address);
158     
159      history                  = (hit==1)?((history<history_max)?history+1:history):((history>0)?history-1:history);
160     
161      // Wait Ack
162      do
163        {
164          sc_start(1);
165        }
166      while (PREDICT_ACK        [num_port_predict        ].read()!=1);
167
168      PREDICT_VAL             [num_port_predict        ].write(0);
169
170      cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} ["+toString(num_port_predict)+"]" << endl
171           << " - history new : " << PREDICT_HISTORY [num_port_predict].read() << endl
172           << dec;
173
174      TEST(Thistory_t,PREDICT_HISTORY [num_port_predict].read(),history);
175    }
176
177  /********************************************************
178   * Simulation - End
179   ********************************************************/
180
181  cout << "<" << name << "> ............ Stop Simulation" << endl;
182
183#endif
184
185  delete _Pattern_History_Table;
186}
Note: See TracBrowser for help on using the repository browser.