[2] | 1 | /* |
---|
| 2 | * $Id: test.cpp 81 2008-04-15 18:40:01Z rosiere $ |
---|
| 3 | * |
---|
| 4 | * [ Description ] |
---|
| 5 | * |
---|
| 6 | * Test |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #define NB_ITERATION 64 |
---|
| 10 | |
---|
[48] | 11 | #include "Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Direction/Meta_Predictor/Two_Level_Branch_Predictor/Two_Level_Branch_Predictor_Glue/SelfTest/include/test.h" |
---|
[44] | 12 | #include "Common/include/BitManipulation.h" |
---|
| 13 | #include "Common/include/Test.h" |
---|
[2] | 14 | |
---|
| 15 | void test (string name, |
---|
[48] | 16 | morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::direction::meta_predictor::two_level_branch_predictor::two_level_branch_predictor_glue::Parameters param) |
---|
[2] | 17 | { |
---|
| 18 | cout << "<" << name << "> : Simulation SystemC" << endl; |
---|
| 19 | |
---|
| 20 | try |
---|
| 21 | { |
---|
| 22 | cout << param.print(1); |
---|
| 23 | param.test(); |
---|
| 24 | } |
---|
| 25 | catch (morpheo::ErrorMorpheo & error) |
---|
| 26 | { |
---|
| 27 | cout << "<" << name << "> : " << error.what (); |
---|
| 28 | return; |
---|
| 29 | } |
---|
| 30 | catch (...) |
---|
| 31 | { |
---|
| 32 | cerr << "<" << name << "> : This test must generate a error" << endl; |
---|
| 33 | exit (EXIT_FAILURE); |
---|
| 34 | } |
---|
| 35 | Two_Level_Branch_Predictor_Glue * _Two_Level_Branch_Predictor_Glue = new Two_Level_Branch_Predictor_Glue (name.c_str(), |
---|
| 36 | #ifdef STATISTICS |
---|
| 37 | morpheo::behavioural::Parameters_Statistics(5,50), |
---|
| 38 | #endif |
---|
| 39 | param); |
---|
| 40 | |
---|
| 41 | #ifdef SYSTEMC |
---|
| 42 | /********************************************************************* |
---|
| 43 | * Déclarations des signaux |
---|
| 44 | *********************************************************************/ |
---|
| 45 | sc_clock CLOCK ("clock", 1.0, 0.5); |
---|
[42] | 46 | sc_signal<Tcontrol_t> NRESET; |
---|
[2] | 47 | |
---|
| 48 | sc_signal<Tcontrol_t> PREDICT_BHT_ACK [param._nb_prediction]; |
---|
| 49 | sc_signal<Tcontrol_t> PREDICT_PHT_ACK [param._nb_prediction]; |
---|
| 50 | sc_signal<Tcontrol_t> PREDICT_ACK [param._nb_prediction]; |
---|
| 51 | |
---|
| 52 | sc_signal<Taddress_t> PREDICT_ADDRESS [param._nb_prediction]; |
---|
| 53 | sc_signal<Tbht_history_t> PREDICT_BHT_HISTORY [param._nb_prediction]; |
---|
| 54 | sc_signal<Taddress_t> PREDICT_BHT_ADDRESS [param._nb_prediction]; |
---|
| 55 | sc_signal<Taddress_t> PREDICT_PHT_ADDRESS [param._nb_prediction]; |
---|
| 56 | |
---|
| 57 | sc_signal<Tcontrol_t> BRANCH_COMPLETE_BHT_ACK [param._nb_branch_complete]; |
---|
| 58 | sc_signal<Tcontrol_t> BRANCH_COMPLETE_PHT_ACK [param._nb_branch_complete]; |
---|
| 59 | sc_signal<Tcontrol_t> BRANCH_COMPLETE_ACK [param._nb_branch_complete]; |
---|
| 60 | sc_signal<Taddress_t> BRANCH_COMPLETE_ADDRESS [param._nb_branch_complete]; |
---|
| 61 | sc_signal<Tbht_history_t> BRANCH_COMPLETE_BHT_HISTORY [param._nb_branch_complete]; |
---|
| 62 | sc_signal<Taddress_t> BRANCH_COMPLETE_BHT_ADDRESS [param._nb_branch_complete]; |
---|
| 63 | sc_signal<Taddress_t> BRANCH_COMPLETE_PHT_ADDRESS [param._nb_branch_complete]; |
---|
| 64 | |
---|
| 65 | /******************************************************** |
---|
| 66 | * Instanciation |
---|
| 67 | ********************************************************/ |
---|
| 68 | |
---|
| 69 | cout << "<" << name << "> Instanciation of _Two_Level_Branch_Predictor_Glue" << endl; |
---|
| 70 | |
---|
| 71 | (*(_Two_Level_Branch_Predictor_Glue->in_CLOCK)) (CLOCK); |
---|
[42] | 72 | (*(_Two_Level_Branch_Predictor_Glue->in_NRESET)) (NRESET); |
---|
[2] | 73 | |
---|
| 74 | for (uint32_t i=0; i<param._nb_prediction; i++) |
---|
| 75 | { |
---|
| 76 | if (param._have_bht) |
---|
| 77 | { |
---|
| 78 | (*(_Two_Level_Branch_Predictor_Glue-> in_PREDICT_BHT_ACK [i])) (PREDICT_BHT_ACK [i]); |
---|
| 79 | (*(_Two_Level_Branch_Predictor_Glue->out_PREDICT_BHT_ADDRESS [i])) (PREDICT_BHT_ADDRESS [i]); |
---|
| 80 | } |
---|
| 81 | if (param._have_bht and param._have_pht) |
---|
| 82 | (*(_Two_Level_Branch_Predictor_Glue-> in_PREDICT_BHT_HISTORY [i])) (PREDICT_BHT_HISTORY [i]); |
---|
| 83 | if (param._have_pht) |
---|
| 84 | { |
---|
| 85 | (*(_Two_Level_Branch_Predictor_Glue-> in_PREDICT_PHT_ACK [i])) (PREDICT_PHT_ACK [i]); |
---|
| 86 | (*(_Two_Level_Branch_Predictor_Glue->out_PREDICT_PHT_ADDRESS [i])) (PREDICT_PHT_ADDRESS [i]); |
---|
| 87 | } |
---|
| 88 | (*(_Two_Level_Branch_Predictor_Glue->out_PREDICT_ACK [i])) (PREDICT_ACK [i]); |
---|
| 89 | (*(_Two_Level_Branch_Predictor_Glue-> in_PREDICT_ADDRESS [i])) (PREDICT_ADDRESS [i]); |
---|
| 90 | } |
---|
| 91 | for (uint32_t i=0; i<param._nb_branch_complete; i++) |
---|
| 92 | { |
---|
| 93 | if (param._have_bht) |
---|
| 94 | { |
---|
| 95 | (*(_Two_Level_Branch_Predictor_Glue-> in_BRANCH_COMPLETE_BHT_ACK [i])) (BRANCH_COMPLETE_BHT_ACK [i]); |
---|
| 96 | (*(_Two_Level_Branch_Predictor_Glue->out_BRANCH_COMPLETE_BHT_ADDRESS [i])) (BRANCH_COMPLETE_BHT_ADDRESS [i]); |
---|
| 97 | } |
---|
| 98 | if (param._have_bht and param._have_pht) |
---|
| 99 | (*(_Two_Level_Branch_Predictor_Glue-> in_BRANCH_COMPLETE_BHT_HISTORY [i])) (BRANCH_COMPLETE_BHT_HISTORY [i]); |
---|
| 100 | |
---|
| 101 | if (param._have_pht) |
---|
| 102 | { |
---|
| 103 | (*(_Two_Level_Branch_Predictor_Glue-> in_BRANCH_COMPLETE_PHT_ACK [i])) (BRANCH_COMPLETE_PHT_ACK [i]); |
---|
| 104 | (*(_Two_Level_Branch_Predictor_Glue->out_BRANCH_COMPLETE_PHT_ADDRESS [i])) (BRANCH_COMPLETE_PHT_ADDRESS [i]); |
---|
| 105 | } |
---|
| 106 | (*(_Two_Level_Branch_Predictor_Glue->out_BRANCH_COMPLETE_ACK [i])) (BRANCH_COMPLETE_ACK [i]); |
---|
| 107 | (*(_Two_Level_Branch_Predictor_Glue-> in_BRANCH_COMPLETE_ADDRESS [i])) (BRANCH_COMPLETE_ADDRESS [i]); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | /******************************************************** |
---|
| 111 | * Simulation - Begin |
---|
| 112 | ********************************************************/ |
---|
| 113 | |
---|
| 114 | cout << "<" << name << "> Start Simulation ............" << endl; |
---|
| 115 | // Initialisation |
---|
| 116 | |
---|
| 117 | Tcontrol_t predict_bht_ack; |
---|
| 118 | Tcontrol_t predict_pht_ack; |
---|
| 119 | |
---|
| 120 | Tcontrol_t branch_complete_bht_ack; |
---|
| 121 | Tcontrol_t branch_complete_pht_ack; |
---|
| 122 | |
---|
| 123 | srand(0); |
---|
| 124 | //srand(time(NULL)); |
---|
| 125 | |
---|
| 126 | sc_start(0); |
---|
[42] | 127 | |
---|
[2] | 128 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Initialisation" << endl; |
---|
| 129 | |
---|
[42] | 130 | NRESET.write(1); |
---|
[2] | 131 | |
---|
| 132 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Test ack" << endl; |
---|
| 133 | |
---|
| 134 | for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++) |
---|
| 135 | { |
---|
| 136 | // Branch History Table |
---|
| 137 | if (param._have_bht) |
---|
| 138 | { |
---|
| 139 | predict_bht_ack = (rand()%2)!=0; |
---|
| 140 | branch_complete_bht_ack = (rand()%2)!=0; |
---|
| 141 | |
---|
| 142 | } |
---|
| 143 | else |
---|
| 144 | { |
---|
| 145 | predict_bht_ack = 1; |
---|
| 146 | branch_complete_bht_ack = 1; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | // Pattern History Table |
---|
| 150 | if (param._have_pht) |
---|
| 151 | { |
---|
| 152 | predict_pht_ack = (rand()%2)!=0; |
---|
| 153 | branch_complete_pht_ack = (rand()%2)!=0; |
---|
| 154 | } |
---|
| 155 | else |
---|
| 156 | { |
---|
| 157 | predict_pht_ack = 1; |
---|
| 158 | branch_complete_pht_ack = 1; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | for (uint32_t i=0; i<param._nb_prediction; i++) |
---|
| 162 | { |
---|
| 163 | PREDICT_BHT_ACK [i] .write(predict_bht_ack); |
---|
| 164 | PREDICT_PHT_ACK [i] .write(predict_pht_ack); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | for (uint32_t i=0; i<param._nb_branch_complete; i++) |
---|
| 168 | { |
---|
| 169 | BRANCH_COMPLETE_BHT_ACK [i] .write(branch_complete_bht_ack); |
---|
| 170 | BRANCH_COMPLETE_PHT_ACK [i] .write(branch_complete_pht_ack); |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | sc_start(0); |
---|
| 174 | |
---|
| 175 | // Test result |
---|
| 176 | for (uint32_t i=0; i<param._nb_prediction; i++) |
---|
| 177 | TEST(Tcontrol_t,(predict_pht_ack & predict_bht_ack),PREDICT_ACK [i].read()); |
---|
| 178 | |
---|
| 179 | for (uint32_t i=0; i<param._nb_branch_complete; i++) |
---|
| 180 | TEST(Tcontrol_t,(branch_complete_pht_ack & branch_complete_bht_ack),BRANCH_COMPLETE_ACK [i].read()); |
---|
| 181 | |
---|
| 182 | sc_start(1); |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | Taddress_t predict_address; |
---|
| 186 | Tbht_history_t predict_bht_history; |
---|
| 187 | Taddress_t branch_complete_address; |
---|
| 188 | Tbht_history_t branch_complete_bht_history; |
---|
| 189 | |
---|
| 190 | |
---|
| 191 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Test address" << endl; |
---|
| 192 | |
---|
| 193 | for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++) |
---|
| 194 | { |
---|
| 195 | predict_address = rand()%(1<<param._size_address ); |
---|
| 196 | predict_bht_history = 0; |
---|
| 197 | branch_complete_address = rand()%(1<<param._size_address ); |
---|
| 198 | branch_complete_bht_history = 0; |
---|
| 199 | |
---|
| 200 | for (uint32_t i=0; i<param._nb_prediction; i++) |
---|
| 201 | PREDICT_ADDRESS [i].write (predict_address); |
---|
| 202 | for (uint32_t i=0; i<param._nb_branch_complete; i++) |
---|
| 203 | BRANCH_COMPLETE_ADDRESS [i].write (branch_complete_address); |
---|
| 204 | |
---|
| 205 | // Branch History Table |
---|
| 206 | if (param._have_bht and param._have_pht) |
---|
| 207 | { |
---|
| 208 | predict_bht_history = rand()%(1<<param._bht_size_history); |
---|
| 209 | branch_complete_bht_history = rand()%(1<<param._bht_size_history); |
---|
| 210 | |
---|
| 211 | for (uint32_t i=0; i<param._nb_prediction; i++) |
---|
| 212 | PREDICT_BHT_HISTORY [i].write(predict_bht_history); |
---|
| 213 | for (uint32_t i=0; i<param._nb_branch_complete; i++) |
---|
| 214 | BRANCH_COMPLETE_BHT_HISTORY [i].write(branch_complete_bht_history); |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | sc_start(0); |
---|
| 218 | |
---|
| 219 | // Branch History Table |
---|
| 220 | if (param._have_bht) |
---|
| 221 | { |
---|
| 222 | for (uint32_t i=0; i<param._nb_prediction; i++) |
---|
| 223 | TEST(Taddress_t,PREDICT_BHT_ADDRESS [i].read(),(predict_address & gen_mask<Taddress_t>(param._bht_size_address))); |
---|
| 224 | |
---|
| 225 | for (uint32_t i=0; i<param._nb_branch_complete; i++) |
---|
| 226 | TEST(Taddress_t,BRANCH_COMPLETE_BHT_ADDRESS [i].read(),(branch_complete_address & gen_mask<Taddress_t>(param._bht_size_address))); |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | // Pattern History Table |
---|
| 230 | if (param._have_pht) |
---|
| 231 | { |
---|
| 232 | uint32_t shift = (param._have_bht==false)?0:(param._pht_size_address_shift); |
---|
| 233 | |
---|
| 234 | for (uint32_t i=0; i<param._nb_prediction; i++) |
---|
| 235 | TEST(Taddress_t,PREDICT_PHT_ADDRESS [i].read(),(((predict_address << shift) xor predict_bht_history) & gen_mask<Taddress_t>(param._pht_size_address))); |
---|
| 236 | for (uint32_t i=0; i<param._nb_branch_complete; i++) |
---|
| 237 | TEST(Taddress_t,BRANCH_COMPLETE_PHT_ADDRESS [i].read(), (((branch_complete_address << shift) xor branch_complete_bht_history) & gen_mask<Taddress_t>(param._pht_size_address))); |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | sc_start(1); |
---|
| 241 | } |
---|
| 242 | /******************************************************** |
---|
| 243 | * Simulation - End |
---|
| 244 | ********************************************************/ |
---|
| 245 | |
---|
| 246 | cout << "<" << name << "> ............ Stop Simulation" << endl; |
---|
| 247 | |
---|
| 248 | #endif |
---|
| 249 | |
---|
| 250 | delete _Two_Level_Branch_Predictor_Glue; |
---|
| 251 | } |
---|