[78] | 1 | /* |
---|
| 2 | * $Id: test.cpp 81 2008-04-15 18:40:01Z rosiere $ |
---|
| 3 | * |
---|
| 4 | * [ Description ] |
---|
| 5 | * |
---|
| 6 | * Test |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #include "Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Direction/Direction_Glue/SelfTest/include/test.h" |
---|
| 10 | #include "Common/include/Test.h" |
---|
| 11 | #include "Common/include/BitManipulation.h" |
---|
| 12 | #include "Behavioural/include/Allocation.h" |
---|
| 13 | |
---|
| 14 | #define NB_ITERATION 1024 |
---|
| 15 | #define CYCLE_MAX (128*NB_ITERATION) |
---|
| 16 | |
---|
| 17 | #define LABEL(str...) \ |
---|
| 18 | { \ |
---|
| 19 | msg (_("{%d} "),static_cast<uint32_t>(sc_simulation_time())); \ |
---|
| 20 | msg (str); \ |
---|
| 21 | msg (_("\n")); \ |
---|
| 22 | } while(0) |
---|
| 23 | |
---|
| 24 | #define SC_START(cycle_offset) \ |
---|
| 25 | do \ |
---|
| 26 | { \ |
---|
| 27 | /*cout << "SC_START (begin)" << endl;*/ \ |
---|
| 28 | \ |
---|
| 29 | uint32_t cycle_current = static_cast<uint32_t>(sc_simulation_time()); \ |
---|
| 30 | if (cycle_offset != 0) \ |
---|
| 31 | { \ |
---|
| 32 | cout << "##########[ cycle "<< cycle_current+cycle_offset << " ]" << endl; \ |
---|
| 33 | } \ |
---|
| 34 | \ |
---|
| 35 | if (cycle_current > CYCLE_MAX) \ |
---|
| 36 | { \ |
---|
| 37 | TEST_KO("Maximal cycles Reached"); \ |
---|
| 38 | } \ |
---|
| 39 | \ |
---|
| 40 | sc_start(cycle_offset); \ |
---|
| 41 | \ |
---|
| 42 | /*cout << "SC_START (end )" << endl;*/ \ |
---|
| 43 | } while(0) |
---|
| 44 | |
---|
| 45 | void test (string name, |
---|
| 46 | morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::direction::direction_glue::Parameters * _param) |
---|
| 47 | { |
---|
| 48 | msg(_("<%s> : Simulation SystemC.\n"),name.c_str()); |
---|
| 49 | |
---|
| 50 | #ifdef STATISTICS |
---|
| 51 | morpheo::behavioural::Parameters_Statistics * _parameters_statistics = new morpheo::behavioural::Parameters_Statistics (5,50); |
---|
| 52 | #endif |
---|
| 53 | |
---|
| 54 | Direction_Glue * _Direction_Glue = new Direction_Glue (name.c_str(), |
---|
| 55 | #ifdef STATISTICS |
---|
| 56 | _parameters_statistics, |
---|
| 57 | #endif |
---|
| 58 | _param); |
---|
| 59 | |
---|
| 60 | #ifdef SYSTEMC |
---|
| 61 | /********************************************************************* |
---|
| 62 | * Déclarations des signaux |
---|
| 63 | *********************************************************************/ |
---|
| 64 | string rename; |
---|
| 65 | |
---|
| 66 | sc_clock * in_CLOCK = new sc_clock ("clock", 1.0, 0.5); |
---|
| 67 | sc_signal<Tcontrol_t> * in_NRESET = new sc_signal<Tcontrol_t> ("NRESET"); |
---|
| 68 | |
---|
| 69 | ALLOC1_SC_SIGNAL( in_PREDICT_VAL ," in_PREDICT_VAL ",Tcontrol_t,_param->_nb_inst_predict); |
---|
| 70 | ALLOC1_SC_SIGNAL(out_PREDICT_ACK ,"out_PREDICT_ACK ",Tcontrol_t,_param->_nb_inst_predict); |
---|
| 71 | ALLOC1_SC_SIGNAL( in_PREDICT_ADDRESS_SRC ," in_PREDICT_ADDRESS_SRC ",Taddress_t,_param->_nb_inst_predict); |
---|
| 72 | ALLOC1_SC_SIGNAL( in_PREDICT_STATIC ," in_PREDICT_STATIC ",Tcontrol_t,_param->_nb_inst_predict); |
---|
| 73 | ALLOC1_SC_SIGNAL( in_PREDICT_LAST_TAKE ," in_PREDICT_LAST_TAKE ",Tcontrol_t,_param->_nb_inst_predict); |
---|
| 74 | ALLOC1_SC_SIGNAL(out_PREDICT_HISTORY ,"out_PREDICT_HISTORY ",Thistory_t,_param->_nb_inst_predict); |
---|
| 75 | ALLOC1_SC_SIGNAL(out_PREDICT_DIRECTION ,"out_PREDICT_DIRECTION ",Tcontrol_t,_param->_nb_inst_predict); |
---|
| 76 | ALLOC1_SC_SIGNAL(out_PREDICT_PREDICTOR_VAL ,"out_PREDICT_PREDICTOR_VAL ",Tcontrol_t,_param->_nb_inst_predict); |
---|
| 77 | ALLOC1_SC_SIGNAL( in_PREDICT_PREDICTOR_ACK ," in_PREDICT_PREDICTOR_ACK ",Tcontrol_t,_param->_nb_inst_predict); |
---|
| 78 | ALLOC1_SC_SIGNAL(out_PREDICT_PREDICTOR_ADDRESS_SRC,"out_PREDICT_PREDICTOR_ADDRESS_SRC",Taddress_t,_param->_nb_inst_predict); |
---|
| 79 | ALLOC1_SC_SIGNAL( in_PREDICT_PREDICTOR_HISTORY ," in_PREDICT_PREDICTOR_HISTORY ",Thistory_t,_param->_nb_inst_predict); |
---|
| 80 | ALLOC1_SC_SIGNAL( in_PREDICT_PREDICTOR_DIRECTION ," in_PREDICT_PREDICTOR_DIRECTION ",Tcontrol_t,_param->_nb_inst_predict); |
---|
| 81 | ALLOC1_SC_SIGNAL( in_UPDATE_VAL ," in_UPDATE_VAL ",Tcontrol_t,_param->_nb_inst_update); |
---|
| 82 | ALLOC1_SC_SIGNAL(out_UPDATE_ACK ,"out_UPDATE_ACK ",Tcontrol_t,_param->_nb_inst_update); |
---|
| 83 | ALLOC1_SC_SIGNAL( in_UPDATE_ADDRESS ," in_UPDATE_ADDRESS ",Taddress_t,_param->_nb_inst_update); |
---|
| 84 | ALLOC1_SC_SIGNAL( in_UPDATE_HISTORY ," in_UPDATE_HISTORY ",Thistory_t,_param->_nb_inst_update); |
---|
| 85 | ALLOC1_SC_SIGNAL( in_UPDATE_DIRECTION ," in_UPDATE_DIRECTION ",Tcontrol_t,_param->_nb_inst_update); |
---|
| 86 | ALLOC1_SC_SIGNAL(out_UPDATE_PREDICTOR_VAL ,"out_UPDATE_PREDICTOR_VAL ",Tcontrol_t,_param->_nb_inst_update); |
---|
| 87 | ALLOC1_SC_SIGNAL( in_UPDATE_PREDICTOR_ACK ," in_UPDATE_PREDICTOR_ACK ",Tcontrol_t,_param->_nb_inst_update); |
---|
| 88 | ALLOC1_SC_SIGNAL(out_UPDATE_PREDICTOR_ADDRESS ,"out_UPDATE_PREDICTOR_ADDRESS ",Taddress_t,_param->_nb_inst_update); |
---|
| 89 | ALLOC1_SC_SIGNAL(out_UPDATE_PREDICTOR_HISTORY ,"out_UPDATE_PREDICTOR_HISTORY ",Thistory_t,_param->_nb_inst_update); |
---|
| 90 | ALLOC1_SC_SIGNAL(out_UPDATE_PREDICTOR_DIRECTION ,"out_UPDATE_PREDICTOR_DIRECTION ",Tcontrol_t,_param->_nb_inst_update); |
---|
| 91 | |
---|
| 92 | /******************************************************** |
---|
| 93 | * Instanciation |
---|
| 94 | ********************************************************/ |
---|
| 95 | |
---|
| 96 | msg(_("<%s> : Instanciation of _Direction_Glue.\n"),name.c_str()); |
---|
| 97 | |
---|
| 98 | (*(_Direction_Glue->in_CLOCK)) (*(in_CLOCK)); |
---|
| 99 | (*(_Direction_Glue->in_NRESET)) (*(in_NRESET)); |
---|
| 100 | |
---|
| 101 | INSTANCE1_SC_SIGNAL(_Direction_Glue, in_PREDICT_VAL ,_param->_nb_inst_predict); |
---|
| 102 | INSTANCE1_SC_SIGNAL(_Direction_Glue,out_PREDICT_ACK ,_param->_nb_inst_predict); |
---|
| 103 | INSTANCE1_SC_SIGNAL(_Direction_Glue, in_PREDICT_ADDRESS_SRC ,_param->_nb_inst_predict); |
---|
| 104 | INSTANCE1_SC_SIGNAL(_Direction_Glue, in_PREDICT_STATIC ,_param->_nb_inst_predict); |
---|
| 105 | INSTANCE1_SC_SIGNAL(_Direction_Glue, in_PREDICT_LAST_TAKE ,_param->_nb_inst_predict); |
---|
| 106 | if (_param->_have_port_history) |
---|
| 107 | INSTANCE1_SC_SIGNAL(_Direction_Glue,out_PREDICT_HISTORY ,_param->_nb_inst_predict); |
---|
| 108 | INSTANCE1_SC_SIGNAL(_Direction_Glue,out_PREDICT_DIRECTION ,_param->_nb_inst_predict); |
---|
| 109 | if (_param->_have_component_meta_predictor) |
---|
| 110 | { |
---|
| 111 | INSTANCE1_SC_SIGNAL(_Direction_Glue,out_PREDICT_PREDICTOR_VAL ,_param->_nb_inst_predict); |
---|
| 112 | INSTANCE1_SC_SIGNAL(_Direction_Glue, in_PREDICT_PREDICTOR_ACK ,_param->_nb_inst_predict); |
---|
| 113 | INSTANCE1_SC_SIGNAL(_Direction_Glue,out_PREDICT_PREDICTOR_ADDRESS_SRC,_param->_nb_inst_predict); |
---|
| 114 | if (_param->_have_port_history) |
---|
| 115 | INSTANCE1_SC_SIGNAL(_Direction_Glue, in_PREDICT_PREDICTOR_HISTORY ,_param->_nb_inst_predict); |
---|
| 116 | INSTANCE1_SC_SIGNAL(_Direction_Glue, in_PREDICT_PREDICTOR_DIRECTION ,_param->_nb_inst_predict); |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | INSTANCE1_SC_SIGNAL(_Direction_Glue, in_UPDATE_VAL ,_param->_nb_inst_update ); |
---|
| 120 | INSTANCE1_SC_SIGNAL(_Direction_Glue,out_UPDATE_ACK ,_param->_nb_inst_update ); |
---|
| 121 | INSTANCE1_SC_SIGNAL(_Direction_Glue, in_UPDATE_ADDRESS ,_param->_nb_inst_update ); |
---|
| 122 | if (_param->_have_port_history) |
---|
| 123 | INSTANCE1_SC_SIGNAL(_Direction_Glue, in_UPDATE_HISTORY ,_param->_nb_inst_update ); |
---|
| 124 | INSTANCE1_SC_SIGNAL(_Direction_Glue, in_UPDATE_DIRECTION ,_param->_nb_inst_update ); |
---|
| 125 | if (_param->_have_component_meta_predictor) |
---|
| 126 | { |
---|
| 127 | INSTANCE1_SC_SIGNAL(_Direction_Glue,out_UPDATE_PREDICTOR_VAL ,_param->_nb_inst_update ); |
---|
| 128 | INSTANCE1_SC_SIGNAL(_Direction_Glue, in_UPDATE_PREDICTOR_ACK ,_param->_nb_inst_update ); |
---|
| 129 | INSTANCE1_SC_SIGNAL(_Direction_Glue,out_UPDATE_PREDICTOR_ADDRESS ,_param->_nb_inst_update ); |
---|
| 130 | if (_param->_have_port_history) |
---|
| 131 | INSTANCE1_SC_SIGNAL(_Direction_Glue,out_UPDATE_PREDICTOR_HISTORY ,_param->_nb_inst_update ); |
---|
| 132 | INSTANCE1_SC_SIGNAL(_Direction_Glue,out_UPDATE_PREDICTOR_DIRECTION ,_param->_nb_inst_update ); |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | msg(_("<%s> : Start Simulation ............\n"),name.c_str()); |
---|
| 136 | |
---|
| 137 | Time * _time = new Time(); |
---|
| 138 | |
---|
| 139 | /******************************************************** |
---|
| 140 | * Simulation - Begin |
---|
| 141 | ********************************************************/ |
---|
| 142 | |
---|
| 143 | // Initialisation |
---|
| 144 | |
---|
| 145 | const uint32_t seed = 0; |
---|
| 146 | //const uint32_t seed = static_cast<uint32_t>(time(NULL)); |
---|
| 147 | |
---|
| 148 | srand(seed); |
---|
| 149 | |
---|
| 150 | SC_START(0); |
---|
| 151 | LABEL("Initialisation"); |
---|
| 152 | |
---|
| 153 | LABEL("Reset"); |
---|
| 154 | in_NRESET->write(0); |
---|
| 155 | SC_START(5); |
---|
| 156 | in_NRESET->write(1); |
---|
| 157 | |
---|
| 158 | LABEL("Loop of Test"); |
---|
| 159 | |
---|
| 160 | for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++) |
---|
| 161 | { |
---|
| 162 | LABEL("Iteration %d",iteration); |
---|
| 163 | |
---|
| 164 | for (uint32_t i=0; i<_param->_nb_inst_predict; i++) |
---|
| 165 | { |
---|
| 166 | in_PREDICT_VAL [i]->write(rand()%2); |
---|
| 167 | in_PREDICT_ADDRESS_SRC [i]->write(range<Taddress_t>(rand(),_param->_size_address)); |
---|
| 168 | in_PREDICT_STATIC [i]->write(rand()%2); |
---|
| 169 | in_PREDICT_LAST_TAKE [i]->write(rand()%2); |
---|
| 170 | in_PREDICT_PREDICTOR_ACK [i]->write(rand()%2); |
---|
| 171 | in_PREDICT_PREDICTOR_HISTORY [i]->write(range<Thistory_t>(rand(),_param->_size_history)); |
---|
| 172 | in_PREDICT_PREDICTOR_DIRECTION [i]->write(rand()%2); |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | for (uint32_t i=0; i<_param->_nb_inst_update; i++) |
---|
| 176 | { |
---|
| 177 | in_UPDATE_VAL [i]->write(rand()%2); |
---|
| 178 | in_UPDATE_ADDRESS [i]->write(range<Taddress_t>(rand(),_param->_size_address)); |
---|
| 179 | in_UPDATE_HISTORY [i]->write(range<Thistory_t>(rand(),_param->_size_history)); |
---|
| 180 | in_UPDATE_DIRECTION [i]->write(rand()%2); |
---|
| 181 | in_UPDATE_PREDICTOR_ACK [i]->write(rand()%2); |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | SC_START(0); |
---|
| 185 | |
---|
| 186 | for (uint32_t i=0; i<_param->_nb_inst_predict; i++) |
---|
| 187 | { |
---|
| 188 | switch (_param->_predictor_scheme) |
---|
| 189 | { |
---|
| 190 | case PREDICTOR_NEVER_TAKE : |
---|
| 191 | { |
---|
| 192 | TEST(Tcontrol_t,out_PREDICT_ACK [i]->read(), 1); |
---|
| 193 | TEST(Tcontrol_t,out_PREDICT_DIRECTION [i]->read(), 0); |
---|
| 194 | break; |
---|
| 195 | } |
---|
| 196 | case PREDICTOR_ALWAYS_TAKE : |
---|
| 197 | { |
---|
| 198 | TEST(Tcontrol_t,out_PREDICT_ACK [i]->read(), 1); |
---|
| 199 | TEST(Tcontrol_t,out_PREDICT_DIRECTION [i]->read(), 1); |
---|
| 200 | break; |
---|
| 201 | } |
---|
| 202 | case PREDICTOR_STATIC : |
---|
| 203 | { |
---|
| 204 | TEST(Tcontrol_t,out_PREDICT_ACK [i]->read(), 1); |
---|
| 205 | TEST(Tcontrol_t,out_PREDICT_DIRECTION [i]->read(), in_PREDICT_STATIC [i]->read()); |
---|
| 206 | break; |
---|
| 207 | } |
---|
| 208 | case PREDICTOR_LAST_TAKE : |
---|
| 209 | { |
---|
| 210 | TEST(Tcontrol_t,out_PREDICT_DIRECTION [i]->read(), in_PREDICT_LAST_TAKE [i]->read()); |
---|
| 211 | break; |
---|
| 212 | } |
---|
| 213 | case PREDICTOR_COUNTER : |
---|
| 214 | case PREDICTOR_LOCAL : |
---|
| 215 | case PREDICTOR_GLOBAL : |
---|
| 216 | case PREDICTOR_META : |
---|
| 217 | case PREDICTOR_CUSTOM : |
---|
| 218 | { |
---|
| 219 | TEST(Tcontrol_t,out_PREDICT_ACK [i]->read(), in_PREDICT_PREDICTOR_ACK [i]->read()); |
---|
| 220 | TEST(Thistory_t,out_PREDICT_HISTORY [i]->read(), in_PREDICT_PREDICTOR_HISTORY [i]->read()); |
---|
| 221 | TEST(Tcontrol_t,out_PREDICT_DIRECTION [i]->read(), in_PREDICT_PREDICTOR_DIRECTION [i]->read()); |
---|
| 222 | TEST(Tcontrol_t,out_PREDICT_PREDICTOR_VAL [i]->read(), in_PREDICT_VAL [i]->read()); |
---|
| 223 | TEST(Taddress_t,out_PREDICT_PREDICTOR_ADDRESS_SRC [i]->read(), in_PREDICT_ADDRESS_SRC [i]->read()); |
---|
| 224 | |
---|
| 225 | break; |
---|
| 226 | } |
---|
| 227 | default : |
---|
| 228 | { |
---|
| 229 | break; |
---|
| 230 | } |
---|
| 231 | } |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | for (uint32_t i=0; i<_param->_nb_inst_update; i++) |
---|
| 235 | { |
---|
| 236 | |
---|
| 237 | |
---|
| 238 | switch (_param->_predictor_scheme) |
---|
| 239 | { |
---|
| 240 | case PREDICTOR_COUNTER : |
---|
| 241 | case PREDICTOR_LOCAL : |
---|
| 242 | case PREDICTOR_GLOBAL : |
---|
| 243 | case PREDICTOR_META : |
---|
| 244 | case PREDICTOR_CUSTOM : |
---|
| 245 | { |
---|
| 246 | TEST(Tcontrol_t,out_UPDATE_ACK [i]->read(), in_UPDATE_PREDICTOR_ACK [i]->read()); |
---|
| 247 | TEST(Tcontrol_t,out_UPDATE_PREDICTOR_VAL [i]->read(), in_UPDATE_VAL [i]->read()); |
---|
| 248 | TEST(Taddress_t,out_UPDATE_PREDICTOR_ADDRESS [i]->read(), in_UPDATE_ADDRESS [i]->read()); |
---|
| 249 | TEST(Thistory_t,out_UPDATE_PREDICTOR_HISTORY [i]->read(), in_UPDATE_HISTORY [i]->read()); |
---|
| 250 | TEST(Tcontrol_t,out_UPDATE_PREDICTOR_DIRECTION [i]->read(), in_UPDATE_DIRECTION [i]->read()); |
---|
| 251 | |
---|
| 252 | break; |
---|
| 253 | } |
---|
| 254 | case PREDICTOR_NEVER_TAKE : |
---|
| 255 | case PREDICTOR_ALWAYS_TAKE : |
---|
| 256 | case PREDICTOR_STATIC : |
---|
| 257 | case PREDICTOR_LAST_TAKE : |
---|
| 258 | default : |
---|
| 259 | { |
---|
| 260 | TEST(Tcontrol_t,out_UPDATE_ACK [i]->read(), 1); |
---|
| 261 | |
---|
| 262 | break; |
---|
| 263 | } |
---|
| 264 | } |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | SC_START(1); |
---|
| 268 | } |
---|
| 269 | |
---|
| 270 | /******************************************************** |
---|
| 271 | * Simulation - End |
---|
| 272 | ********************************************************/ |
---|
| 273 | |
---|
| 274 | TEST_OK ("End of Simulation"); |
---|
| 275 | delete _time; |
---|
| 276 | |
---|
| 277 | msg(_("<%s> : ............ Stop Simulation\n"),name.c_str()); |
---|
| 278 | |
---|
| 279 | delete in_CLOCK; |
---|
| 280 | delete in_NRESET; |
---|
| 281 | |
---|
| 282 | delete [] in_PREDICT_VAL ; |
---|
| 283 | delete [] out_PREDICT_ACK ; |
---|
| 284 | delete [] in_PREDICT_ADDRESS_SRC ; |
---|
| 285 | delete [] in_PREDICT_STATIC ; |
---|
| 286 | delete [] in_PREDICT_LAST_TAKE ; |
---|
| 287 | delete [] out_PREDICT_HISTORY ; |
---|
| 288 | delete [] out_PREDICT_DIRECTION ; |
---|
| 289 | delete [] out_PREDICT_PREDICTOR_VAL ; |
---|
| 290 | delete [] in_PREDICT_PREDICTOR_ACK ; |
---|
| 291 | delete [] out_PREDICT_PREDICTOR_ADDRESS_SRC; |
---|
| 292 | delete [] in_PREDICT_PREDICTOR_HISTORY ; |
---|
| 293 | delete [] in_PREDICT_PREDICTOR_DIRECTION ; |
---|
| 294 | delete [] in_UPDATE_VAL ; |
---|
| 295 | delete [] out_UPDATE_ACK ; |
---|
| 296 | delete [] in_UPDATE_ADDRESS ; |
---|
| 297 | delete [] in_UPDATE_HISTORY ; |
---|
| 298 | delete [] in_UPDATE_DIRECTION ; |
---|
| 299 | delete [] out_UPDATE_PREDICTOR_VAL ; |
---|
| 300 | delete [] in_UPDATE_PREDICTOR_ACK ; |
---|
| 301 | delete [] out_UPDATE_PREDICTOR_ADDRESS ; |
---|
| 302 | delete [] out_UPDATE_PREDICTOR_HISTORY ; |
---|
| 303 | delete [] out_UPDATE_PREDICTOR_DIRECTION ; |
---|
| 304 | #endif |
---|
| 305 | |
---|
| 306 | delete _Direction_Glue; |
---|
| 307 | #ifdef STATISTICS |
---|
| 308 | delete _parameters_statistics; |
---|
| 309 | #endif |
---|
| 310 | } |
---|