[2] | 1 | /* |
---|
| 2 | * $Id$ |
---|
| 3 | * |
---|
| 4 | * [ Description ] |
---|
| 5 | * |
---|
| 6 | * Test |
---|
| 7 | */ |
---|
| 8 | |
---|
[3] | 9 | #define NB_ITERATION 512 |
---|
[2] | 10 | |
---|
| 11 | #include "Behavioural/Stage_1_Ifetch/Predictor/Meta_Predictor/Two_Level_Branch_Predictor/SelfTest/include/test.h" |
---|
| 12 | #include "Include/Test.h" |
---|
[3] | 13 | #include "Include/BitManipulation.h" |
---|
[2] | 14 | void test (string name, |
---|
| 15 | morpheo::behavioural::stage_1_ifetch::predictor::meta_predictor::two_level_branch_predictor::Parameters param) |
---|
| 16 | { |
---|
| 17 | cout << "<" << name << "> : Simulation SystemC" << endl; |
---|
| 18 | |
---|
| 19 | Two_Level_Branch_Predictor * _Two_Level_Branch_Predictor = new Two_Level_Branch_Predictor (name.c_str(), |
---|
| 20 | #ifdef STATISTICS |
---|
| 21 | morpheo::behavioural::Parameters_Statistics(5,50), |
---|
| 22 | #endif |
---|
| 23 | param); |
---|
| 24 | |
---|
| 25 | #ifdef SYSTEMC |
---|
| 26 | |
---|
| 27 | /********************************************************************* |
---|
| 28 | * Déclarations des signaux |
---|
| 29 | *********************************************************************/ |
---|
[3] | 30 | sc_clock * CLOCK; |
---|
[15] | 31 | sc_signal<Tcontrol_t> * NRESET; |
---|
[2] | 32 | |
---|
| 33 | sc_signal<Tcontrol_t> * PREDICT_VAL [param._nb_prediction]; |
---|
| 34 | sc_signal<Tcontrol_t> * PREDICT_ACK [param._nb_prediction]; |
---|
| 35 | sc_signal<Taddress_t> * PREDICT_ADDRESS [param._nb_prediction]; |
---|
| 36 | sc_signal<Tbht_history_t> * PREDICT_BHT_HISTORY [param._nb_prediction]; |
---|
| 37 | sc_signal<Tpht_history_t> * PREDICT_PHT_HISTORY [param._nb_prediction]; |
---|
| 38 | |
---|
| 39 | sc_signal<Tcontrol_t> * BRANCH_COMPLETE_VAL [param._nb_branch_complete]; |
---|
| 40 | sc_signal<Tcontrol_t> * BRANCH_COMPLETE_ACK [param._nb_branch_complete]; |
---|
| 41 | sc_signal<Taddress_t> * BRANCH_COMPLETE_ADDRESS [param._nb_branch_complete]; |
---|
| 42 | sc_signal<Tbht_history_t> * BRANCH_COMPLETE_BHT_HISTORY [param._nb_branch_complete]; |
---|
| 43 | sc_signal<Tpht_history_t> * BRANCH_COMPLETE_PHT_HISTORY [param._nb_branch_complete]; |
---|
[3] | 44 | sc_signal<Tcontrol_t> * BRANCH_COMPLETE_DIRECTION [param._nb_branch_complete]; |
---|
[2] | 45 | |
---|
| 46 | // Rename signal |
---|
| 47 | |
---|
| 48 | string rename; |
---|
| 49 | |
---|
[15] | 50 | CLOCK = new sc_clock ("clock", 1.0, 0.5); |
---|
| 51 | NRESET = new sc_signal<Tcontrol_t> ("NRESET"); |
---|
[2] | 52 | |
---|
| 53 | for (uint32_t i=0; i<param._nb_prediction; i++) |
---|
| 54 | { |
---|
| 55 | rename = "PREDICT_VAL_" +toString(i); |
---|
| 56 | PREDICT_VAL [i] = new sc_signal<Tcontrol_t> (rename.c_str()); |
---|
| 57 | rename = "PREDICT_ACK_" +toString(i); |
---|
| 58 | PREDICT_ACK [i] = new sc_signal<Tcontrol_t> (rename.c_str()); |
---|
| 59 | rename = "PREDICT_ADDRESS_" +toString(i); |
---|
| 60 | PREDICT_ADDRESS [i] = new sc_signal<Taddress_t> (rename.c_str()); |
---|
| 61 | rename = "PREDICT_BHT_HISTORY_"+toString(i); |
---|
| 62 | PREDICT_BHT_HISTORY [i] = new sc_signal<Tbht_history_t> (rename.c_str()); |
---|
| 63 | rename = "PREDICT_PHT_HISTORY_"+toString(i); |
---|
| 64 | PREDICT_PHT_HISTORY [i] = new sc_signal<Tpht_history_t> (rename.c_str()); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | for (uint32_t i=0; i<param._nb_branch_complete; i++) |
---|
| 68 | { |
---|
| 69 | rename = "BRANCH_COMPLETE_VAL_" +toString(i); |
---|
| 70 | BRANCH_COMPLETE_VAL [i] = new sc_signal<Tcontrol_t> (rename.c_str()); |
---|
| 71 | rename = "BRANCH_COMPLETE_ACK_" +toString(i); |
---|
| 72 | BRANCH_COMPLETE_ACK [i] = new sc_signal<Tcontrol_t> (rename.c_str()); |
---|
| 73 | rename = "BRANCH_COMPLETE_ADDRESS_" +toString(i); |
---|
| 74 | BRANCH_COMPLETE_ADDRESS [i] = new sc_signal<Taddress_t> (rename.c_str()); |
---|
| 75 | rename = "BRANCH_COMPLETE_BHT_HISTORY_"+toString(i); |
---|
| 76 | BRANCH_COMPLETE_BHT_HISTORY [i] = new sc_signal<Tbht_history_t> (rename.c_str()); |
---|
| 77 | rename = "BRANCH_COMPLETE_PHT_HISTORY_"+toString(i); |
---|
| 78 | BRANCH_COMPLETE_PHT_HISTORY [i] = new sc_signal<Tpht_history_t> (rename.c_str()); |
---|
[3] | 79 | rename = "BRANCH_COMPLETE_DIRECTION_" +toString(i); |
---|
| 80 | BRANCH_COMPLETE_DIRECTION [i] = new sc_signal<Tcontrol_t> (rename.c_str()); |
---|
[2] | 81 | } |
---|
| 82 | |
---|
| 83 | /******************************************************** |
---|
| 84 | * Instanciation |
---|
| 85 | ********************************************************/ |
---|
| 86 | |
---|
| 87 | cout << "<" << name << "> Instanciation of _Two_Level_Branch_Predictor" << endl; |
---|
| 88 | |
---|
[15] | 89 | (*(_Two_Level_Branch_Predictor->in_CLOCK )) (*(CLOCK )); |
---|
| 90 | (*(_Two_Level_Branch_Predictor->in_NRESET)) (*(NRESET)); |
---|
[3] | 91 | |
---|
| 92 | for (uint32_t i=0; i<param._nb_prediction; i++) |
---|
| 93 | { |
---|
| 94 | (*(_Two_Level_Branch_Predictor-> in_PREDICT_VAL [i])) (*(PREDICT_VAL [i])); |
---|
| 95 | (*(_Two_Level_Branch_Predictor->out_PREDICT_ACK [i])) (*(PREDICT_ACK [i])); |
---|
| 96 | (*(_Two_Level_Branch_Predictor-> in_PREDICT_ADDRESS [i])) (*(PREDICT_ADDRESS [i])); |
---|
| 97 | if (param._have_bht) |
---|
| 98 | (*(_Two_Level_Branch_Predictor->out_PREDICT_BHT_HISTORY [i])) (*(PREDICT_BHT_HISTORY [i])); |
---|
| 99 | if (param._have_pht) |
---|
| 100 | (*(_Two_Level_Branch_Predictor->out_PREDICT_PHT_HISTORY [i])) (*(PREDICT_PHT_HISTORY [i])); |
---|
| 101 | } |
---|
[2] | 102 | |
---|
| 103 | for (uint32_t i=0; i<param._nb_branch_complete; i++) |
---|
| 104 | { |
---|
| 105 | (*(_Two_Level_Branch_Predictor-> in_BRANCH_COMPLETE_VAL [i])) (*(BRANCH_COMPLETE_VAL [i])); |
---|
| 106 | (*(_Two_Level_Branch_Predictor->out_BRANCH_COMPLETE_ACK [i])) (*(BRANCH_COMPLETE_ACK [i])); |
---|
| 107 | (*(_Two_Level_Branch_Predictor-> in_BRANCH_COMPLETE_ADDRESS [i])) (*(BRANCH_COMPLETE_ADDRESS [i])); |
---|
| 108 | if (param._have_bht) |
---|
| 109 | (*(_Two_Level_Branch_Predictor-> in_BRANCH_COMPLETE_BHT_HISTORY [i])) (*(BRANCH_COMPLETE_BHT_HISTORY [i])); |
---|
[3] | 110 | if (param._have_pht) |
---|
[2] | 111 | (*(_Two_Level_Branch_Predictor-> in_BRANCH_COMPLETE_PHT_HISTORY [i])) (*(BRANCH_COMPLETE_PHT_HISTORY [i])); |
---|
[3] | 112 | (*(_Two_Level_Branch_Predictor-> in_BRANCH_COMPLETE_DIRECTION [i])) (*(BRANCH_COMPLETE_DIRECTION [i])); |
---|
[2] | 113 | } |
---|
| 114 | |
---|
| 115 | /******************************************************** |
---|
| 116 | * Simulation - Begin |
---|
| 117 | ********************************************************/ |
---|
| 118 | |
---|
| 119 | cout << "<" << name << "> Start Simulation ............" << endl; |
---|
| 120 | // Initialisation |
---|
| 121 | |
---|
| 122 | const uint32_t seed = 0; |
---|
| 123 | //const uint32_t seed = static_cast<uint32_t>(time(NULL)); |
---|
| 124 | |
---|
| 125 | srand(seed); |
---|
| 126 | |
---|
[3] | 127 | const uint32_t num_port_predict = rand()%param._nb_prediction; |
---|
| 128 | const uint32_t num_port_branch_complete = rand()%param._nb_branch_complete; |
---|
| 129 | const Taddress_t address = rand()%param._size_address; |
---|
| 130 | Tcontrol_t direction; |
---|
| 131 | |
---|
[2] | 132 | sc_start(0); |
---|
| 133 | |
---|
| 134 | for (uint32_t i=0; i<param._nb_prediction; i++) |
---|
| 135 | PREDICT_VAL [i]->write(0); |
---|
| 136 | for (uint32_t i=0; i<param._nb_branch_complete; i++) |
---|
| 137 | BRANCH_COMPLETE_VAL [i]->write(0); |
---|
| 138 | |
---|
| 139 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Initialisation" << endl; |
---|
| 140 | |
---|
| 141 | // Step 1 |
---|
[3] | 142 | BRANCH_COMPLETE_VAL [num_port_branch_complete]->write(1); |
---|
| 143 | BRANCH_COMPLETE_DIRECTION [num_port_branch_complete]->write(0); |
---|
[2] | 144 | |
---|
[3] | 145 | if (param._have_pht) |
---|
[2] | 146 | { |
---|
[3] | 147 | // Step 1.1 -> pattern_history_table |
---|
| 148 | |
---|
| 149 | // Step 1.1.1 compute number of group. |
---|
| 150 | uint32_t size_address_shift=0; |
---|
| 151 | |
---|
| 152 | if (param._have_bht) |
---|
| 153 | size_address_shift=param._param_two_level_branch_predictor_glue->_pht_size_address_shift; |
---|
| 154 | |
---|
| 155 | uint32_t nb_group = (1<<size_address_shift); |
---|
| 156 | uint32_t nb_reg_by_group = (1<<(param._pht_size_address-size_address_shift)); |
---|
| 157 | |
---|
| 158 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Init pht" << endl; |
---|
[2] | 159 | |
---|
[3] | 160 | BRANCH_COMPLETE_PHT_HISTORY [num_port_branch_complete]->write(0); |
---|
| 161 | |
---|
| 162 | // Step 1.1.2 for all group ... |
---|
| 163 | for (uint32_t i=0; i<nb_group; i++) |
---|
[2] | 164 | { |
---|
[3] | 165 | if (param._have_bht) |
---|
| 166 | BRANCH_COMPLETE_BHT_HISTORY [num_port_branch_complete]->write(i); |
---|
[2] | 167 | |
---|
[3] | 168 | for (uint32_t j=0; j<nb_reg_by_group; j++) |
---|
| 169 | { |
---|
| 170 | BRANCH_COMPLETE_ADDRESS [num_port_branch_complete]->write(j); |
---|
| 171 | |
---|
| 172 | sc_start(1); |
---|
| 173 | |
---|
| 174 | // wait ackwolegde |
---|
| 175 | while (BRANCH_COMPLETE_ACK [num_port_branch_complete] -> read() == 0) |
---|
| 176 | sc_start(1); |
---|
| 177 | } |
---|
[2] | 178 | } |
---|
| 179 | } |
---|
| 180 | |
---|
[3] | 181 | if (param._have_bht) |
---|
[2] | 182 | { |
---|
[3] | 183 | // Step 1.2 -> branch_history_table |
---|
| 184 | BRANCH_COMPLETE_BHT_HISTORY [num_port_branch_complete]->write(0); |
---|
[2] | 185 | |
---|
| 186 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Init bht" << endl; |
---|
| 187 | |
---|
| 188 | for (uint32_t i=0; i<param._bht_nb_shifter; i++) |
---|
| 189 | { |
---|
[3] | 190 | BRANCH_COMPLETE_ADDRESS [num_port_branch_complete]->write(i); |
---|
[2] | 191 | |
---|
| 192 | sc_start(1); |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | // wait ackwolegde |
---|
[3] | 196 | while (BRANCH_COMPLETE_ACK [num_port_branch_complete] -> read() == 0) |
---|
[2] | 197 | sc_start(1); |
---|
| 198 | } |
---|
| 199 | |
---|
[3] | 200 | // Step 2 |
---|
| 201 | BRANCH_COMPLETE_VAL [num_port_branch_complete]->write(0); |
---|
| 202 | PREDICT_ADDRESS [num_port_predict ]->write(address); |
---|
| 203 | BRANCH_COMPLETE_ADDRESS [num_port_branch_complete]->write(address); |
---|
[2] | 204 | |
---|
[3] | 205 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Loop of Test" << endl |
---|
| 206 | << " * predict_address : " << hex << address << dec << endl; |
---|
| 207 | |
---|
| 208 | // A lot of prediction |
---|
| 209 | Tbht_history_t bht_history = 0; |
---|
| 210 | Tpht_history_t pht_history [1<<param._bht_size_shifter]; |
---|
| 211 | |
---|
| 212 | for (uint32_t i=0; i<static_cast<uint32_t>(1<<param._bht_size_shifter); i++) |
---|
| 213 | pht_history [i] = 0; |
---|
[2] | 214 | |
---|
| 215 | for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++) |
---|
| 216 | { |
---|
[3] | 217 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Predict : bht_history " << bht_history << " - pht_history " << pht_history[bht_history] << endl; |
---|
| 218 | |
---|
[5] | 219 | |
---|
[3] | 220 | // Ask a new prediction |
---|
| 221 | PREDICT_VAL [num_port_predict ]->write(1); |
---|
| 222 | |
---|
[2] | 223 | sc_start(1); |
---|
[3] | 224 | |
---|
| 225 | // wait ackwolegde |
---|
| 226 | while (PREDICT_ACK [num_port_predict] -> read() == 0) |
---|
| 227 | sc_start(1); |
---|
| 228 | PREDICT_ACK [num_port_predict ]->write(0); |
---|
| 229 | |
---|
| 230 | sc_start(0); |
---|
| 231 | |
---|
| 232 | // Test |
---|
| 233 | if (param._have_bht) |
---|
| 234 | TEST(Tbht_history_t,bht_history ,PREDICT_BHT_HISTORY[num_port_predict]->read()); |
---|
| 235 | if (param._have_pht) |
---|
| 236 | TEST(Tpht_history_t,pht_history[bht_history],PREDICT_PHT_HISTORY[num_port_predict]->read()); |
---|
| 237 | |
---|
| 238 | // update |
---|
| 239 | direction = ((rand()%2)==1); |
---|
| 240 | |
---|
| 241 | BRANCH_COMPLETE_VAL [num_port_branch_complete]->write(1); |
---|
| 242 | if (param._have_bht) |
---|
| 243 | BRANCH_COMPLETE_BHT_HISTORY [num_port_branch_complete]->write(bht_history ); |
---|
| 244 | |
---|
| 245 | |
---|
| 246 | if (param._have_pht) |
---|
| 247 | BRANCH_COMPLETE_PHT_HISTORY [num_port_branch_complete]->write(pht_history[bht_history]); |
---|
| 248 | BRANCH_COMPLETE_DIRECTION [num_port_branch_complete]->write(direction); |
---|
| 249 | |
---|
| 250 | if (param._have_pht) |
---|
| 251 | if (direction == 0) |
---|
| 252 | { |
---|
| 253 | if (pht_history[bht_history] > 0) |
---|
| 254 | pht_history[bht_history] --; |
---|
| 255 | } |
---|
| 256 | else |
---|
| 257 | { |
---|
| 258 | if (pht_history[bht_history] < (static_cast<Tpht_history_t>(1<<param._pht_size_counter)-1)) |
---|
| 259 | pht_history[bht_history] ++; |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | if (param._have_bht) |
---|
| 263 | bht_history = (((bht_history) << 1) | direction) & gen_mask<Tbht_history_t>(param._bht_size_shifter); |
---|
| 264 | |
---|
| 265 | sc_start(1); |
---|
| 266 | |
---|
| 267 | // wait ackwolegde |
---|
| 268 | while (BRANCH_COMPLETE_ACK [num_port_branch_complete] -> read() == 0) |
---|
| 269 | sc_start(1); |
---|
| 270 | |
---|
| 271 | BRANCH_COMPLETE_VAL [num_port_branch_complete]->write(0); |
---|
[2] | 272 | } |
---|
| 273 | |
---|
| 274 | /******************************************************** |
---|
| 275 | * Simulation - End |
---|
| 276 | ********************************************************/ |
---|
| 277 | |
---|
| 278 | cout << "<" << name << "> ............ Stop Simulation" << endl; |
---|
| 279 | |
---|
| 280 | #endif |
---|
| 281 | |
---|
| 282 | delete _Two_Level_Branch_Predictor; |
---|
| 283 | } |
---|