1 | /* |
---|
2 | * $Id$ |
---|
3 | * |
---|
4 | * [ Description ] |
---|
5 | * |
---|
6 | * Test |
---|
7 | */ |
---|
8 | |
---|
9 | #include "Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Branch_Target_Buffer/SelfTest/include/test.h" |
---|
10 | #include "Common/include/Test.h" |
---|
11 | #include "Behavioural/include/Allocation.h" |
---|
12 | |
---|
13 | #define NB_ITERATION 1024 |
---|
14 | #define CYCLE_MAX (128*NB_ITERATION) |
---|
15 | |
---|
16 | #define LABEL(str...) \ |
---|
17 | { \ |
---|
18 | msg (_("{%d} "),static_cast<uint32_t>(sc_simulation_time())); \ |
---|
19 | msg (str); \ |
---|
20 | msg (_("\n")); \ |
---|
21 | } while(0) |
---|
22 | |
---|
23 | #define SC_START(cycle_offset) \ |
---|
24 | do \ |
---|
25 | { \ |
---|
26 | /*cout << "SC_START (begin)" << endl;*/ \ |
---|
27 | \ |
---|
28 | uint32_t cycle_current = static_cast<uint32_t>(sc_simulation_time()); \ |
---|
29 | if (cycle_offset != 0) \ |
---|
30 | { \ |
---|
31 | cout << "##########[ cycle "<< cycle_current+cycle_offset << " ]" << endl; \ |
---|
32 | } \ |
---|
33 | \ |
---|
34 | if (cycle_current > CYCLE_MAX) \ |
---|
35 | { \ |
---|
36 | TEST_KO("Maximal cycles Reached"); \ |
---|
37 | } \ |
---|
38 | \ |
---|
39 | sc_start(cycle_offset); \ |
---|
40 | \ |
---|
41 | /*cout << "SC_START (end )" << endl;*/ \ |
---|
42 | } while(0) |
---|
43 | |
---|
44 | void test (string name, |
---|
45 | morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::branch_target_buffer::Parameters * _param) |
---|
46 | { |
---|
47 | msg(_("<%s> : Simulation SystemC.\n"),name.c_str()); |
---|
48 | |
---|
49 | #ifdef STATISTICS |
---|
50 | morpheo::behavioural::Parameters_Statistics * _parameters_statistics = new morpheo::behavioural::Parameters_Statistics (5,50); |
---|
51 | #endif |
---|
52 | |
---|
53 | Branch_Target_Buffer * _Branch_Target_Buffer = new Branch_Target_Buffer (name.c_str(), |
---|
54 | #ifdef STATISTICS |
---|
55 | _parameters_statistics, |
---|
56 | #endif |
---|
57 | _param); |
---|
58 | |
---|
59 | #ifdef SYSTEMC |
---|
60 | /********************************************************************* |
---|
61 | * Déclarations des signaux |
---|
62 | *********************************************************************/ |
---|
63 | string rename; |
---|
64 | |
---|
65 | sc_clock * in_CLOCK = new sc_clock ("clock", 1.0, 0.5); |
---|
66 | sc_signal<Tcontrol_t> * in_NRESET = new sc_signal<Tcontrol_t> ("NRESET"); |
---|
67 | |
---|
68 | ALLOC1_SC_SIGNAL( in_PREDICT_VAL ," in_PREDICT_VAL ",Tcontrol_t ,_param->_nb_inst_predict); |
---|
69 | ALLOC1_SC_SIGNAL(out_PREDICT_ACK ,"out_PREDICT_ACK ",Tcontrol_t ,_param->_nb_inst_predict); |
---|
70 | ALLOC1_SC_SIGNAL( in_PREDICT_CONTEXT_ID ," in_PREDICT_CONTEXT_ID ",Tcontext_t ,_param->_nb_inst_predict); |
---|
71 | ALLOC1_SC_SIGNAL( in_PREDICT_ADDRESS ," in_PREDICT_ADDRESS ",Tgeneral_data_t ,_param->_nb_inst_predict); |
---|
72 | ALLOC1_SC_SIGNAL(out_PREDICT_HIT ,"out_PREDICT_HIT ",Tcontrol_t ,_param->_nb_inst_predict); |
---|
73 | ALLOC1_SC_SIGNAL(out_PREDICT_ADDRESS_SRC ,"out_PREDICT_ADDRESS_SRC ",Tgeneral_data_t ,_param->_nb_inst_predict); |
---|
74 | ALLOC1_SC_SIGNAL(out_PREDICT_ADDRESS_DEST ,"out_PREDICT_ADDRESS_DEST ",Tgeneral_data_t ,_param->_nb_inst_predict); |
---|
75 | ALLOC1_SC_SIGNAL(out_PREDICT_CONDITION ,"out_PREDICT_CONDITION ",Tbranch_condition_t,_param->_nb_inst_predict); |
---|
76 | ALLOC1_SC_SIGNAL(out_PREDICT_LAST_TAKE ,"out_PREDICT_LAST_TAKE ",Tcontrol_t ,_param->_nb_inst_predict); |
---|
77 | ALLOC1_SC_SIGNAL(out_PREDICT_IS_ACCURATE ,"out_PREDICT_IS_ACCURATE ",Tcontrol_t ,_param->_nb_inst_predict); |
---|
78 | ALLOC1_SC_SIGNAL( in_DECOD_VAL ," in_DECOD_VAL ",Tcontrol_t ,_param->_nb_inst_decod); |
---|
79 | ALLOC1_SC_SIGNAL(out_DECOD_ACK ,"out_DECOD_ACK ",Tcontrol_t ,_param->_nb_inst_decod); |
---|
80 | ALLOC1_SC_SIGNAL( in_DECOD_CONTEXT_ID ," in_DECOD_CONTEXT_ID ",Tcontext_t ,_param->_nb_inst_decod); |
---|
81 | ALLOC1_SC_SIGNAL( in_DECOD_ADDRESS_SRC ," in_DECOD_ADDRESS_SRC ",Tgeneral_data_t ,_param->_nb_inst_decod); |
---|
82 | ALLOC1_SC_SIGNAL( in_DECOD_ADDRESS_DEST ," in_DECOD_ADDRESS_DEST ",Tgeneral_data_t ,_param->_nb_inst_decod); |
---|
83 | ALLOC1_SC_SIGNAL( in_DECOD_CONDITION ," in_DECOD_CONDITION ",Tbranch_condition_t,_param->_nb_inst_decod); |
---|
84 | ALLOC1_SC_SIGNAL( in_DECOD_LAST_TAKE ," in_DECOD_LAST_TAKE ",Tcontrol_t ,_param->_nb_inst_decod); |
---|
85 | ALLOC1_SC_SIGNAL( in_DECOD_MISS_PREDICTION ," in_DECOD_MISS_PREDICTION ",Tcontrol_t ,_param->_nb_inst_decod); |
---|
86 | ALLOC1_SC_SIGNAL( in_UPDATE_VAL ," in_UPDATE_VAL ",Tcontrol_t ,_param->_nb_inst_update); |
---|
87 | ALLOC1_SC_SIGNAL(out_UPDATE_ACK ,"out_UPDATE_ACK ",Tcontrol_t ,_param->_nb_inst_update); |
---|
88 | ALLOC1_SC_SIGNAL( in_UPDATE_CONTEXT_ID ," in_UPDATE_CONTEXT_ID ",Tcontext_t ,_param->_nb_inst_update); |
---|
89 | ALLOC1_SC_SIGNAL( in_UPDATE_ADDRESS_SRC ," in_UPDATE_ADDRESS_SRC ",Tgeneral_data_t ,_param->_nb_inst_update); |
---|
90 | ALLOC1_SC_SIGNAL( in_UPDATE_ADDRESS_DEST ," in_UPDATE_ADDRESS_DEST ",Tgeneral_data_t ,_param->_nb_inst_update); |
---|
91 | ALLOC1_SC_SIGNAL( in_UPDATE_CONDITION ," in_UPDATE_CONDITION ",Tbranch_condition_t,_param->_nb_inst_update); |
---|
92 | ALLOC1_SC_SIGNAL( in_UPDATE_LAST_TAKE ," in_UPDATE_LAST_TAKE ",Tcontrol_t ,_param->_nb_inst_update); |
---|
93 | ALLOC1_SC_SIGNAL( in_UPDATE_MISS_PREDICTION," in_UPDATE_MISS_PREDICTION",Tcontrol_t ,_param->_nb_inst_update); |
---|
94 | |
---|
95 | /******************************************************** |
---|
96 | * Instanciation |
---|
97 | ********************************************************/ |
---|
98 | |
---|
99 | msg(_("<%s> : Instanciation of _Branch_Target_Buffer.\n"),name.c_str()); |
---|
100 | |
---|
101 | (*(_Branch_Target_Buffer->in_CLOCK)) (*(in_CLOCK)); |
---|
102 | (*(_Branch_Target_Buffer->in_NRESET)) (*(in_NRESET)); |
---|
103 | |
---|
104 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer, in_PREDICT_VAL ,_param->_nb_inst_predict); |
---|
105 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer,out_PREDICT_ACK ,_param->_nb_inst_predict); |
---|
106 | if (_param->_have_port_context_id) |
---|
107 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer, in_PREDICT_CONTEXT_ID ,_param->_nb_inst_predict); |
---|
108 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer, in_PREDICT_ADDRESS ,_param->_nb_inst_predict); |
---|
109 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer,out_PREDICT_HIT ,_param->_nb_inst_predict); |
---|
110 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer,out_PREDICT_ADDRESS_SRC ,_param->_nb_inst_predict); |
---|
111 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer,out_PREDICT_ADDRESS_DEST ,_param->_nb_inst_predict); |
---|
112 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer,out_PREDICT_CONDITION ,_param->_nb_inst_predict); |
---|
113 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer,out_PREDICT_LAST_TAKE ,_param->_nb_inst_predict); |
---|
114 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer,out_PREDICT_IS_ACCURATE ,_param->_nb_inst_predict); |
---|
115 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer, in_DECOD_VAL ,_param->_nb_inst_decod); |
---|
116 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer,out_DECOD_ACK ,_param->_nb_inst_decod); |
---|
117 | if (_param->_have_port_context_id) |
---|
118 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer, in_DECOD_CONTEXT_ID ,_param->_nb_inst_decod); |
---|
119 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer, in_DECOD_ADDRESS_SRC ,_param->_nb_inst_decod); |
---|
120 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer, in_DECOD_ADDRESS_DEST ,_param->_nb_inst_decod); |
---|
121 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer, in_DECOD_CONDITION ,_param->_nb_inst_decod); |
---|
122 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer, in_DECOD_LAST_TAKE ,_param->_nb_inst_decod); |
---|
123 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer, in_DECOD_MISS_PREDICTION ,_param->_nb_inst_decod); |
---|
124 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer, in_UPDATE_VAL ,_param->_nb_inst_update); |
---|
125 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer,out_UPDATE_ACK ,_param->_nb_inst_update); |
---|
126 | if (_param->_have_port_context_id) |
---|
127 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer, in_UPDATE_CONTEXT_ID ,_param->_nb_inst_update); |
---|
128 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer, in_UPDATE_ADDRESS_SRC ,_param->_nb_inst_update); |
---|
129 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer, in_UPDATE_ADDRESS_DEST ,_param->_nb_inst_update); |
---|
130 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer, in_UPDATE_CONDITION ,_param->_nb_inst_update); |
---|
131 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer, in_UPDATE_LAST_TAKE ,_param->_nb_inst_update); |
---|
132 | INSTANCE1_SC_SIGNAL(_Branch_Target_Buffer, in_UPDATE_MISS_PREDICTION,_param->_nb_inst_update); |
---|
133 | |
---|
134 | msg(_("<%s> : Start Simulation ............\n"),name.c_str()); |
---|
135 | |
---|
136 | Time * _time = new Time(); |
---|
137 | |
---|
138 | /******************************************************** |
---|
139 | * Simulation - Begin |
---|
140 | ********************************************************/ |
---|
141 | |
---|
142 | // Initialisation |
---|
143 | |
---|
144 | const uint32_t seed = 0; |
---|
145 | //const uint32_t seed = static_cast<uint32_t>(time(NULL)); |
---|
146 | |
---|
147 | srand(seed); |
---|
148 | |
---|
149 | SC_START(0); |
---|
150 | LABEL("Initialisation"); |
---|
151 | |
---|
152 | LABEL("Reset"); |
---|
153 | in_NRESET->write(0); |
---|
154 | SC_START(5); |
---|
155 | in_NRESET->write(1); |
---|
156 | |
---|
157 | LABEL("Loop of Test"); |
---|
158 | |
---|
159 | for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++) |
---|
160 | { |
---|
161 | LABEL("Iteration %d",iteration); |
---|
162 | |
---|
163 | SC_START(1); |
---|
164 | } |
---|
165 | |
---|
166 | /******************************************************** |
---|
167 | * Simulation - End |
---|
168 | ********************************************************/ |
---|
169 | |
---|
170 | TEST_OK ("End of Simulation"); |
---|
171 | delete _time; |
---|
172 | |
---|
173 | msg(_("<%s> : ............ Stop Simulation\n"),name.c_str()); |
---|
174 | |
---|
175 | delete in_CLOCK; |
---|
176 | delete in_NRESET; |
---|
177 | |
---|
178 | delete [] in_PREDICT_VAL ; |
---|
179 | delete [] out_PREDICT_ACK ; |
---|
180 | delete [] in_PREDICT_CONTEXT_ID ; |
---|
181 | delete [] in_PREDICT_ADDRESS ; |
---|
182 | delete [] out_PREDICT_HIT ; |
---|
183 | delete [] out_PREDICT_ADDRESS_SRC ; |
---|
184 | delete [] out_PREDICT_ADDRESS_DEST ; |
---|
185 | delete [] out_PREDICT_CONDITION ; |
---|
186 | delete [] out_PREDICT_LAST_TAKE ; |
---|
187 | delete [] out_PREDICT_IS_ACCURATE ; |
---|
188 | |
---|
189 | delete [] in_DECOD_VAL ; |
---|
190 | delete [] out_DECOD_ACK ; |
---|
191 | delete [] in_DECOD_CONTEXT_ID ; |
---|
192 | delete [] in_DECOD_ADDRESS_SRC ; |
---|
193 | delete [] in_DECOD_ADDRESS_DEST ; |
---|
194 | delete [] in_DECOD_CONDITION ; |
---|
195 | delete [] in_DECOD_LAST_TAKE ; |
---|
196 | delete [] in_DECOD_MISS_PREDICTION ; |
---|
197 | |
---|
198 | delete [] in_UPDATE_VAL ; |
---|
199 | delete [] out_UPDATE_ACK ; |
---|
200 | delete [] in_UPDATE_CONTEXT_ID ; |
---|
201 | delete [] in_UPDATE_ADDRESS_SRC ; |
---|
202 | delete [] in_UPDATE_ADDRESS_DEST ; |
---|
203 | delete [] in_UPDATE_CONDITION ; |
---|
204 | delete [] in_UPDATE_LAST_TAKE ; |
---|
205 | delete [] in_UPDATE_MISS_PREDICTION; |
---|
206 | #endif |
---|
207 | |
---|
208 | delete _Branch_Target_Buffer; |
---|
209 | #ifdef STATISTICS |
---|
210 | delete _parameters_statistics; |
---|
211 | #endif |
---|
212 | } |
---|