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 512 |
---|
10 | |
---|
11 | #include "Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Direction/Meta_Predictor/Two_Level_Branch_Predictor/Pattern_History_Table/SelfTest/include/test.h" |
---|
12 | #include "Common/include/Test.h" |
---|
13 | |
---|
14 | void test (string name, |
---|
15 | morpheo::behavioural::core::multi_front_end::front_end::prediction_unit::direction::meta_predictor::two_level_branch_predictor::pattern_history_table::Parameters param) |
---|
16 | { |
---|
17 | cout << "<" << name << "> : Simulation SystemC" << endl; |
---|
18 | |
---|
19 | try |
---|
20 | { |
---|
21 | cout << param.print(1); |
---|
22 | param.test(); |
---|
23 | } |
---|
24 | catch (morpheo::ErrorMorpheo & error) |
---|
25 | { |
---|
26 | cout << "<" << name << "> : " << error.what (); |
---|
27 | return; |
---|
28 | } |
---|
29 | catch (...) |
---|
30 | { |
---|
31 | cerr << "<" << name << "> : This test must generate a error" << endl; |
---|
32 | exit (EXIT_FAILURE); |
---|
33 | } |
---|
34 | Pattern_History_Table * _Pattern_History_Table = new Pattern_History_Table (name.c_str(), |
---|
35 | #ifdef STATISTICS |
---|
36 | morpheo::behavioural::Parameters_Statistics(5,50), |
---|
37 | #endif |
---|
38 | param); |
---|
39 | |
---|
40 | #ifdef SYSTEMC |
---|
41 | /********************************************************************* |
---|
42 | * Déclarations des signaux |
---|
43 | *********************************************************************/ |
---|
44 | sc_clock CLOCK ("clock", 1.0, 0.5); |
---|
45 | sc_signal<Tcontrol_t> NRESET; |
---|
46 | |
---|
47 | sc_signal<Tcontrol_t> PREDICT_VAL [param._nb_prediction]; |
---|
48 | sc_signal<Tcontrol_t> PREDICT_ACK [param._nb_prediction]; |
---|
49 | sc_signal<Taddress_t> PREDICT_ADDRESS [param._nb_prediction]; |
---|
50 | sc_signal<Thistory_t> PREDICT_HISTORY [param._nb_prediction]; |
---|
51 | |
---|
52 | sc_signal<Tcontrol_t> BRANCH_COMPLETE_VAL [param._nb_branch_complete]; |
---|
53 | sc_signal<Tcontrol_t> BRANCH_COMPLETE_ACK [param._nb_branch_complete]; |
---|
54 | sc_signal<Taddress_t> BRANCH_COMPLETE_ADDRESS [param._nb_branch_complete]; |
---|
55 | sc_signal<Thistory_t> BRANCH_COMPLETE_HISTORY [param._nb_branch_complete]; |
---|
56 | sc_signal<Tcontrol_t> BRANCH_COMPLETE_DIRECTION [param._nb_branch_complete]; |
---|
57 | |
---|
58 | /******************************************************** |
---|
59 | * Instanciation |
---|
60 | ********************************************************/ |
---|
61 | |
---|
62 | cout << "<" << name << "> Instanciation of _Pattern_History_Table" << endl; |
---|
63 | |
---|
64 | (*(_Pattern_History_Table->in_CLOCK)) (CLOCK); |
---|
65 | (*(_Pattern_History_Table->in_NRESET)) (NRESET); |
---|
66 | |
---|
67 | for (uint32_t i=0; i<param._nb_prediction; i++) |
---|
68 | { |
---|
69 | (*(_Pattern_History_Table-> in_PREDICT_VAL [i])) (PREDICT_VAL [i]); |
---|
70 | (*(_Pattern_History_Table->out_PREDICT_ACK [i])) (PREDICT_ACK [i]); |
---|
71 | (*(_Pattern_History_Table-> in_PREDICT_ADDRESS [i])) (PREDICT_ADDRESS [i]); |
---|
72 | (*(_Pattern_History_Table->out_PREDICT_HISTORY [i])) (PREDICT_HISTORY [i]); |
---|
73 | } |
---|
74 | |
---|
75 | for (uint32_t i=0; i<param._nb_branch_complete; i++) |
---|
76 | { |
---|
77 | (*(_Pattern_History_Table-> in_BRANCH_COMPLETE_VAL [i])) (BRANCH_COMPLETE_VAL [i]); |
---|
78 | (*(_Pattern_History_Table->out_BRANCH_COMPLETE_ACK [i])) (BRANCH_COMPLETE_ACK [i]); |
---|
79 | (*(_Pattern_History_Table-> in_BRANCH_COMPLETE_ADDRESS [i])) (BRANCH_COMPLETE_ADDRESS [i]); |
---|
80 | (*(_Pattern_History_Table-> in_BRANCH_COMPLETE_HISTORY [i])) (BRANCH_COMPLETE_HISTORY [i]); |
---|
81 | (*(_Pattern_History_Table-> in_BRANCH_COMPLETE_DIRECTION [i])) (BRANCH_COMPLETE_DIRECTION [i]); |
---|
82 | } |
---|
83 | |
---|
84 | /******************************************************** |
---|
85 | * Simulation - Begin |
---|
86 | ********************************************************/ |
---|
87 | |
---|
88 | cout << "<" << name << "> Start Simulation ............" << endl; |
---|
89 | // Initialisation |
---|
90 | |
---|
91 | srand(0); |
---|
92 | //srand(TIME(NULL)); |
---|
93 | |
---|
94 | sc_start(0); |
---|
95 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Initialisation" << endl; |
---|
96 | |
---|
97 | NRESET.write(1); |
---|
98 | |
---|
99 | for (uint32_t i=0; i<param._nb_prediction; i++) |
---|
100 | PREDICT_VAL [i].write(0); |
---|
101 | for (uint32_t i=0; i<param._nb_branch_complete; i++) |
---|
102 | BRANCH_COMPLETE_VAL [i].write(0); |
---|
103 | |
---|
104 | // Initialisation of Register |
---|
105 | uint32_t num_port_branch_complete = 0; |
---|
106 | uint32_t num_port_predict = 0; |
---|
107 | Taddress_t address = 0; |
---|
108 | Thistory_t history_max = (1<<param._size_counter)-1; |
---|
109 | Thistory_t history = 0; |
---|
110 | Tcontrol_t direction = 0; |
---|
111 | |
---|
112 | while (address<param._nb_counter) |
---|
113 | { |
---|
114 | BRANCH_COMPLETE_VAL [0].write(1); |
---|
115 | BRANCH_COMPLETE_ADDRESS [0].write(address); |
---|
116 | BRANCH_COMPLETE_HISTORY [0].write(0); |
---|
117 | BRANCH_COMPLETE_DIRECTION [0].write(0); |
---|
118 | |
---|
119 | sc_start(1); |
---|
120 | |
---|
121 | if (BRANCH_COMPLETE_ACK[0].read()==1) |
---|
122 | address++; |
---|
123 | } |
---|
124 | |
---|
125 | BRANCH_COMPLETE_VAL [0].write(0); |
---|
126 | sc_start(0); |
---|
127 | |
---|
128 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} Loop of Test" << endl; |
---|
129 | |
---|
130 | for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++) |
---|
131 | { |
---|
132 | num_port_branch_complete = rand() % param._nb_branch_complete; |
---|
133 | num_port_predict = rand() % param._nb_prediction ; |
---|
134 | address = rand() % param._nb_counter ; |
---|
135 | history = rand() % (1<<param._size_counter) ; |
---|
136 | direction = rand() % 2; |
---|
137 | |
---|
138 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} ["+toString(num_port_branch_complete)+"]" << endl |
---|
139 | << hex |
---|
140 | << " - address : " << address << endl |
---|
141 | << " - history old : " << history << endl |
---|
142 | << " - direction : " << direction << endl; |
---|
143 | |
---|
144 | BRANCH_COMPLETE_VAL [num_port_branch_complete].write(1); |
---|
145 | BRANCH_COMPLETE_ADDRESS [num_port_branch_complete].write(address); |
---|
146 | BRANCH_COMPLETE_HISTORY [num_port_branch_complete].write(history); |
---|
147 | BRANCH_COMPLETE_DIRECTION [num_port_branch_complete].write(direction); |
---|
148 | |
---|
149 | // Wait Ack |
---|
150 | do |
---|
151 | { |
---|
152 | sc_start(1); |
---|
153 | } |
---|
154 | while (BRANCH_COMPLETE_ACK[num_port_branch_complete].read()!=1); |
---|
155 | |
---|
156 | BRANCH_COMPLETE_VAL [num_port_branch_complete].write(0); |
---|
157 | PREDICT_VAL [num_port_predict ].write(1); |
---|
158 | PREDICT_ADDRESS [num_port_predict ].write(address); |
---|
159 | |
---|
160 | history = (direction==1)?((history<history_max)?history+1:history):((history>0)?history-1:history); |
---|
161 | |
---|
162 | // Wait Ack |
---|
163 | do |
---|
164 | { |
---|
165 | sc_start(1); |
---|
166 | } |
---|
167 | while (PREDICT_ACK [num_port_predict ].read()!=1); |
---|
168 | |
---|
169 | PREDICT_VAL [num_port_predict ].write(0); |
---|
170 | |
---|
171 | cout << "{"+toString(static_cast<uint32_t>(sc_simulation_time()))+"} ["+toString(num_port_predict)+"]" << endl |
---|
172 | << " - history new : " << PREDICT_HISTORY [num_port_predict].read() << endl |
---|
173 | << dec; |
---|
174 | |
---|
175 | TEST(Thistory_t,PREDICT_HISTORY [num_port_predict].read(),history); |
---|
176 | } |
---|
177 | |
---|
178 | /******************************************************** |
---|
179 | * Simulation - End |
---|
180 | ********************************************************/ |
---|
181 | |
---|
182 | cout << "<" << name << "> ............ Stop Simulation" << endl; |
---|
183 | |
---|
184 | #endif |
---|
185 | |
---|
186 | delete _Pattern_History_Table; |
---|
187 | } |
---|