1 | #ifdef SYSTEMC |
---|
2 | /* |
---|
3 | * $Id$ |
---|
4 | * |
---|
5 | * [ Description ] |
---|
6 | * |
---|
7 | */ |
---|
8 | |
---|
9 | #include "Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Prediction_unit_Glue/include/Prediction_unit_Glue.h" |
---|
10 | |
---|
11 | namespace morpheo { |
---|
12 | namespace behavioural { |
---|
13 | namespace core { |
---|
14 | namespace multi_front_end { |
---|
15 | namespace front_end { |
---|
16 | namespace prediction_unit { |
---|
17 | namespace prediction_unit_glue { |
---|
18 | |
---|
19 | |
---|
20 | #undef FUNCTION |
---|
21 | #define FUNCTION "Prediction_unit_Glue::genMealy_decod" |
---|
22 | void Prediction_unit_Glue::genMealy_decod (void) |
---|
23 | { |
---|
24 | log_begin(Prediction_unit_Glue,FUNCTION); |
---|
25 | log_function(Prediction_unit_Glue,FUNCTION,_name.c_str()); |
---|
26 | |
---|
27 | if (PORT_READ(in_NRESET)) |
---|
28 | { |
---|
29 | // Init |
---|
30 | uint32_t decod_unit = reg_DECOD_PRIORITY; |
---|
31 | |
---|
32 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * decod_unit : %d",decod_unit); |
---|
33 | |
---|
34 | Tcontrol_t ack [_param->_nb_inst_decod[decod_unit]]; |
---|
35 | |
---|
36 | for (uint32_t i=0;i<_param->_nb_inst_decod[decod_unit]; i++) |
---|
37 | ack [i] = true; |
---|
38 | |
---|
39 | Tcontrol_t btb_val [_param->_nb_inst_branch_decod]; |
---|
40 | Tcontrol_t ras_val [_param->_nb_inst_branch_decod]; |
---|
41 | Tcontrol_t upt_val [_param->_nb_inst_branch_decod]; |
---|
42 | |
---|
43 | for (uint32_t i=0; i<_param->_nb_inst_branch_decod; i++) |
---|
44 | { |
---|
45 | btb_val [i] = false; |
---|
46 | ras_val [i] = false; |
---|
47 | upt_val [i] = false; |
---|
48 | } |
---|
49 | |
---|
50 | uint32_t port = 0; |
---|
51 | for (uint32_t i=0; i<_param->_nb_inst_decod[decod_unit]; i++) |
---|
52 | // Test if decod_unit have detected a branch |
---|
53 | if ((port>=_param->_nb_inst_branch_decod) or |
---|
54 | (PORT_READ(in_DECOD_VAL [decod_unit][i]) == 0)) |
---|
55 | { |
---|
56 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * DECOD[%d][%d] : not valid",decod_unit,i); |
---|
57 | ack [i] = false; |
---|
58 | } |
---|
59 | else |
---|
60 | { |
---|
61 | Tcontext_t context = (_param->_have_port_context_id)?PORT_READ(in_DECOD_CONTEXT_ID [decod_unit][i]):0; |
---|
62 | Tbranch_state_t branch_state = PORT_READ(in_DECOD_BRANCH_STATE [decod_unit][i]); |
---|
63 | Tcontrol_t match_inst_ifetch_ptr = PORT_READ(in_DECOD_MATCH_INST_IFETCH_PTR [decod_unit][i]); |
---|
64 | Tprediction_ptr_t depth = (_param->_have_port_depth)?PORT_READ(in_DECOD_BRANCH_UPDATE_PREDICTION_ID [decod_unit][i]):0; |
---|
65 | Tcontrol_t use_btb = false; |
---|
66 | Tcontrol_t use_ras = false; |
---|
67 | Tcontrol_t use_upt = true ; // always update upt. |
---|
68 | |
---|
69 | // Ifetch stage made an miss if : |
---|
70 | // * branch is previously predict, but it's not the good |
---|
71 | Tcontrol_t miss_ifetch = ((branch_state != BRANCH_STATE_NONE) and (match_inst_ifetch_ptr == 0)); |
---|
72 | // Decod stage made an miss if : |
---|
73 | // * branch was not detected |
---|
74 | Tcontrol_t miss_decod = (branch_state == BRANCH_STATE_NONE); |
---|
75 | |
---|
76 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * DECOD[%d][%d] : valid",decod_unit,i); |
---|
77 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * branch_state : %d",branch_state); |
---|
78 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * match_inst_ifetch_ptr : %d",match_inst_ifetch_ptr); |
---|
79 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * depth : [%d] %d",i,depth); |
---|
80 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * miss_ifetch : %d",miss_ifetch); |
---|
81 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * miss_decod : %d",miss_decod); |
---|
82 | |
---|
83 | // Test if ifetch have detecte a branch is the packet |
---|
84 | if (miss_ifetch or miss_decod) |
---|
85 | { |
---|
86 | Tbranch_condition_t condition = PORT_READ(in_DECOD_BRANCH_CONDITION [decod_unit][i]); |
---|
87 | Tcontrol_t direction = PORT_READ(in_DECOD_BRANCH_DIRECTION [decod_unit][i]); |
---|
88 | Taddress_t address_src = PORT_READ(in_DECOD_ADDRESS_SRC [decod_unit][i]); |
---|
89 | Taddress_t address_dest = PORT_READ(in_DECOD_ADDRESS_DEST [decod_unit][i]); |
---|
90 | Tcontrol_t is_accurate; |
---|
91 | |
---|
92 | // Miss speculation |
---|
93 | use_btb = true; |
---|
94 | |
---|
95 | switch (condition) |
---|
96 | { |
---|
97 | case BRANCH_CONDITION_NONE_WITH_WRITE_STACK : |
---|
98 | { |
---|
99 | // l.jal |
---|
100 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * BRANCH_CONDITION_NONE_WITH_WRITE_STACK"); |
---|
101 | |
---|
102 | is_accurate = true ;//PORT_READ(in_DECOD_RAS_HIT [port]); |
---|
103 | use_ras = true ; |
---|
104 | |
---|
105 | PORT_WRITE(out_DECOD_RAS_PUSH [port],1); |
---|
106 | PORT_WRITE(out_DECOD_RAS_ADDRESS_PUSH [port],address_src+2); |
---|
107 | |
---|
108 | break; |
---|
109 | } |
---|
110 | |
---|
111 | case BRANCH_CONDITION_READ_REGISTER_WITH_WRITE_STACK : |
---|
112 | { |
---|
113 | // l.jalr |
---|
114 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * BRANCH_CONDITION_READ_REGISTER_WITH_WRITE_STACK"); |
---|
115 | |
---|
116 | is_accurate = false; // address unknow : in a register |
---|
117 | use_ras = true; |
---|
118 | |
---|
119 | PORT_WRITE(out_DECOD_RAS_PUSH [port],1); |
---|
120 | PORT_WRITE(out_DECOD_RAS_ADDRESS_PUSH [port],address_src+2); |
---|
121 | |
---|
122 | break; |
---|
123 | } |
---|
124 | case BRANCH_CONDITION_READ_STACK : |
---|
125 | { |
---|
126 | // l.jr with rb=r9 |
---|
127 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * BRANCH_CONDITION_READ_STACK"); |
---|
128 | |
---|
129 | is_accurate = PORT_READ(in_DECOD_RAS_HIT [port]); |
---|
130 | use_ras = true; |
---|
131 | |
---|
132 | PORT_WRITE(out_DECOD_RAS_PUSH [port],0); // POP |
---|
133 | address_dest = PORT_READ(in_DECOD_RAS_ADDRESS_POP [port]); |
---|
134 | |
---|
135 | break; |
---|
136 | } |
---|
137 | case BRANCH_CONDITION_READ_REGISTER_WITHOUT_WRITE_STACK : |
---|
138 | { |
---|
139 | // l.jr with rb!=r9 |
---|
140 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * BRANCH_CONDITION_READ_REGISTER_WITHOUT_WRITE_STACK"); |
---|
141 | |
---|
142 | // * READ_REGISTER_WITHOUT_WRITE_STACK : Take but destination is unknow - don't continue |
---|
143 | is_accurate = false; // address unknow : in a register |
---|
144 | |
---|
145 | break; |
---|
146 | } |
---|
147 | |
---|
148 | case BRANCH_CONDITION_FLAG_UNSET : |
---|
149 | case BRANCH_CONDITION_FLAG_SET : |
---|
150 | { |
---|
151 | // l.bf, l.bnf |
---|
152 | // * FLAG : static direction and destination is know |
---|
153 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * BRANCH_CONDITION_FLAG"); |
---|
154 | |
---|
155 | is_accurate = true; // address dest is know |
---|
156 | |
---|
157 | break; |
---|
158 | } |
---|
159 | |
---|
160 | case BRANCH_CONDITION_NONE_WITHOUT_WRITE_STACK : |
---|
161 | { |
---|
162 | // l.j |
---|
163 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * BRANCH_CONDITION_NONE_WITHOUT_WRITE_STACK"); |
---|
164 | |
---|
165 | is_accurate = true; |
---|
166 | |
---|
167 | break; |
---|
168 | } |
---|
169 | } |
---|
170 | |
---|
171 | if (use_btb) |
---|
172 | { |
---|
173 | if (_param->_have_port_context_id) |
---|
174 | PORT_WRITE(out_DECOD_BTB_CONTEXT_ID [port],context); |
---|
175 | PORT_WRITE(out_DECOD_BTB_ADDRESS_SRC [port],address_src); |
---|
176 | PORT_WRITE(out_DECOD_BTB_ADDRESS_DEST [port],address_dest); |
---|
177 | PORT_WRITE(out_DECOD_BTB_CONDITION [port],condition); |
---|
178 | PORT_WRITE(out_DECOD_BTB_LAST_TAKE [port],direction); |
---|
179 | PORT_WRITE(out_DECOD_BTB_MISS_PREDICTION [port],1); |
---|
180 | PORT_WRITE(out_DECOD_BTB_IS_ACCURATE [port],is_accurate); |
---|
181 | } |
---|
182 | if (use_ras) |
---|
183 | { |
---|
184 | miss_decod |= not PORT_READ(in_DECOD_RAS_HIT [port]); |
---|
185 | |
---|
186 | if (_param->_have_port_context_id) |
---|
187 | PORT_WRITE(out_DECOD_RAS_CONTEXT_ID [port],context); |
---|
188 | PORT_WRITE(out_DECOD_RAS_MISS_PREDICTION [port],1); |
---|
189 | } |
---|
190 | if (use_upt) |
---|
191 | { |
---|
192 | PORT_WRITE(out_DECOD_UPT_BTB_ADDRESS_SRC [port],address_src); |
---|
193 | PORT_WRITE(out_DECOD_UPT_BTB_ADDRESS_DEST[port],address_dest); |
---|
194 | PORT_WRITE(out_DECOD_UPT_BTB_CONDITION [port],condition); |
---|
195 | PORT_WRITE(out_DECOD_UPT_BTB_LAST_TAKE [port],direction); |
---|
196 | PORT_WRITE(out_DECOD_UPT_RAS_ADDRESS [port],PORT_READ(in_DECOD_RAS_ADDRESS_POP [port])); |
---|
197 | PORT_WRITE(out_DECOD_UPT_IS_ACCURATE [port],is_accurate); |
---|
198 | } |
---|
199 | } |
---|
200 | // else |
---|
201 | // { |
---|
202 | // log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * hit"); |
---|
203 | |
---|
204 | // miss_decod = false; |
---|
205 | // // Hit speculation |
---|
206 | // } |
---|
207 | |
---|
208 | |
---|
209 | // in all case |
---|
210 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * use_btb : %d",use_btb); |
---|
211 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * use_ras : %d",use_ras); |
---|
212 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * use_upt : %d",use_upt); |
---|
213 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * btb_ack [%d] : %d",port,PORT_READ(in_DECOD_BTB_ACK [port])); |
---|
214 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * ras_ack [%d] : %d",port,PORT_READ(in_DECOD_RAS_ACK [port])); |
---|
215 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * upt_ack [%d] : %d",port,PORT_READ(in_DECOD_UPT_ACK [port])); |
---|
216 | |
---|
217 | btb_val [port] = (use_btb and |
---|
218 | (not use_ras or (use_ras and PORT_READ(in_DECOD_RAS_ACK [port]))) and |
---|
219 | (not use_upt or (use_upt and PORT_READ(in_DECOD_UPT_ACK [port])))); |
---|
220 | |
---|
221 | ras_val [port] = (use_ras and |
---|
222 | (not use_btb or (use_btb and PORT_READ(in_DECOD_BTB_ACK [port]))) and |
---|
223 | (not use_upt or (use_upt and PORT_READ(in_DECOD_UPT_ACK [port])))); |
---|
224 | |
---|
225 | upt_val [port] = (use_upt and |
---|
226 | (not use_btb or (use_btb and PORT_READ(in_DECOD_BTB_ACK [port]))) and |
---|
227 | (not use_ras or (use_ras and PORT_READ(in_DECOD_RAS_ACK [port])))); |
---|
228 | |
---|
229 | if (use_btb) |
---|
230 | ack [i] &= btb_val [port] and PORT_READ(in_DECOD_BTB_ACK [port]); |
---|
231 | if (use_ras) |
---|
232 | ack [i] &= ras_val [port] and PORT_READ(in_DECOD_RAS_ACK [port]); |
---|
233 | if (use_upt) |
---|
234 | ack [i] &= upt_val [port] and PORT_READ(in_DECOD_UPT_ACK [port]); |
---|
235 | |
---|
236 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * btb_val [%d] : %d",port,btb_val [port]); |
---|
237 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * ras_val [%d] : %d",port,ras_val [port]); |
---|
238 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * upt_val [%d] : %d",port,upt_val [port]); |
---|
239 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * ack [%d] : %d",i ,ack [i ]); |
---|
240 | |
---|
241 | if (_param->_have_port_context_id) |
---|
242 | PORT_WRITE(out_DECOD_UPT_CONTEXT_ID [port],context); |
---|
243 | PORT_WRITE(out_DECOD_UPT_MISS_IFETCH [port],miss_ifetch); |
---|
244 | PORT_WRITE(out_DECOD_UPT_MISS_DECOD [port],miss_decod ); |
---|
245 | if (_param->_have_port_depth) |
---|
246 | PORT_WRITE(out_DECOD_UPT_UPDATE_PREDICTION_ID [port],depth); |
---|
247 | |
---|
248 | port ++; |
---|
249 | } |
---|
250 | |
---|
251 | // Write output |
---|
252 | |
---|
253 | for (uint32_t i=0; i<_param->_nb_inst_branch_decod; i++) |
---|
254 | { |
---|
255 | PORT_WRITE(out_DECOD_BTB_VAL [i], btb_val [i]); |
---|
256 | PORT_WRITE(out_DECOD_RAS_VAL [i], ras_val [i]); |
---|
257 | PORT_WRITE(out_DECOD_UPT_VAL [i], upt_val [i]); |
---|
258 | } |
---|
259 | |
---|
260 | for (uint32_t i=0; i<_param->_nb_decod_unit; i++) |
---|
261 | for (uint32_t j=0; j<_param->_nb_inst_decod[i]; j++) |
---|
262 | if (i!= decod_unit) |
---|
263 | PORT_WRITE(out_DECOD_ACK [i][j], 0); |
---|
264 | else |
---|
265 | PORT_WRITE(out_DECOD_ACK [i][j], ack[j]); |
---|
266 | } |
---|
267 | log_end(Prediction_unit_Glue,FUNCTION); |
---|
268 | }; |
---|
269 | |
---|
270 | }; // end namespace prediction_unit_glue |
---|
271 | }; // end namespace prediction_unit |
---|
272 | }; // end namespace front_end |
---|
273 | }; // end namespace multi_front_end |
---|
274 | }; // end namespace core |
---|
275 | |
---|
276 | }; // end namespace behavioural |
---|
277 | }; // end namespace morpheo |
---|
278 | #endif |
---|