1 | /* |
---|
2 | * $Id$ |
---|
3 | * |
---|
4 | * [ Description ] |
---|
5 | * |
---|
6 | * Test |
---|
7 | */ |
---|
8 | |
---|
9 | #define NB_ITERATION 1 |
---|
10 | |
---|
11 | #include "Behavioural/Stage_1_Ifetch/Predictor/Meta_Predictor/Two_Level_Branch_Predictor/SelfTest/include/test.h" |
---|
12 | #include "Include/Test.h" |
---|
13 | |
---|
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 | *********************************************************************/ |
---|
30 | sc_clock * CLOCK ("clock", 1.0, 0.5); |
---|
31 | |
---|
32 | sc_signal<Tcontrol_t> * PREDICT_VAL [param._nb_prediction]; |
---|
33 | sc_signal<Tcontrol_t> * PREDICT_ACK [param._nb_prediction]; |
---|
34 | sc_signal<Taddress_t> * PREDICT_ADDRESS [param._nb_prediction]; |
---|
35 | sc_signal<Tbht_history_t> * PREDICT_BHT_HISTORY [param._nb_prediction]; |
---|
36 | sc_signal<Tpht_history_t> * PREDICT_PHT_HISTORY [param._nb_prediction]; |
---|
37 | |
---|
38 | sc_signal<Tcontrol_t> * BRANCH_COMPLETE_VAL [param._nb_branch_complete]; |
---|
39 | sc_signal<Tcontrol_t> * BRANCH_COMPLETE_ACK [param._nb_branch_complete]; |
---|
40 | sc_signal<Taddress_t> * BRANCH_COMPLETE_ADDRESS [param._nb_branch_complete]; |
---|
41 | sc_signal<Tbht_history_t> * BRANCH_COMPLETE_BHT_HISTORY [param._nb_branch_complete]; |
---|
42 | sc_signal<Tpht_history_t> * BRANCH_COMPLETE_PHT_HISTORY [param._nb_branch_complete]; |
---|
43 | sc_signal<Tcontrol_t> * BRANCH_COMPLETE_HIT [param._nb_branch_complete]; |
---|
44 | |
---|
45 | // Rename signal |
---|
46 | |
---|
47 | string rename; |
---|
48 | |
---|
49 | CLOCK = new sc_clock ("clock", 1.0, 0.5); |
---|
50 | |
---|
51 | for (uint32_t i=0; i<param._nb_prediction; i++) |
---|
52 | { |
---|
53 | rename = "PREDICT_VAL_" +toString(i); |
---|
54 | PREDICT_VAL [i] = new sc_signal<Tcontrol_t> (rename.c_str()); |
---|
55 | rename = "PREDICT_ACK_" +toString(i); |
---|
56 | PREDICT_ACK [i] = new sc_signal<Tcontrol_t> (rename.c_str()); |
---|
57 | rename = "PREDICT_ADDRESS_" +toString(i); |
---|
58 | PREDICT_ADDRESS [i] = new sc_signal<Taddress_t> (rename.c_str()); |
---|
59 | rename = "PREDICT_BHT_HISTORY_"+toString(i); |
---|
60 | PREDICT_BHT_HISTORY [i] = new sc_signal<Tbht_history_t> (rename.c_str()); |
---|
61 | rename = "PREDICT_PHT_HISTORY_"+toString(i); |
---|
62 | PREDICT_PHT_HISTORY [i] = new sc_signal<Tpht_history_t> (rename.c_str()); |
---|
63 | } |
---|
64 | |
---|
65 | for (uint32_t i=0; i<param._nb_branch_complete; i++) |
---|
66 | { |
---|
67 | rename = "BRANCH_COMPLETE_VAL_" +toString(i); |
---|
68 | BRANCH_COMPLETE_VAL [i] = new sc_signal<Tcontrol_t> (rename.c_str()); |
---|
69 | rename = "BRANCH_COMPLETE_ACK_" +toString(i); |
---|
70 | BRANCH_COMPLETE_ACK [i] = new sc_signal<Tcontrol_t> (rename.c_str()); |
---|
71 | rename = "BRANCH_COMPLETE_ADDRESS_" +toString(i); |
---|
72 | BRANCH_COMPLETE_ADDRESS [i] = new sc_signal<Taddress_t> (rename.c_str()); |
---|
73 | rename = "BRANCH_COMPLETE_BHT_HISTORY_"+toString(i); |
---|
74 | BRANCH_COMPLETE_BHT_HISTORY [i] = new sc_signal<Tbht_history_t> (rename.c_str()); |
---|
75 | rename = "BRANCH_COMPLETE_PHT_HISTORY_"+toString(i); |
---|
76 | BRANCH_COMPLETE_PHT_HISTORY [i] = new sc_signal<Tpht_history_t> (rename.c_str()); |
---|
77 | rename = "BRANCH_COMPLETE_HIT_" +toString(i); |
---|
78 | BRANCH_COMPLETE_HIT [i] = new sc_signal<Tcontrol_t> (rename.c_str()); |
---|
79 | } |
---|
80 | |
---|
81 | /******************************************************** |
---|
82 | * Instanciation |
---|
83 | ********************************************************/ |
---|
84 | |
---|
85 | cout << "<" << name << "> Instanciation of _Two_Level_Branch_Predictor" << endl; |
---|
86 | |
---|
87 | (*(_Two_Level_Branch_Predictor->in_CLOCK)) (*(CLOCK)); |
---|
88 | |
---|
89 | for (uint32_t i=0; i<param._nb_prediction; i++) |
---|
90 | { |
---|
91 | (*(_Two_Level_Branch_Predictor-> in_PREDICT_VAL [i])) (*(PREDICT_VAL [i])); |
---|
92 | (*(_Two_Level_Branch_Predictor->out_PREDICT_ACK [i])) (*(PREDICT_ACK [i])); |
---|
93 | (*(_Two_Level_Branch_Predictor-> in_PREDICT_ADDRESS [i])) (*(PREDICT_ADDRESS [i])); |
---|
94 | if (param._have_bht) |
---|
95 | (*(_Two_Level_Branch_Predictor->out_PREDICT_BHT_HISTORY [i])) (*(PREDICT_BHT_HISTORY [i])); |
---|
96 | if (param._have_pht) |
---|
97 | (*(_Two_Level_Branch_Predictor->out_PREDICT_PHT_HISTORY [i])) (*(PREDICT_PHT_HISTORY [i])); |
---|
98 | } |
---|
99 | |
---|
100 | for (uint32_t i=0; i<param._nb_branch_complete; i++) |
---|
101 | { |
---|
102 | (*(_Two_Level_Branch_Predictor-> in_BRANCH_COMPLETE_VAL [i])) (*(BRANCH_COMPLETE_VAL [i])); |
---|
103 | (*(_Two_Level_Branch_Predictor->out_BRANCH_COMPLETE_ACK [i])) (*(BRANCH_COMPLETE_ACK [i])); |
---|
104 | (*(_Two_Level_Branch_Predictor-> in_BRANCH_COMPLETE_ADDRESS [i])) (*(BRANCH_COMPLETE_ADDRESS [i])); |
---|
105 | if (param._have_bht) |
---|
106 | (*(_Two_Level_Branch_Predictor-> in_BRANCH_COMPLETE_BHT_HISTORY [i])) (*(BRANCH_COMPLETE_BHT_HISTORY [i])); |
---|
107 | if (param._have_bht) |
---|
108 | (*(_Two_Level_Branch_Predictor-> in_BRANCH_COMPLETE_PHT_HISTORY [i])) (*(BRANCH_COMPLETE_PHT_HISTORY [i])); |
---|
109 | (*(_Two_Level_Branch_Predictor-> in_BRANCH_COMPLETE_HIT [i])) (*(BRANCH_COMPLETE_HIT [i])); |
---|
110 | } |
---|
111 | |
---|
112 | /******************************************************** |
---|
113 | * Simulation - Begin |
---|
114 | ********************************************************/ |
---|
115 | |
---|
116 | cout << "<" << name << "> Start Simulation ............" << endl; |
---|
117 | // Initialisation |
---|
118 | |
---|
119 | const uint32_t seed = 0; |
---|
120 | //const uint32_t seed = static_cast<uint32_t>(time(NULL)); |
---|
121 | |
---|
122 | srand(seed); |
---|
123 | |
---|
124 | sc_start(0); |
---|
125 | |
---|
126 | for (uint32_t i=0; i<param._nb_prediction; i++) |
---|
127 | PREDICT_VAL [i]->write(0); |
---|
128 | for (uint32_t i=0; i<param._nb_branch_complete; i++) |
---|
129 | BRANCH_COMPLETE_VAL [i]->write(0); |
---|
130 | |
---|
131 | _Two_Level_Branch_Predictor->vhdl_testbench_label("Initialisation"); |
---|
132 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Initialisation" << endl; |
---|
133 | |
---|
134 | // Step 1 |
---|
135 | BRANCH_COMPLETE_VAL [0]->write(1); |
---|
136 | BRANCH_COMPLETE_HIT [0]->write(0); |
---|
137 | |
---|
138 | if (param._have_bht) |
---|
139 | { |
---|
140 | BRANCH_COMPLETE_BHT_HISTORY [0]->write(0); |
---|
141 | |
---|
142 | _Two_Level_Branch_Predictor->vhdl_testbench_label("Init bht"); |
---|
143 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Init bht" << endl; |
---|
144 | |
---|
145 | for (uint32_t i=0; i<param._bht_nb_shifter; i++) |
---|
146 | { |
---|
147 | BRANCH_COMPLETE_ADDRESS [0]->write(i); |
---|
148 | |
---|
149 | sc_start(1); |
---|
150 | } |
---|
151 | |
---|
152 | // wait ackwolegde |
---|
153 | while (BRANCH_COMPLETE_ACK [0] -> read() == 0) |
---|
154 | sc_start(1); |
---|
155 | } |
---|
156 | |
---|
157 | if (param._have_pht) |
---|
158 | { |
---|
159 | BRANCH_COMPLETE_BHT_HISTORY [0]->write(0); |
---|
160 | BRANCH_COMPLETE_PHT_HISTORY [0]->write(0); |
---|
161 | |
---|
162 | _Two_Level_Branch_Predictor->vhdl_testbench_label("Init bht"); |
---|
163 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Init bht" << endl; |
---|
164 | |
---|
165 | for (uint32_t i=0; i<param._bht_nb_shifter; i++) |
---|
166 | { |
---|
167 | BRANCH_COMPLETE_ADDRESS [0]->write(i); |
---|
168 | |
---|
169 | sc_start(1); |
---|
170 | } |
---|
171 | |
---|
172 | // wait ackwolegde |
---|
173 | while (BRANCH_COMPLETE_ACK [0] -> read() == 0) |
---|
174 | sc_start(1); |
---|
175 | } |
---|
176 | |
---|
177 | |
---|
178 | |
---|
179 | // Step 2 |
---|
180 | _Two_Level_Branch_Predictor->vhdl_testbench_label("Loop of Test"); |
---|
181 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Loop of Test" << endl; |
---|
182 | |
---|
183 | for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++) |
---|
184 | { |
---|
185 | _Two_Level_Branch_Predictor->vhdl_testbench_label("Iteration "+toString(iteration)); |
---|
186 | |
---|
187 | sc_start(1); |
---|
188 | } |
---|
189 | |
---|
190 | /******************************************************** |
---|
191 | * Simulation - End |
---|
192 | ********************************************************/ |
---|
193 | |
---|
194 | cout << "<" << name << "> ............ Stop Simulation" << endl; |
---|
195 | |
---|
196 | #endif |
---|
197 | |
---|
198 | delete _Two_Level_Branch_Predictor; |
---|
199 | } |
---|