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

Last change on this file since 88 was 88, checked in by rosiere, 16 years ago

Almost complete design
with Test and test platform

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