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