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

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

1) Fix test in Direction_Glue for Conditionnal Branch
2) Fix Instruction Address Compute

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