[2] | 1 | /* |
---|
| 2 | * $Id$ |
---|
| 3 | * |
---|
| 4 | * [ Description ] |
---|
| 5 | * |
---|
| 6 | * Test |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | #define NB_ITERATION 1024 |
---|
| 10 | |
---|
| 11 | #include "Behavioural/Stage_1_Ifetch/Predictor/Meta_Predictor/Two_Level_Branch_Predictor/Branch_History_Table/SelfTest/include/test.h" |
---|
| 12 | #include "Include/BitManipulation.h" |
---|
| 13 | #include "Include/Test.h" |
---|
| 14 | |
---|
| 15 | void test (string name, |
---|
| 16 | morpheo::behavioural::stage_1_ifetch::predictor::meta_predictor::two_level_branch_predictor::branch_history_table::Parameters param) |
---|
| 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 | |
---|
| 36 | Branch_History_Table * _Branch_History_Table = new Branch_History_Table (name.c_str(), |
---|
| 37 | #ifdef STATISTICS |
---|
| 38 | morpheo::behavioural::Parameters_Statistics(5,50), |
---|
| 39 | #endif |
---|
| 40 | param); |
---|
| 41 | |
---|
| 42 | #ifdef SYSTEMC |
---|
| 43 | |
---|
| 44 | /********************************************************************* |
---|
| 45 | * Déclarations des signaux |
---|
| 46 | *********************************************************************/ |
---|
| 47 | sc_clock CLOCK ("clock", 1.0, 0.5); |
---|
[15] | 48 | sc_signal<Tcontrol_t> NRESET; |
---|
[3] | 49 | sc_signal<Tcontrol_t> PREDICT_VAL [param._nb_prediction]; |
---|
| 50 | sc_signal<Tcontrol_t> PREDICT_ACK [param._nb_prediction]; |
---|
| 51 | sc_signal<Taddress_t> PREDICT_ADDRESS [param._nb_prediction]; |
---|
| 52 | sc_signal<Thistory_t> PREDICT_HISTORY [param._nb_prediction]; |
---|
| 53 | |
---|
| 54 | sc_signal<Tcontrol_t> BRANCH_COMPLETE_VAL [param._nb_branch_complete]; |
---|
| 55 | sc_signal<Tcontrol_t> BRANCH_COMPLETE_ACK [param._nb_branch_complete]; |
---|
| 56 | sc_signal<Taddress_t> BRANCH_COMPLETE_ADDRESS [param._nb_branch_complete]; |
---|
| 57 | sc_signal<Thistory_t> BRANCH_COMPLETE_HISTORY [param._nb_branch_complete]; |
---|
| 58 | sc_signal<Tcontrol_t> BRANCH_COMPLETE_DIRECTION [param._nb_branch_complete]; |
---|
[2] | 59 | |
---|
| 60 | /******************************************************** |
---|
| 61 | * Instanciation |
---|
| 62 | ********************************************************/ |
---|
| 63 | |
---|
| 64 | cout << "<" << name << "> Instanciation of _Branch_History_Table" << endl; |
---|
| 65 | |
---|
| 66 | (*(_Branch_History_Table->in_CLOCK)) (CLOCK); |
---|
[15] | 67 | (*(_Branch_History_Table->in_NRESET)) (NRESET); |
---|
[2] | 68 | |
---|
| 69 | for (uint32_t i=0; i<param._nb_prediction; i++) |
---|
| 70 | { |
---|
| 71 | (*(_Branch_History_Table-> in_PREDICT_VAL [i])) (PREDICT_VAL [i]); |
---|
| 72 | (*(_Branch_History_Table->out_PREDICT_ACK [i])) (PREDICT_ACK [i]); |
---|
| 73 | (*(_Branch_History_Table-> in_PREDICT_ADDRESS [i])) (PREDICT_ADDRESS [i]); |
---|
| 74 | (*(_Branch_History_Table->out_PREDICT_HISTORY [i])) (PREDICT_HISTORY [i]); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | for (uint32_t i=0; i<param._nb_branch_complete; i++) |
---|
| 78 | { |
---|
[3] | 79 | (*(_Branch_History_Table-> in_BRANCH_COMPLETE_VAL [i])) (BRANCH_COMPLETE_VAL [i]); |
---|
| 80 | (*(_Branch_History_Table->out_BRANCH_COMPLETE_ACK [i])) (BRANCH_COMPLETE_ACK [i]); |
---|
| 81 | (*(_Branch_History_Table-> in_BRANCH_COMPLETE_ADDRESS [i])) (BRANCH_COMPLETE_ADDRESS [i]); |
---|
| 82 | (*(_Branch_History_Table-> in_BRANCH_COMPLETE_HISTORY [i])) (BRANCH_COMPLETE_HISTORY [i]); |
---|
| 83 | (*(_Branch_History_Table-> in_BRANCH_COMPLETE_DIRECTION [i])) (BRANCH_COMPLETE_DIRECTION [i]); |
---|
[2] | 84 | } |
---|
| 85 | |
---|
| 86 | /******************************************************** |
---|
| 87 | * Simulation - Begin |
---|
| 88 | ********************************************************/ |
---|
| 89 | |
---|
| 90 | cout << "<" << name << "> Start Simulation ............" << endl; |
---|
| 91 | // Initialisation |
---|
| 92 | sc_start(0); |
---|
| 93 | |
---|
| 94 | srand(0); |
---|
| 95 | //srand(time(NULL)); |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Initialisation" << endl; |
---|
| 99 | |
---|
[15] | 100 | NRESET.write(1); |
---|
[2] | 101 | for (uint32_t i=0; i<param._nb_prediction; i++) |
---|
| 102 | PREDICT_VAL [i].write(0); |
---|
| 103 | for (uint32_t i=0; i<param._nb_branch_complete; i++) |
---|
| 104 | BRANCH_COMPLETE_VAL [i].write(0); |
---|
| 105 | |
---|
| 106 | // Initialisation of Register |
---|
| 107 | uint32_t num_port_branch_complete = 0; |
---|
| 108 | uint32_t num_port_predict = 0; |
---|
| 109 | Taddress_t address = 0; |
---|
| 110 | Thistory_t history = 0; |
---|
| 111 | Thistory_t mask = gen_mask <Thistory_t> (param._size_shifter); |
---|
[3] | 112 | Tcontrol_t direction = 0; |
---|
[2] | 113 | |
---|
| 114 | while (address<param._nb_shifter) |
---|
| 115 | { |
---|
[3] | 116 | BRANCH_COMPLETE_VAL [0].write(1); |
---|
| 117 | BRANCH_COMPLETE_ADDRESS [0].write(address); |
---|
| 118 | BRANCH_COMPLETE_HISTORY [0].write(0); |
---|
| 119 | BRANCH_COMPLETE_DIRECTION [0].write(0); |
---|
[2] | 120 | |
---|
| 121 | sc_start(1); |
---|
| 122 | |
---|
| 123 | if (BRANCH_COMPLETE_ACK[0].read()==1) |
---|
| 124 | address++; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | BRANCH_COMPLETE_VAL [0].write(0); |
---|
| 128 | sc_start(0); |
---|
| 129 | |
---|
| 130 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Loop of Test" << endl; |
---|
| 131 | |
---|
| 132 | for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++) |
---|
| 133 | { |
---|
| 134 | num_port_branch_complete = rand() % param._nb_branch_complete; |
---|
| 135 | num_port_predict = rand() % param._nb_prediction ; |
---|
| 136 | address = rand() % param._nb_shifter ; |
---|
| 137 | history = rand() % (1<<param._size_shifter) ; |
---|
[3] | 138 | direction = rand() % 2; |
---|
[2] | 139 | |
---|
| 140 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} ["+toString(num_port_branch_complete)+"]" << endl |
---|
| 141 | << hex |
---|
[3] | 142 | << " - address : " << address << endl |
---|
| 143 | << " - history old : " << history << endl |
---|
| 144 | << " - direction : " << direction<< endl; |
---|
[2] | 145 | |
---|
[3] | 146 | BRANCH_COMPLETE_VAL [num_port_branch_complete].write(1); |
---|
| 147 | BRANCH_COMPLETE_ADDRESS [num_port_branch_complete].write(address); |
---|
| 148 | BRANCH_COMPLETE_HISTORY [num_port_branch_complete].write(history); |
---|
| 149 | BRANCH_COMPLETE_DIRECTION [num_port_branch_complete].write(direction); |
---|
[2] | 150 | |
---|
| 151 | // Wait Ack |
---|
| 152 | do |
---|
| 153 | { |
---|
| 154 | sc_start(1); |
---|
| 155 | } |
---|
| 156 | while (BRANCH_COMPLETE_ACK[num_port_branch_complete].read()!=1); |
---|
| 157 | |
---|
| 158 | BRANCH_COMPLETE_VAL [num_port_branch_complete].write(0); |
---|
| 159 | PREDICT_VAL [num_port_predict ].write(1); |
---|
| 160 | PREDICT_ADDRESS [num_port_predict ].write(address); |
---|
| 161 | |
---|
[3] | 162 | history = ((history<<1)&mask)|direction; |
---|
[2] | 163 | |
---|
| 164 | // Wait Ack |
---|
| 165 | do |
---|
| 166 | { |
---|
| 167 | sc_start(1); |
---|
| 168 | } |
---|
| 169 | while (PREDICT_ACK [num_port_predict ].read()!=1); |
---|
| 170 | |
---|
| 171 | PREDICT_VAL [num_port_predict ].write(0); |
---|
| 172 | |
---|
| 173 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} ["+toString(num_port_predict)+"]" << endl |
---|
| 174 | << " - history new : " << PREDICT_HISTORY [num_port_predict].read() << endl; |
---|
| 175 | |
---|
| 176 | TEST(Thistory_t,PREDICT_HISTORY [num_port_predict].read(),history); |
---|
| 177 | |
---|
| 178 | cout << dec; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | /******************************************************** |
---|
| 182 | * Simulation - End |
---|
| 183 | ********************************************************/ |
---|
| 184 | |
---|
| 185 | cout << "<" << name << "> ............ Stop Simulation" << endl; |
---|
| 186 | |
---|
| 187 | #endif |
---|
| 188 | |
---|
| 189 | delete _Branch_History_Table; |
---|
| 190 | } |
---|