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 @ 145

Last change on this file since 145 was 145, checked in by rosiere, 14 years ago

1) add test with SPECINT2K
2) new config of Selftest
3) modif RAT to support multiple depth_save ... but not finish (need fix Update Prediction Table)
4) add Function_pointer but need fix

File size: 12.0 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          = PORT_READ(in_DECOD_UPT_CAN_CONTINUE [port]);
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              can_continue &= not take;
216            }
217          else
218            {
219              log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * hit");
220
221//            can_continue = PORT_READ(in_DECOD_UPT_CAN_CONTINUE [port]);
222//            miss_decod = false;
223//            // Hit speculation
224            }
225         
226          // in all case
227          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * can_continue : %d",can_continue);
228          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * use_btb      : %d",use_btb);
229          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * use_ras      : %d",use_ras);
230          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * use_upt      : %d",use_upt);
231          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * btb_ack [%d] : %d",port,PORT_READ(in_DECOD_BTB_ACK [port]));
232          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * ras_ack [%d] : %d",port,PORT_READ(in_DECOD_RAS_ACK [port]));
233          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * upt_ack [%d] : %d",port,PORT_READ(in_DECOD_UPT_ACK [port]));
234 
235          btb_val [port] = (use_btb and
236                            (not use_ras or (use_ras and PORT_READ(in_DECOD_RAS_ACK [port]))) and
237                            (not use_upt or (use_upt and PORT_READ(in_DECOD_UPT_ACK [port]))));
238         
239          ras_val [port] = (use_ras and
240                            (not use_btb or (use_btb and PORT_READ(in_DECOD_BTB_ACK [port]))) and
241                            (not use_upt or (use_upt and PORT_READ(in_DECOD_UPT_ACK [port]))));
242         
243          upt_val [port] = (use_upt and
244                            (not use_btb or (use_btb and PORT_READ(in_DECOD_BTB_ACK [port]))) and
245                            (not use_ras or (use_ras and PORT_READ(in_DECOD_RAS_ACK [port]))));
246
247          if (use_btb)
248            ack [i] &= btb_val [port] and PORT_READ(in_DECOD_BTB_ACK [port]);
249          if (use_ras)
250            ack [i] &= ras_val [port] and PORT_READ(in_DECOD_RAS_ACK [port]);
251          if (use_upt)
252            ack [i] &= upt_val [port] and PORT_READ(in_DECOD_UPT_ACK [port]);
253         
254          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * btb_val [%d] : %d",port,btb_val [port]);
255          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * ras_val [%d] : %d",port,ras_val [port]);
256          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * upt_val [%d] : %d",port,upt_val [port]);
257          log_printf(TRACE,Prediction_unit_Glue,FUNCTION,"    * ack     [%d] : %d",i   ,ack     [i   ]);
258
259          if (_param->_have_port_context_id)
260          PORT_WRITE(out_DECOD_UPT_CONTEXT_ID           [port],context);
261          PORT_WRITE(out_DECOD_UPT_MISS_IFETCH          [port],miss_ifetch); 
262          PORT_WRITE(out_DECOD_UPT_MISS_DECOD           [port],miss_decod ); 
263          if (_param->_have_port_depth)
264          PORT_WRITE(out_DECOD_UPT_UPDATE_PREDICTION_ID [port],depth);
265          PORT_WRITE(out_DECOD_CAN_CONTINUE [decod_unit][i], can_continue);
266
267          port ++; // have find port
268        }
269      }
270   
271    // Write output
272    for (uint32_t i=0; i<_param->_nb_inst_branch_decod; i++)
273      {
274        PORT_WRITE(out_DECOD_BTB_VAL [i], btb_val [i]);
275        PORT_WRITE(out_DECOD_RAS_VAL [i], ras_val [i]);
276        PORT_WRITE(out_DECOD_UPT_VAL [i], upt_val [i]);
277      }
278
279    for (uint32_t i=0; i<_param->_nb_decod_unit; i++)
280      for (uint32_t j=0; j<_param->_nb_inst_decod[i]; j++)
281        if (i!= decod_unit)
282          PORT_WRITE(out_DECOD_ACK [i][j], 0);
283        else
284          PORT_WRITE(out_DECOD_ACK [i][j], ack[j]);
285      }
286    else
287      {
288        // Reset
289        for (uint32_t i=0; i<_param->_nb_inst_branch_decod; i++)
290          {
291            PORT_WRITE(out_DECOD_BTB_VAL [i], 0);
292            PORT_WRITE(out_DECOD_RAS_VAL [i], 0);
293            PORT_WRITE(out_DECOD_UPT_VAL [i], 0);
294          }
295       
296        for (uint32_t i=0; i<_param->_nb_decod_unit; i++)
297          for (uint32_t j=0; j<_param->_nb_inst_decod[i]; j++)
298            PORT_WRITE(out_DECOD_ACK [i][j], 0);
299      }
300    log_end(Prediction_unit_Glue,FUNCTION);
301  };
302
303}; // end namespace prediction_unit_glue
304}; // end namespace prediction_unit
305}; // end namespace front_end
306}; // end namespace multi_front_end
307}; // end namespace core
308
309}; // end namespace behavioural
310}; // end namespace morpheo             
311#endif
Note: See TracBrowser for help on using the repository browser.