source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Prediction_unit_Glue/src/Prediction_unit_Glue_genMealy_decod.cpp @ 111

Last change on this file since 111 was 110, checked in by rosiere, 15 years ago

1) OOO_egine : add stat to depiste low perf source
2) Commit : add stat
3) LSU_Pointer : retire - always ack (else combinatory loop). insert - max nb_inst_memory
4) TopLevel? : add debug_idle_time to stop combinatory loop.
5) Issue_queue : add reexecute_queue, new implementation (routage after issue_queue)
6) Decod / Predictor : add "can_continue"

File size: 11.7 KB
Line 
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
11namespace morpheo                    {
12namespace behavioural {
13namespace core {
14namespace multi_front_end {
15namespace front_end {
16namespace prediction_unit {
17namespace 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      {
53        log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"  * DECOD [%d][%d]",decod_unit,i);
54        log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * val  : %d",PORT_READ(in_DECOD_VAL [decod_unit][i]));
55        log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * port : %d",port);
56
57      // Test if decod_unit have detected a branch
58      if ((port>=_param->_nb_inst_branch_decod) or
59          (PORT_READ(in_DECOD_VAL [decod_unit][i]) == 0))
60        {
61          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"  * DECOD [%d][%d]          : not valid",decod_unit,i);
62          ack [i] = false;
63        }
64      else
65        {
66          Tcontext_t        context               = (_param->_have_port_context_id)?PORT_READ(in_DECOD_CONTEXT_ID [decod_unit][i]):0;
67          Tbranch_state_t   branch_state          = PORT_READ(in_DECOD_BRANCH_STATE          [decod_unit][i]);
68          Tcontrol_t        match_inst_ifetch_ptr = PORT_READ(in_DECOD_MATCH_INST_IFETCH_PTR [decod_unit][i]);
69          Tprediction_ptr_t depth                 = (_param->_have_port_depth)?PORT_READ(in_DECOD_BRANCH_UPDATE_PREDICTION_ID [decod_unit][i]):0;
70          Tcontrol_t        use_btb               = false;
71          Tcontrol_t        use_ras               = false;
72          Tcontrol_t        use_upt               = true ; // always update upt.
73
74          // Ifetch stage made an miss if :
75          //   * branch is previously predict, but it's not the good
76          Tcontrol_t        miss_ifetch           = ((branch_state != BRANCH_STATE_NONE) and (match_inst_ifetch_ptr == 0));
77          // Decod stage made an miss if :
78          //   * branch was not detected
79          Tcontrol_t        miss_decod            = (branch_state == BRANCH_STATE_NONE);
80          Tcontrol_t        can_continue          = false;
81
82          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"  * DECOD [%d][%d]          : valid",decod_unit,i);
83          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * branch_state          : %d",branch_state);
84          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * match_inst_ifetch_ptr : %d",match_inst_ifetch_ptr);
85          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * depth                 : [%d] %d",i,depth);
86          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * miss_ifetch           : %d",miss_ifetch);
87          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * miss_decod            : %d",miss_decod);
88
89          // Test if ifetch have detecte a branch is the packet
90          if (miss_ifetch or miss_decod)
91            {
92              Tbranch_condition_t condition    = PORT_READ(in_DECOD_BRANCH_CONDITION            [decod_unit][i]);
93              Tcontrol_t          take;
94              Taddress_t          address_src  = PORT_READ(in_DECOD_ADDRESS_SRC                 [decod_unit][i]);
95              Taddress_t          address_dest = PORT_READ(in_DECOD_ADDRESS_DEST                [decod_unit][i]);
96              Tcontrol_t          is_accurate;
97
98              // Miss speculation
99              use_btb = true;
100             
101              switch (condition)
102                {
103                case BRANCH_CONDITION_NONE_WITH_WRITE_STACK             :
104                  {
105                    // l.jal
106                    log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * BRANCH_CONDITION_NONE_WITH_WRITE_STACK");
107
108                    take        = true ;
109                    is_accurate = true ;//PORT_READ(in_DECOD_RAS_HIT [port]);
110                    use_ras     = true ;
111
112                    PORT_WRITE(out_DECOD_RAS_PUSH         [port],1);
113                    PORT_WRITE(out_DECOD_RAS_ADDRESS_PUSH [port],address_src+2);
114                   
115                    break;
116                  }
117
118                case BRANCH_CONDITION_READ_REGISTER_WITH_WRITE_STACK    :
119                  {
120                    // l.jalr
121                    log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * BRANCH_CONDITION_READ_REGISTER_WITH_WRITE_STACK");
122
123                    take        = true ;
124                    is_accurate = false; // address unknow : in a register
125                    use_ras     = true;
126
127                    PORT_WRITE(out_DECOD_RAS_PUSH         [port],1);
128                    PORT_WRITE(out_DECOD_RAS_ADDRESS_PUSH [port],address_src+2);
129                   
130                    break;
131                  }
132                case BRANCH_CONDITION_READ_STACK                        :
133                  {
134                    // l.jr with rb=r9
135                    log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * BRANCH_CONDITION_READ_STACK");
136
137                    take        = true ;
138                    is_accurate = PORT_READ(in_DECOD_RAS_HIT [port]);
139                    use_ras     = true;
140
141                    PORT_WRITE(out_DECOD_RAS_PUSH         [port],0); // POP
142                    address_dest = PORT_READ(in_DECOD_RAS_ADDRESS_POP [port]);
143                   
144                    break;
145                  }
146                case BRANCH_CONDITION_READ_REGISTER_WITHOUT_WRITE_STACK :
147                  {
148                    // l.jr with rb!=r9
149                    log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * BRANCH_CONDITION_READ_REGISTER_WITHOUT_WRITE_STACK");
150
151                    //   * READ_REGISTER_WITHOUT_WRITE_STACK : Take but destination is unknow - don't continue
152                    take        = true ;
153                    is_accurate = false; // address unknow : in a register
154
155                    break;
156                  }
157
158                case BRANCH_CONDITION_FLAG_UNSET                        :
159                case BRANCH_CONDITION_FLAG_SET                          :
160                  {
161                    // l.bf, l.bnf
162                    //   * FLAG                              : static direction and destination is know
163                    log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * BRANCH_CONDITION_FLAG");
164
165                    take        = PORT_READ(in_DECOD_BRANCH_DIRECTION [decod_unit][i]);
166                    is_accurate = true; // address dest is know
167
168                    break;
169                  }
170
171                case BRANCH_CONDITION_NONE_WITHOUT_WRITE_STACK          :
172                  {
173                    // l.j
174                    log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"      * BRANCH_CONDITION_NONE_WITHOUT_WRITE_STACK");
175
176                    take        = true;
177                    is_accurate = true;
178
179                    break;
180                  }
181                }
182
183              log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * take         : %d",take);
184
185              if (use_btb)
186                {
187                  if (_param->_have_port_context_id)
188                  PORT_WRITE(out_DECOD_BTB_CONTEXT_ID      [port],context);
189                  PORT_WRITE(out_DECOD_BTB_ADDRESS_SRC     [port],address_src);
190                  PORT_WRITE(out_DECOD_BTB_ADDRESS_DEST    [port],address_dest);
191                  PORT_WRITE(out_DECOD_BTB_CONDITION       [port],condition);
192                  PORT_WRITE(out_DECOD_BTB_LAST_TAKE       [port],take);
193                  PORT_WRITE(out_DECOD_BTB_MISS_PREDICTION [port],1);
194                  PORT_WRITE(out_DECOD_BTB_IS_ACCURATE     [port],is_accurate);
195                }
196              if (use_ras)
197                {
198                  miss_decod |= not PORT_READ(in_DECOD_RAS_HIT [port]);
199
200                  if (_param->_have_port_context_id)
201                  PORT_WRITE(out_DECOD_RAS_CONTEXT_ID      [port],context);
202                  PORT_WRITE(out_DECOD_RAS_MISS_PREDICTION [port],1);
203                }
204              if (use_upt)
205                {
206                  PORT_WRITE(out_DECOD_UPT_BTB_ADDRESS_SRC [port],address_src);
207                  PORT_WRITE(out_DECOD_UPT_BTB_ADDRESS_DEST[port],address_dest);
208                  PORT_WRITE(out_DECOD_UPT_BTB_CONDITION   [port],condition);
209                  PORT_WRITE(out_DECOD_UPT_BTB_LAST_TAKE   [port],take);
210                  PORT_WRITE(out_DECOD_UPT_RAS_ADDRESS     [port],PORT_READ(in_DECOD_RAS_ADDRESS_POP [port]));
211                  PORT_WRITE(out_DECOD_UPT_IS_ACCURATE     [port],is_accurate);
212                }
213
214              can_continue = false; // need update upt
215            }
216          else
217            {
218              log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * hit");
219
220              if (branch_state == BRANCH_STATE_SPEC_NTAKE)
221                can_continue = PORT_READ(in_DECOD_UPT_CAN_CONTINUE [port]);
222              else
223                // BRANCH_STATE_NONE       -> miss
224                // BRANCH_STATE_NSPEC_TAKE -> take
225                // BRANCH_STATE_SPEC_TAKE  -> take
226                can_continue = false;
227
228//            miss_decod = false;
229//            // Hit speculation
230            }
231         
232          // in all case
233          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * can_continue : %d",can_continue);
234          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * use_btb      : %d",use_btb);
235          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * use_ras      : %d",use_ras);
236          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * use_upt      : %d",use_upt);
237          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * btb_ack [%d] : %d",port,PORT_READ(in_DECOD_BTB_ACK [port]));
238          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * ras_ack [%d] : %d",port,PORT_READ(in_DECOD_RAS_ACK [port]));
239          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * upt_ack [%d] : %d",port,PORT_READ(in_DECOD_UPT_ACK [port]));
240 
241          btb_val [port] = (use_btb and
242                            (not use_ras or (use_ras and PORT_READ(in_DECOD_RAS_ACK [port]))) and
243                            (not use_upt or (use_upt and PORT_READ(in_DECOD_UPT_ACK [port]))));
244         
245          ras_val [port] = (use_ras and
246                            (not use_btb or (use_btb and PORT_READ(in_DECOD_BTB_ACK [port]))) and
247                            (not use_upt or (use_upt and PORT_READ(in_DECOD_UPT_ACK [port]))));
248         
249          upt_val [port] = (use_upt and
250                            (not use_btb or (use_btb and PORT_READ(in_DECOD_BTB_ACK [port]))) and
251                            (not use_ras or (use_ras and PORT_READ(in_DECOD_RAS_ACK [port]))));
252
253          if (use_btb)
254            ack [i] &= btb_val [port] and PORT_READ(in_DECOD_BTB_ACK [port]);
255          if (use_ras)
256            ack [i] &= ras_val [port] and PORT_READ(in_DECOD_RAS_ACK [port]);
257          if (use_upt)
258            ack [i] &= upt_val [port] and PORT_READ(in_DECOD_UPT_ACK [port]);
259         
260          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * btb_val [%d] : %d",port,btb_val [port]);
261          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * ras_val [%d] : %d",port,ras_val [port]);
262          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * upt_val [%d] : %d",port,upt_val [port]);
263          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * ack     [%d] : %d",i   ,ack     [i   ]);
264
265          if (_param->_have_port_context_id)
266          PORT_WRITE(out_DECOD_UPT_CONTEXT_ID           [port],context);
267          PORT_WRITE(out_DECOD_UPT_MISS_IFETCH          [port],miss_ifetch); 
268          PORT_WRITE(out_DECOD_UPT_MISS_DECOD           [port],miss_decod ); 
269          if (_param->_have_port_depth)
270          PORT_WRITE(out_DECOD_UPT_UPDATE_PREDICTION_ID [port],depth);
271          PORT_WRITE(out_DECOD_CAN_CONTINUE [decod_unit][i], can_continue);
272
273          port ++; // have find port
274        }
275      }
276   
277    // Write output
278    for (uint32_t i=0; i<_param->_nb_inst_branch_decod; i++)
279      {
280        PORT_WRITE(out_DECOD_BTB_VAL [i], btb_val [i]);
281        PORT_WRITE(out_DECOD_RAS_VAL [i], ras_val [i]);
282        PORT_WRITE(out_DECOD_UPT_VAL [i], upt_val [i]);
283      }
284
285    for (uint32_t i=0; i<_param->_nb_decod_unit; i++)
286      for (uint32_t j=0; j<_param->_nb_inst_decod[i]; j++)
287        if (i!= decod_unit)
288          PORT_WRITE(out_DECOD_ACK [i][j], 0);
289        else
290          PORT_WRITE(out_DECOD_ACK [i][j], ack[j]);
291      }
292    log_end(Prediction_unit_Glue,FUNCTION);
293  };
294
295}; // end namespace prediction_unit_glue
296}; // end namespace prediction_unit
297}; // end namespace front_end
298}; // end namespace multi_front_end
299}; // end namespace core
300
301}; // end namespace behavioural
302}; // end namespace morpheo             
303#endif
Note: See TracBrowser for help on using the repository browser.