1 | /* |
---|
2 | * $Id: test.cpp 82 2008-05-01 16:48:45Z rosiere $ |
---|
3 | * |
---|
4 | * [ Description ] |
---|
5 | * |
---|
6 | * Test |
---|
7 | */ |
---|
8 | |
---|
9 | #define NB_ITERATION 1024 |
---|
10 | #define CYCLE_MAX (128*NB_ITERATION) |
---|
11 | |
---|
12 | #include "Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Direction/SelfTest/include/test.h" |
---|
13 | #include "Common/include/Test.h" |
---|
14 | #include "Common/include/BitManipulation.h" |
---|
15 | #include "Behavioural/include/Allocation.h" |
---|
16 | |
---|
17 | void test (string name, |
---|
18 | morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::direction::Parameters * _param) |
---|
19 | { |
---|
20 | msg(_("<%s> : Simulation SystemC.\n"),name.c_str()); |
---|
21 | |
---|
22 | #ifdef STATISTICS |
---|
23 | morpheo::behavioural::Parameters_Statistics * _parameters_statistics = new morpheo::behavioural::Parameters_Statistics (5,50); |
---|
24 | #endif |
---|
25 | |
---|
26 | Direction * _Direction = new Direction |
---|
27 | (name.c_str(), |
---|
28 | #ifdef STATISTICS |
---|
29 | _parameters_statistics, |
---|
30 | #endif |
---|
31 | _param, |
---|
32 | USE_ALL); |
---|
33 | |
---|
34 | #ifdef SYSTEMC |
---|
35 | /********************************************************************* |
---|
36 | * Déclarations des signaux |
---|
37 | *********************************************************************/ |
---|
38 | string rename; |
---|
39 | |
---|
40 | sc_clock * in_CLOCK = new sc_clock ("clock", 1.0, 0.5); |
---|
41 | sc_signal<Tcontrol_t> * in_NRESET = new sc_signal<Tcontrol_t> ("NRESET"); |
---|
42 | |
---|
43 | ALLOC1_SC_SIGNAL( in_PREDICT_VAL ," in_PREDICT_VAL ",Tcontrol_t,_param->_nb_inst_predict); |
---|
44 | ALLOC1_SC_SIGNAL(out_PREDICT_ACK ,"out_PREDICT_ACK ",Tcontrol_t,_param->_nb_inst_predict); |
---|
45 | ALLOC1_SC_SIGNAL( in_PREDICT_ADDRESS_SRC ," in_PREDICT_ADDRESS_SRC ",Taddress_t,_param->_nb_inst_predict); |
---|
46 | ALLOC1_SC_SIGNAL( in_PREDICT_STATIC ," in_PREDICT_STATIC ",Tcontrol_t,_param->_nb_inst_predict); |
---|
47 | ALLOC1_SC_SIGNAL( in_PREDICT_LAST_TAKE ," in_PREDICT_LAST_TAKE ",Tcontrol_t,_param->_nb_inst_predict); |
---|
48 | ALLOC1_SC_SIGNAL(out_PREDICT_HISTORY ,"out_PREDICT_HISTORY ",Thistory_t,_param->_nb_inst_predict); |
---|
49 | ALLOC1_SC_SIGNAL(out_PREDICT_DIRECTION ,"out_PREDICT_DIRECTION ",Tcontrol_t,_param->_nb_inst_predict); |
---|
50 | ALLOC1_SC_SIGNAL( in_UPDATE_VAL ," in_UPDATE_VAL ",Tcontrol_t,_param->_nb_inst_update); |
---|
51 | ALLOC1_SC_SIGNAL(out_UPDATE_ACK ,"out_UPDATE_ACK ",Tcontrol_t,_param->_nb_inst_update); |
---|
52 | ALLOC1_SC_SIGNAL( in_UPDATE_ADDRESS ," in_UPDATE_ADDRESS ",Taddress_t,_param->_nb_inst_update); |
---|
53 | ALLOC1_SC_SIGNAL( in_UPDATE_HISTORY ," in_UPDATE_HISTORY ",Thistory_t,_param->_nb_inst_update); |
---|
54 | ALLOC1_SC_SIGNAL( in_UPDATE_DIRECTION ," in_UPDATE_DIRECTION ",Tcontrol_t,_param->_nb_inst_update); |
---|
55 | |
---|
56 | /******************************************************** |
---|
57 | * Instanciation |
---|
58 | ********************************************************/ |
---|
59 | |
---|
60 | msg(_("<%s> : Instanciation of _Direction.\n"),name.c_str()); |
---|
61 | |
---|
62 | (*(_Direction->in_CLOCK)) (*(in_CLOCK)); |
---|
63 | (*(_Direction->in_NRESET)) (*(in_NRESET)); |
---|
64 | |
---|
65 | INSTANCE1_SC_SIGNAL(_Direction, in_PREDICT_VAL ,_param->_nb_inst_predict); |
---|
66 | INSTANCE1_SC_SIGNAL(_Direction,out_PREDICT_ACK ,_param->_nb_inst_predict); |
---|
67 | INSTANCE1_SC_SIGNAL(_Direction, in_PREDICT_ADDRESS_SRC ,_param->_nb_inst_predict); |
---|
68 | INSTANCE1_SC_SIGNAL(_Direction, in_PREDICT_STATIC ,_param->_nb_inst_predict); |
---|
69 | INSTANCE1_SC_SIGNAL(_Direction, in_PREDICT_LAST_TAKE ,_param->_nb_inst_predict); |
---|
70 | if (_param->_have_port_history) |
---|
71 | INSTANCE1_SC_SIGNAL(_Direction,out_PREDICT_HISTORY ,_param->_nb_inst_predict); |
---|
72 | INSTANCE1_SC_SIGNAL(_Direction,out_PREDICT_DIRECTION ,_param->_nb_inst_predict); |
---|
73 | INSTANCE1_SC_SIGNAL(_Direction, in_UPDATE_VAL ,_param->_nb_inst_update); |
---|
74 | INSTANCE1_SC_SIGNAL(_Direction,out_UPDATE_ACK ,_param->_nb_inst_update); |
---|
75 | INSTANCE1_SC_SIGNAL(_Direction, in_UPDATE_ADDRESS ,_param->_nb_inst_update); |
---|
76 | if (_param->_have_port_history) |
---|
77 | INSTANCE1_SC_SIGNAL(_Direction, in_UPDATE_HISTORY ,_param->_nb_inst_update); |
---|
78 | INSTANCE1_SC_SIGNAL(_Direction, in_UPDATE_DIRECTION ,_param->_nb_inst_update); |
---|
79 | |
---|
80 | msg(_("<%s> : Start Simulation ............\n"),name.c_str()); |
---|
81 | |
---|
82 | Time * _time = new Time(); |
---|
83 | |
---|
84 | /******************************************************** |
---|
85 | * Simulation - Begin |
---|
86 | ********************************************************/ |
---|
87 | |
---|
88 | // Initialisation |
---|
89 | |
---|
90 | const uint32_t seed = 0; |
---|
91 | //const uint32_t seed = static_cast<uint32_t>(time(NULL)); |
---|
92 | |
---|
93 | srand(seed); |
---|
94 | |
---|
95 | SC_START(0); |
---|
96 | LABEL("Initialisation"); |
---|
97 | |
---|
98 | LABEL("Reset"); |
---|
99 | in_NRESET->write(0); |
---|
100 | SC_START(5); |
---|
101 | in_NRESET->write(1); |
---|
102 | |
---|
103 | LABEL("Loop of Test"); |
---|
104 | |
---|
105 | for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++) |
---|
106 | { |
---|
107 | LABEL("Iteration %d",iteration); |
---|
108 | |
---|
109 | for (uint32_t i=0; i<_param->_nb_inst_predict; i++) |
---|
110 | { |
---|
111 | in_PREDICT_VAL [i]->write(rand()%2); |
---|
112 | in_PREDICT_ADDRESS_SRC [i]->write(range<Taddress_t>(rand(),_param->_size_address)); |
---|
113 | in_PREDICT_STATIC [i]->write(rand()%2); |
---|
114 | in_PREDICT_LAST_TAKE [i]->write(rand()%2); |
---|
115 | } |
---|
116 | |
---|
117 | for (uint32_t i=0; i<_param->_nb_inst_update; i++) |
---|
118 | { |
---|
119 | in_UPDATE_VAL [i]->write(rand()%2); |
---|
120 | in_UPDATE_ADDRESS [i]->write(range<Taddress_t>(rand(),_param->_size_address)); |
---|
121 | in_UPDATE_HISTORY [i]->write(range<Thistory_t>(rand(),_param->_size_history)); |
---|
122 | in_UPDATE_DIRECTION [i]->write(rand()%2); |
---|
123 | } |
---|
124 | |
---|
125 | SC_START(0); |
---|
126 | |
---|
127 | for (uint32_t i=0; i<_param->_nb_inst_predict; i++) |
---|
128 | { |
---|
129 | switch (_param->_predictor_scheme) |
---|
130 | { |
---|
131 | case PREDICTOR_NEVER_TAKE : |
---|
132 | { |
---|
133 | TEST(Tcontrol_t,out_PREDICT_ACK [i]->read(), 1); |
---|
134 | TEST(Tcontrol_t,out_PREDICT_DIRECTION [i]->read(), 0); |
---|
135 | break; |
---|
136 | } |
---|
137 | case PREDICTOR_ALWAYS_TAKE : |
---|
138 | { |
---|
139 | TEST(Tcontrol_t,out_PREDICT_ACK [i]->read(), 1); |
---|
140 | TEST(Tcontrol_t,out_PREDICT_DIRECTION [i]->read(), 1); |
---|
141 | break; |
---|
142 | } |
---|
143 | case PREDICTOR_STATIC : |
---|
144 | { |
---|
145 | TEST(Tcontrol_t,out_PREDICT_ACK [i]->read(), 1); |
---|
146 | TEST(Tcontrol_t,out_PREDICT_DIRECTION [i]->read(), in_PREDICT_STATIC [i]->read()); |
---|
147 | break; |
---|
148 | } |
---|
149 | case PREDICTOR_LAST_TAKE : |
---|
150 | { |
---|
151 | TEST(Tcontrol_t,out_PREDICT_ACK [i]->read(), 1); |
---|
152 | TEST(Tcontrol_t,out_PREDICT_DIRECTION [i]->read(), in_PREDICT_LAST_TAKE [i]->read()); |
---|
153 | break; |
---|
154 | } |
---|
155 | case PREDICTOR_COUNTER : |
---|
156 | case PREDICTOR_LOCAL : |
---|
157 | case PREDICTOR_GLOBAL : |
---|
158 | case PREDICTOR_META : |
---|
159 | case PREDICTOR_CUSTOM : |
---|
160 | { |
---|
161 | break; |
---|
162 | } |
---|
163 | default : |
---|
164 | { |
---|
165 | break; |
---|
166 | } |
---|
167 | } |
---|
168 | } |
---|
169 | |
---|
170 | for (uint32_t i=0; i<_param->_nb_inst_update; i++) |
---|
171 | { |
---|
172 | |
---|
173 | |
---|
174 | switch (_param->_predictor_scheme) |
---|
175 | { |
---|
176 | case PREDICTOR_COUNTER : |
---|
177 | case PREDICTOR_LOCAL : |
---|
178 | case PREDICTOR_GLOBAL : |
---|
179 | case PREDICTOR_META : |
---|
180 | case PREDICTOR_CUSTOM : |
---|
181 | { |
---|
182 | break; |
---|
183 | } |
---|
184 | case PREDICTOR_NEVER_TAKE : |
---|
185 | case PREDICTOR_ALWAYS_TAKE : |
---|
186 | case PREDICTOR_STATIC : |
---|
187 | case PREDICTOR_LAST_TAKE : |
---|
188 | default : |
---|
189 | { |
---|
190 | TEST(Tcontrol_t,out_UPDATE_ACK [i]->read(), 1); |
---|
191 | break; |
---|
192 | } |
---|
193 | } |
---|
194 | } |
---|
195 | |
---|
196 | SC_START(1); |
---|
197 | |
---|
198 | } |
---|
199 | |
---|
200 | /******************************************************** |
---|
201 | * Simulation - End |
---|
202 | ********************************************************/ |
---|
203 | |
---|
204 | TEST_OK ("End of Simulation"); |
---|
205 | delete _time; |
---|
206 | |
---|
207 | msg(_("<%s> : ............ Stop Simulation\n"),name.c_str()); |
---|
208 | |
---|
209 | delete in_CLOCK; |
---|
210 | delete in_NRESET; |
---|
211 | |
---|
212 | delete [] in_PREDICT_VAL ; |
---|
213 | delete [] out_PREDICT_ACK ; |
---|
214 | delete [] in_PREDICT_ADDRESS_SRC ; |
---|
215 | delete [] in_PREDICT_STATIC ; |
---|
216 | delete [] in_PREDICT_LAST_TAKE ; |
---|
217 | delete [] out_PREDICT_HISTORY ; |
---|
218 | delete [] out_PREDICT_DIRECTION ; |
---|
219 | delete [] in_UPDATE_VAL ; |
---|
220 | delete [] out_UPDATE_ACK ; |
---|
221 | delete [] in_UPDATE_ADDRESS ; |
---|
222 | delete [] in_UPDATE_HISTORY ; |
---|
223 | delete [] in_UPDATE_DIRECTION ; |
---|
224 | |
---|
225 | #endif |
---|
226 | |
---|
227 | delete _Direction; |
---|
228 | #ifdef STATISTICS |
---|
229 | delete _parameters_statistics; |
---|
230 | #endif |
---|
231 | } |
---|