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_printf(FUNC,Prediction_unit_Glue,FUNCTION,"Begin"); |
---|
25 | |
---|
26 | uint32_t decod_unit = reg_DECOD_PRIORITY; |
---|
27 | |
---|
28 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * decod_unit : %d",decod_unit); |
---|
29 | |
---|
30 | Tcontrol_t ack [_param->_nb_inst_decod[decod_unit]]; |
---|
31 | |
---|
32 | for (uint32_t i=0;i<_param->_nb_inst_decod[decod_unit]; i++) |
---|
33 | ack [i] = true; |
---|
34 | |
---|
35 | Tcontrol_t btb_val [_param->_nb_inst_branch_decod]; |
---|
36 | Tcontrol_t ras_val [_param->_nb_inst_branch_decod]; |
---|
37 | Tcontrol_t upt_val [_param->_nb_inst_branch_decod]; |
---|
38 | |
---|
39 | for (uint32_t i=0; i<_param->_nb_inst_branch_decod; i++) |
---|
40 | { |
---|
41 | btb_val [i] = false; |
---|
42 | ras_val [i] = false; |
---|
43 | upt_val [i] = false; |
---|
44 | } |
---|
45 | |
---|
46 | uint32_t port = 0; |
---|
47 | for (uint32_t i=0; i<_param->_nb_inst_decod[decod_unit]; i++) |
---|
48 | // Test if decod_unit have detected a branch |
---|
49 | if ((port>=_param->_nb_inst_branch_decod) or |
---|
50 | (PORT_READ(in_DECOD_VAL [decod_unit][i]) == 0)) |
---|
51 | { |
---|
52 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * DECOD[%d][%d] : not valid",decod_unit,i); |
---|
53 | ack [i] = false; |
---|
54 | } |
---|
55 | else |
---|
56 | { |
---|
57 | Tcontext_t context = (_param->_have_port_context_id)?PORT_READ(in_DECOD_CONTEXT_ID [decod_unit][i]):0; |
---|
58 | Tbranch_state_t branch_state = PORT_READ(in_DECOD_BRANCH_STATE [decod_unit][i]); |
---|
59 | Tcontrol_t match_inst_ifetch_ptr = PORT_READ(in_DECOD_MATCH_INST_IFETCH_PTR [decod_unit][i]); |
---|
60 | Tprediction_ptr_t depth = (_param->_have_port_max_depth)?PORT_READ(in_DECOD_BRANCH_UPDATE_PREDICTION_ID [decod_unit][i]):0; |
---|
61 | Tcontrol_t use_btb = false; |
---|
62 | Tcontrol_t use_ras = false; |
---|
63 | Tcontrol_t use_upt = true ; |
---|
64 | Tcontrol_t miss_ifetch = ( (branch_state == BRANCH_STATE_NONE) or // branch not detected |
---|
65 | ((branch_state != BRANCH_STATE_NONE) and (match_inst_ifetch_ptr == 0))); // branch detected, but it's not the good |
---|
66 | Tcontrol_t miss_decod; |
---|
67 | |
---|
68 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * DECOD[%d][%d] : valid",decod_unit,i); |
---|
69 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * depth [%d] : %d",i ,depth); |
---|
70 | |
---|
71 | // Test if ifetch have detecte a branch is the packet |
---|
72 | if (miss_ifetch) |
---|
73 | { |
---|
74 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * miss_ifetch"); |
---|
75 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * state : %d",branch_state); |
---|
76 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * match : %d",match_inst_ifetch_ptr); |
---|
77 | Tbranch_condition_t condition = PORT_READ(in_DECOD_BRANCH_CONDITION [decod_unit][i]); |
---|
78 | Tcontrol_t direction = PORT_READ(in_DECOD_BRANCH_DIRECTION [decod_unit][i]); |
---|
79 | Taddress_t address_src = PORT_READ(in_DECOD_ADDRESS_SRC [decod_unit][i]); |
---|
80 | Taddress_t address_dest = PORT_READ(in_DECOD_ADDRESS_DEST [decod_unit][i]); |
---|
81 | Tcontrol_t is_accurate; |
---|
82 | |
---|
83 | // Miss speculation |
---|
84 | use_btb = true; |
---|
85 | |
---|
86 | switch (condition) |
---|
87 | { |
---|
88 | case BRANCH_CONDITION_NONE_WITH_WRITE_STACK : |
---|
89 | { |
---|
90 | // Write stack |
---|
91 | is_accurate = PORT_READ(in_DECOD_RAS_HIT [port]); |
---|
92 | miss_decod = false; |
---|
93 | use_ras = true; |
---|
94 | |
---|
95 | PORT_WRITE(out_DECOD_RAS_PUSH [port],1); |
---|
96 | PORT_WRITE(out_DECOD_RAS_ADDRESS_PUSH [port],address_dest); |
---|
97 | |
---|
98 | break; |
---|
99 | } |
---|
100 | |
---|
101 | case BRANCH_CONDITION_READ_REGISTER_WITH_WRITE_STACK : |
---|
102 | { |
---|
103 | // Write stack |
---|
104 | is_accurate = false; |
---|
105 | miss_decod = false; |
---|
106 | use_ras = true; |
---|
107 | |
---|
108 | PORT_WRITE(out_DECOD_RAS_PUSH [port],1); |
---|
109 | PORT_WRITE(out_DECOD_RAS_ADDRESS_PUSH [port],address_dest); |
---|
110 | |
---|
111 | break; |
---|
112 | } |
---|
113 | case BRANCH_CONDITION_READ_STACK : |
---|
114 | { |
---|
115 | // Read stack |
---|
116 | is_accurate = PORT_READ(in_DECOD_RAS_HIT [port]); |
---|
117 | miss_decod = false; |
---|
118 | use_ras = true; |
---|
119 | |
---|
120 | PORT_WRITE(out_DECOD_RAS_PUSH [port],0); |
---|
121 | address_dest = PORT_READ(in_DECOD_RAS_ADDRESS_POP [port]); |
---|
122 | |
---|
123 | break; |
---|
124 | } |
---|
125 | case BRANCH_CONDITION_READ_REGISTER_WITHOUT_WRITE_STACK : |
---|
126 | { |
---|
127 | // * READ_REGISTER_WITHOUT_WRITE_STACK : Take but destination is unknow - don't continue |
---|
128 | is_accurate = PORT_READ(in_DECOD_RAS_HIT [port]); |
---|
129 | miss_decod = true; |
---|
130 | |
---|
131 | break; |
---|
132 | } |
---|
133 | |
---|
134 | case BRANCH_CONDITION_FLAG_UNSET : |
---|
135 | case BRANCH_CONDITION_FLAG_SET : |
---|
136 | { |
---|
137 | // No access at the flag |
---|
138 | // * FLAG : static direction and destination is know |
---|
139 | is_accurate = PORT_READ(in_DECOD_RAS_HIT [port]); |
---|
140 | miss_decod = false; |
---|
141 | |
---|
142 | break; |
---|
143 | } |
---|
144 | |
---|
145 | case BRANCH_CONDITION_NONE_WITHOUT_WRITE_STACK : |
---|
146 | { |
---|
147 | // No access at the flag |
---|
148 | // * NONE_WITHOUT_WRITE_STACK : take and destination is know |
---|
149 | is_accurate = false; |
---|
150 | miss_decod = false; |
---|
151 | use_ras = true; |
---|
152 | |
---|
153 | PORT_WRITE(out_DECOD_RAS_PUSH [port],1); |
---|
154 | PORT_WRITE(out_DECOD_RAS_ADDRESS_PUSH [port],address_dest); |
---|
155 | |
---|
156 | break; |
---|
157 | } |
---|
158 | |
---|
159 | } |
---|
160 | |
---|
161 | if (use_btb) |
---|
162 | { |
---|
163 | if (_param->_have_port_context_id) |
---|
164 | PORT_WRITE(out_DECOD_BTB_CONTEXT_ID [port],context); |
---|
165 | PORT_WRITE(out_DECOD_BTB_ADDRESS_SRC [port],address_src); |
---|
166 | PORT_WRITE(out_DECOD_BTB_ADDRESS_DEST [port],address_dest); |
---|
167 | PORT_WRITE(out_DECOD_BTB_CONDITION [port],condition); |
---|
168 | PORT_WRITE(out_DECOD_BTB_LAST_TAKE [port],direction); |
---|
169 | PORT_WRITE(out_DECOD_BTB_MISS_PREDICTION [port],1); |
---|
170 | PORT_WRITE(out_DECOD_BTB_IS_ACCURATE [port],is_accurate); |
---|
171 | } |
---|
172 | if (use_ras) |
---|
173 | { |
---|
174 | miss_decod |= not PORT_READ(in_DECOD_RAS_HIT [port]); |
---|
175 | |
---|
176 | if (_param->_have_port_context_id) |
---|
177 | PORT_WRITE(out_DECOD_RAS_CONTEXT_ID [port],context); |
---|
178 | PORT_WRITE(out_DECOD_RAS_MISS_PREDICTION [port],1); |
---|
179 | } |
---|
180 | if (use_upt) |
---|
181 | { |
---|
182 | PORT_WRITE(out_DECOD_UPT_BTB_ADDRESS_SRC [port],address_src); |
---|
183 | PORT_WRITE(out_DECOD_UPT_BTB_ADDRESS_DEST [port],address_dest); |
---|
184 | PORT_WRITE(out_DECOD_UPT_BTB_CONDITION [port],condition); |
---|
185 | PORT_WRITE(out_DECOD_UPT_BTB_LAST_TAKE [port],direction); |
---|
186 | PORT_WRITE(out_DECOD_UPT_RAS_ADDRESS [port],PORT_READ(in_DECOD_RAS_ADDRESS_POP [port])); |
---|
187 | } |
---|
188 | } |
---|
189 | else |
---|
190 | { |
---|
191 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * hit"); |
---|
192 | |
---|
193 | miss_decod = false; |
---|
194 | // Hit speculation |
---|
195 | } |
---|
196 | |
---|
197 | // in all case |
---|
198 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * use_btb : %d",use_btb); |
---|
199 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * use_ras : %d",use_ras); |
---|
200 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * use_upt : %d",use_upt); |
---|
201 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * btb_ack [%d] : %d",port,PORT_READ(in_DECOD_BTB_ACK [port])); |
---|
202 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * ras_ack [%d] : %d",port,PORT_READ(in_DECOD_RAS_ACK [port])); |
---|
203 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * upt_ack [%d] : %d",port,PORT_READ(in_DECOD_UPT_ACK [port])); |
---|
204 | |
---|
205 | btb_val [port] = (use_btb and |
---|
206 | (not use_ras or (use_ras and PORT_READ(in_DECOD_RAS_ACK [port]))) and |
---|
207 | (not use_upt or (use_upt and PORT_READ(in_DECOD_UPT_ACK [port])))); |
---|
208 | |
---|
209 | ras_val [port] = (use_ras and |
---|
210 | (not use_btb or (use_btb and PORT_READ(in_DECOD_BTB_ACK [port]))) and |
---|
211 | (not use_upt or (use_upt and PORT_READ(in_DECOD_UPT_ACK [port])))); |
---|
212 | |
---|
213 | upt_val [port] = (use_upt and |
---|
214 | (not use_btb or (use_btb and PORT_READ(in_DECOD_BTB_ACK [port]))) and |
---|
215 | (not use_ras or (use_ras and PORT_READ(in_DECOD_RAS_ACK [port])))); |
---|
216 | |
---|
217 | if (use_btb) |
---|
218 | ack [i] &= btb_val [port] and PORT_READ(in_DECOD_BTB_ACK [port]); |
---|
219 | if (use_ras) |
---|
220 | ack [i] &= ras_val [port] and PORT_READ(in_DECOD_RAS_ACK [port]); |
---|
221 | if (use_upt) |
---|
222 | ack [i] &= upt_val [port] and PORT_READ(in_DECOD_UPT_ACK [port]); |
---|
223 | |
---|
224 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * btb_val [%d] : %d",port,btb_val [port]); |
---|
225 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * ras_val [%d] : %d",port,ras_val [port]); |
---|
226 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * upt_val [%d] : %d",port,upt_val [port]); |
---|
227 | log_printf(TRACE,Prediction_unit_Glue,FUNCTION," * ack [%d] : %d",i ,ack [i ]); |
---|
228 | |
---|
229 | if (_param->_have_port_context_id) |
---|
230 | PORT_WRITE(out_DECOD_UPT_CONTEXT_ID [port],context); |
---|
231 | PORT_WRITE(out_DECOD_UPT_MISS_IFETCH [port],miss_ifetch); |
---|
232 | PORT_WRITE(out_DECOD_UPT_MISS_DECOD [port],miss_decod ); |
---|
233 | if (_param->_have_port_max_depth) |
---|
234 | PORT_WRITE(out_DECOD_UPT_UPDATE_PREDICTION_ID [port],depth); |
---|
235 | |
---|
236 | port ++; |
---|
237 | } |
---|
238 | |
---|
239 | for (uint32_t i=0; i<_param->_nb_inst_branch_decod; i++) |
---|
240 | { |
---|
241 | PORT_WRITE(out_DECOD_BTB_VAL [i], btb_val [i]); |
---|
242 | PORT_WRITE(out_DECOD_RAS_VAL [i], ras_val [i]); |
---|
243 | PORT_WRITE(out_DECOD_UPT_VAL [i], upt_val [i]); |
---|
244 | } |
---|
245 | |
---|
246 | for (uint32_t i=0; i<_param->_nb_decod_unit; i++) |
---|
247 | for (uint32_t j=0; j<_param->_nb_inst_decod[i]; j++) |
---|
248 | if (i!= decod_unit) |
---|
249 | PORT_WRITE(out_DECOD_ACK [i][j], 0); |
---|
250 | else |
---|
251 | PORT_WRITE(out_DECOD_ACK [i][j], ack[j]); |
---|
252 | |
---|
253 | log_printf(FUNC,Prediction_unit_Glue,FUNCTION,"End"); |
---|
254 | }; |
---|
255 | |
---|
256 | }; // end namespace prediction_unit_glue |
---|
257 | }; // end namespace prediction_unit |
---|
258 | }; // end namespace front_end |
---|
259 | }; // end namespace multi_front_end |
---|
260 | }; // end namespace core |
---|
261 | |
---|
262 | }; // end namespace behavioural |
---|
263 | }; // end namespace morpheo |
---|
264 | #endif |
---|