[110] | 1 | /* |
---|
| 2 | * $Id: test.cpp 112 2009-03-18 22:36:26Z rosiere $ |
---|
| 3 | * |
---|
| 4 | * [ Description ] |
---|
| 5 | * |
---|
| 6 | * Test |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #include "Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Direction/Meta_Predictor/Two_Level_Branch_Predictor/SelfTest/include/test.h" |
---|
| 10 | #include "Behavioural/include/Allocation.h" |
---|
| 11 | |
---|
| 12 | void test (string name, |
---|
| 13 | morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::direction::meta_predictor::two_level_branch_predictor::Parameters * _param) |
---|
| 14 | { |
---|
| 15 | msg(_("<%s> : Simulation SystemC.\n"),name.c_str()); |
---|
| 16 | |
---|
| 17 | if (setlocale (LC_ALL, "") == NULL) |
---|
| 18 | msg(_("setlocale ko.\n")); |
---|
| 19 | |
---|
| 20 | #ifdef STATISTICS |
---|
| 21 | morpheo::behavioural::Parameters_Statistics * _parameters_statistics = new morpheo::behavioural::Parameters_Statistics (5,CYCLE_MAX); |
---|
| 22 | #endif |
---|
| 23 | |
---|
| 24 | Tusage_t _usage = USE_ALL; |
---|
| 25 | |
---|
| 26 | // _usage = usage_unset(_usage,USE_SYSTEMC ); |
---|
| 27 | // _usage = usage_unset(_usage,USE_VHDL ); |
---|
| 28 | // _usage = usage_unset(_usage,USE_VHDL_TESTBENCH ); |
---|
| 29 | // _usage = usage_unset(_usage,USE_VHDL_TESTBENCH_ASSERT); |
---|
| 30 | // _usage = usage_unset(_usage,USE_POSITION ); |
---|
| 31 | // _usage = usage_unset(_usage,USE_STATISTICS ); |
---|
| 32 | // _usage = usage_unset(_usage,USE_INFORMATION ); |
---|
| 33 | |
---|
| 34 | Two_Level_Branch_Predictor * _Two_Level_Branch_Predictor = new Two_Level_Branch_Predictor |
---|
| 35 | (name.c_str(), |
---|
| 36 | #ifdef STATISTICS |
---|
| 37 | _parameters_statistics, |
---|
| 38 | #endif |
---|
| 39 | _param, |
---|
| 40 | _usage); |
---|
| 41 | |
---|
| 42 | #ifdef SYSTEMC |
---|
| 43 | if (usage_is_set(_usage,USE_SYSTEMC)) |
---|
| 44 | { |
---|
| 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"); |
---|
[111] | 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 ," in_PREDICT_ADDRESS ",Taddress_t,_param->_nb_inst_predict); |
---|
| 56 | ALLOC1_SC_SIGNAL(out_PREDICT_DIRECTION ,"out_PREDICT_DIRECTION ",Tcontrol_t,_param->_nb_inst_predict); |
---|
| 57 | ALLOC1_SC_SIGNAL(out_PREDICT_HISTORY ,"out_PREDICT_HISTORY ",Thistory_t,_param->_nb_inst_predict); |
---|
| 58 | ALLOC1_SC_SIGNAL( in_PREDICT_DIRECTION_VAL," in_PREDICT_DIRECTION_VAL",Tcontrol_t,_param->_nb_inst_predict); |
---|
| 59 | ALLOC1_SC_SIGNAL( in_PREDICT_DIRECTION ," in_PREDICT_DIRECTION ",Tcontrol_t,_param->_nb_inst_predict); |
---|
[110] | 60 | |
---|
[111] | 61 | ALLOC1_SC_SIGNAL( in_UPDATE_VAL ," in_UPDATE_VAL ",Tcontrol_t,_param->_nb_inst_update); |
---|
| 62 | ALLOC1_SC_SIGNAL(out_UPDATE_ACK ,"out_UPDATE_ACK ",Tcontrol_t,_param->_nb_inst_update); |
---|
| 63 | ALLOC1_SC_SIGNAL( in_UPDATE_ADDRESS ," in_UPDATE_ADDRESS ",Taddress_t,_param->_nb_inst_update); |
---|
| 64 | ALLOC1_SC_SIGNAL( in_UPDATE_HISTORY ," in_UPDATE_HISTORY ",Thistory_t,_param->_nb_inst_update); |
---|
[112] | 65 | ALLOC1_SC_SIGNAL( in_UPDATE_HISTORY_VAL ," in_UPDATE_HISTORY_VAL ",Tcontrol_t,_param->_nb_inst_update); |
---|
[111] | 66 | ALLOC1_SC_SIGNAL( in_UPDATE_DIRECTION ," in_UPDATE_DIRECTION ",Tcontrol_t,_param->_nb_inst_update); |
---|
| 67 | ALLOC1_SC_SIGNAL( in_UPDATE_MISS ," in_UPDATE_MISS ",Tcontrol_t,_param->_nb_inst_update); |
---|
| 68 | |
---|
[110] | 69 | /******************************************************** |
---|
| 70 | * Instanciation |
---|
| 71 | ********************************************************/ |
---|
| 72 | |
---|
| 73 | msg(_("<%s> : Instanciation of _Two_Level_Branch_Predictor.\n"),name.c_str()); |
---|
| 74 | |
---|
| 75 | (*(_Two_Level_Branch_Predictor->in_CLOCK)) (*(in_CLOCK)); |
---|
| 76 | (*(_Two_Level_Branch_Predictor->in_NRESET)) (*(in_NRESET)); |
---|
| 77 | |
---|
[111] | 78 | INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor, in_PREDICT_VAL ,_param->_nb_inst_predict); |
---|
| 79 | INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor,out_PREDICT_ACK ,_param->_nb_inst_predict); |
---|
| 80 | INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor, in_PREDICT_ADDRESS ,_param->_nb_inst_predict); |
---|
| 81 | INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor,out_PREDICT_DIRECTION ,_param->_nb_inst_predict); |
---|
| 82 | INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor,out_PREDICT_HISTORY ,_param->_nb_inst_predict); |
---|
| 83 | if (_param->_update_on_prediction) |
---|
| 84 | { |
---|
| 85 | INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor, in_PREDICT_DIRECTION_VAL,_param->_nb_inst_predict); |
---|
| 86 | INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor, in_PREDICT_DIRECTION ,_param->_nb_inst_predict); |
---|
| 87 | } |
---|
[110] | 88 | |
---|
[111] | 89 | INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor, in_UPDATE_VAL ,_param->_nb_inst_update); |
---|
| 90 | INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor,out_UPDATE_ACK ,_param->_nb_inst_update); |
---|
| 91 | INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor, in_UPDATE_ADDRESS ,_param->_nb_inst_update); |
---|
| 92 | INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor, in_UPDATE_HISTORY ,_param->_nb_inst_update); |
---|
[112] | 93 | INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor, in_UPDATE_HISTORY_VAL ,_param->_nb_inst_update); |
---|
[111] | 94 | INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor, in_UPDATE_DIRECTION ,_param->_nb_inst_update); |
---|
| 95 | if (_param->_update_on_prediction) |
---|
| 96 | INSTANCE1_SC_SIGNAL(_Two_Level_Branch_Predictor, in_UPDATE_MISS ,_param->_nb_inst_update); |
---|
| 97 | |
---|
[110] | 98 | msg(_("<%s> : Start Simulation ............\n"),name.c_str()); |
---|
| 99 | |
---|
| 100 | Time * _time = new Time(); |
---|
| 101 | |
---|
| 102 | /******************************************************** |
---|
| 103 | * Simulation - Begin |
---|
| 104 | ********************************************************/ |
---|
| 105 | |
---|
| 106 | // Initialisation |
---|
| 107 | |
---|
| 108 | const uint32_t seed = 0; |
---|
| 109 | //const uint32_t seed = static_cast<uint32_t>(time(NULL)); |
---|
| 110 | |
---|
| 111 | srand(seed); |
---|
| 112 | |
---|
[111] | 113 | const int32_t percent_transaction_predict = 75; |
---|
| 114 | const int32_t percent_transaction_update = 75; |
---|
| 115 | |
---|
[110] | 116 | SC_START(0); |
---|
| 117 | LABEL("Initialisation"); |
---|
| 118 | |
---|
[111] | 119 | for (uint32_t i=0; i<_param->_nb_inst_predict; ++i) |
---|
| 120 | in_PREDICT_VAL [i]->write(0); |
---|
| 121 | for (uint32_t i=0; i<_param->_nb_inst_update; ++i) |
---|
| 122 | in_UPDATE_VAL [i]->write(0); |
---|
| 123 | |
---|
[110] | 124 | LABEL("Reset"); |
---|
| 125 | in_NRESET->write(0); |
---|
| 126 | SC_START(5); |
---|
| 127 | in_NRESET->write(1); |
---|
| 128 | |
---|
| 129 | LABEL("Loop of Test"); |
---|
[111] | 130 | |
---|
| 131 | Thistory_t bht; |
---|
| 132 | Thistory_t pht [_param->_pht_size_bank]; |
---|
| 133 | |
---|
[110] | 134 | for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++) |
---|
| 135 | { |
---|
| 136 | LABEL("Iteration %d",iteration); |
---|
| 137 | |
---|
[111] | 138 | uint32_t bht_num_reg = (_param->_have_bht)?(rand()%_param->_bht_nb_shifter):0; |
---|
| 139 | uint32_t pht_num_bank = (_param->_have_pht)?(rand()%_param->_pht_nb_bank ):0; |
---|
| 140 | |
---|
| 141 | LABEL(" * bht_num_reg : %d",bht_num_reg ); |
---|
| 142 | LABEL(" * pht_num_bank : %d",pht_num_bank); |
---|
| 143 | |
---|
| 144 | { |
---|
| 145 | LABEL("Init BHT and PHT"); |
---|
| 146 | |
---|
| 147 | bht = 0; |
---|
| 148 | for (uint32_t i=0; i<_param->_pht_size_bank; ++i) |
---|
| 149 | pht [i] = 0; |
---|
| 150 | |
---|
| 151 | uint32_t port = rand()%_param->_nb_inst_update; |
---|
| 152 | |
---|
| 153 | if (_param->_have_bht) |
---|
| 154 | { |
---|
| 155 | bool find = false; |
---|
| 156 | while (not find) |
---|
| 157 | { |
---|
| 158 | bool val = ((rand()%2)<percent_transaction_update); |
---|
[112] | 159 | in_UPDATE_VAL [port]->write(val); |
---|
| 160 | in_UPDATE_DIRECTION [port]->write(0); |
---|
[111] | 161 | |
---|
| 162 | if (_param->_update_on_prediction) |
---|
[112] | 163 | in_UPDATE_MISS [port]->write(1); // miss |
---|
| 164 | in_UPDATE_HISTORY [port]->write(0); |
---|
| 165 | in_UPDATE_HISTORY_VAL [port]->write(0); |
---|
| 166 | in_UPDATE_ADDRESS [port]->write(bht_num_reg); |
---|
[111] | 167 | |
---|
| 168 | SC_START(0); |
---|
| 169 | |
---|
| 170 | if (val and out_UPDATE_ACK [port]->read()) |
---|
| 171 | { |
---|
| 172 | LABEL("UPDATE[%d] - Transaction accepted",port); |
---|
| 173 | find = true; |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | SC_START(1); |
---|
| 177 | } |
---|
| 178 | in_UPDATE_VAL [port]->write(0); |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | if (_param->_have_pht) |
---|
| 182 | { |
---|
| 183 | for (uint32_t i=0; i<_param->_pht_size_bank; ++i) |
---|
| 184 | { |
---|
| 185 | bool find = false; |
---|
| 186 | |
---|
| 187 | while (not find) |
---|
| 188 | { |
---|
| 189 | bool val = ((rand()%2)<percent_transaction_update); |
---|
[112] | 190 | in_UPDATE_VAL [port]->write(val); |
---|
| 191 | in_UPDATE_DIRECTION [port]->write(0); |
---|
[111] | 192 | |
---|
| 193 | if (_param->_update_on_prediction) |
---|
[112] | 194 | in_UPDATE_MISS [port]->write(1); // miss |
---|
| 195 | in_UPDATE_HISTORY [port]->write(i<<_param->_bht_history_rshift); |
---|
| 196 | in_UPDATE_HISTORY_VAL [port]->write(1); |
---|
| 197 | in_UPDATE_ADDRESS [port]->write(pht_num_bank<<_param->_pht_address_bank_rshift); |
---|
[111] | 198 | |
---|
| 199 | SC_START(0); |
---|
| 200 | |
---|
| 201 | if (val and out_UPDATE_ACK [port]->read()) |
---|
| 202 | { |
---|
| 203 | LABEL("UPDATE[%d] - Transaction accepted",port); |
---|
| 204 | find = true; |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | SC_START(1); |
---|
| 208 | } |
---|
| 209 | in_UPDATE_VAL [port]->write(0); |
---|
| 210 | } |
---|
| 211 | } |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | // if (1) |
---|
| 215 | // { |
---|
| 216 | // LABEL("Saturation all PHT"); |
---|
| 217 | |
---|
| 218 | // } |
---|
| 219 | |
---|
[110] | 220 | SC_START(1); |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | /******************************************************** |
---|
| 224 | * Simulation - End |
---|
| 225 | ********************************************************/ |
---|
| 226 | |
---|
| 227 | TEST_OK ("End of Simulation"); |
---|
| 228 | delete _time; |
---|
| 229 | |
---|
| 230 | msg(_("<%s> : ............ Stop Simulation\n"),name.c_str()); |
---|
| 231 | |
---|
| 232 | delete in_CLOCK; |
---|
| 233 | delete in_NRESET; |
---|
[111] | 234 | |
---|
| 235 | DELETE1_SC_SIGNAL( in_PREDICT_VAL ,_param->_nb_inst_predict); |
---|
| 236 | DELETE1_SC_SIGNAL(out_PREDICT_ACK ,_param->_nb_inst_predict); |
---|
| 237 | DELETE1_SC_SIGNAL( in_PREDICT_ADDRESS ,_param->_nb_inst_predict); |
---|
| 238 | DELETE1_SC_SIGNAL(out_PREDICT_DIRECTION ,_param->_nb_inst_predict); |
---|
| 239 | DELETE1_SC_SIGNAL(out_PREDICT_HISTORY ,_param->_nb_inst_predict); |
---|
| 240 | DELETE1_SC_SIGNAL( in_PREDICT_DIRECTION_VAL,_param->_nb_inst_predict); |
---|
| 241 | DELETE1_SC_SIGNAL( in_PREDICT_DIRECTION ,_param->_nb_inst_predict); |
---|
| 242 | |
---|
| 243 | DELETE1_SC_SIGNAL( in_UPDATE_VAL ,_param->_nb_inst_update); |
---|
| 244 | DELETE1_SC_SIGNAL(out_UPDATE_ACK ,_param->_nb_inst_update); |
---|
| 245 | DELETE1_SC_SIGNAL( in_UPDATE_ADDRESS ,_param->_nb_inst_update); |
---|
| 246 | DELETE1_SC_SIGNAL( in_UPDATE_HISTORY ,_param->_nb_inst_update); |
---|
[112] | 247 | DELETE1_SC_SIGNAL( in_UPDATE_HISTORY_VAL ,_param->_nb_inst_update); |
---|
[111] | 248 | DELETE1_SC_SIGNAL( in_UPDATE_DIRECTION ,_param->_nb_inst_update); |
---|
| 249 | DELETE1_SC_SIGNAL( in_UPDATE_MISS ,_param->_nb_inst_update); |
---|
[110] | 250 | } |
---|
| 251 | #endif |
---|
| 252 | |
---|
| 253 | delete _Two_Level_Branch_Predictor; |
---|
| 254 | #ifdef STATISTICS |
---|
| 255 | delete _parameters_statistics; |
---|
| 256 | #endif |
---|
| 257 | } |
---|