source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/src/Return_Address_Stack_transition.cpp @ 95

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

1) Update Prediction Table - New architecture (systemC) done (and tested) -> need change interface in top level
2) Change documentation on VHDL generation
3) Change VHDL constant (case std_logic and std_logic_vector)

  • Property svn:keywords set to Id
File size: 9.9 KB
Line 
1#ifdef SYSTEMC
2/*
3 * $Id: Return_Address_Stack_transition.cpp 95 2008-12-16 16:24:26Z rosiere $
4 *
5 * [ Description ]
6 *
7 */
8
9#include "Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Return_Address_Stack/include/Return_Address_Stack.h"
10
11namespace morpheo                    {
12namespace behavioural {
13namespace core {
14namespace multi_front_end {
15namespace front_end {
16namespace prediction_unit {
17namespace return_address_stack {
18
19
20#undef  FUNCTION
21#define FUNCTION "Return_Address_Stack::transition"
22  void Return_Address_Stack::transition (void)
23  {
24    log_printf(FUNC,Return_Address_Stack,FUNCTION,"Begin");
25
26    if (PORT_READ(in_NRESET)==0)
27      {
28        for (uint32_t i=0; i<_param->_nb_context; i++)
29          {
30            reg_TOP    [i] = 0;
31            reg_BOTTOM [i] = 0;
32            reg_NB_ELT [i] = 0;
33
34            reg_PREDICT_TOP    [i] = 0;
35            reg_PREDICT_BOTTOM [i] = 0;
36            reg_PREDICT_NB_ELT [i] = 0;
37
38            for (uint32_t j=0; j<_param->_size_queue [i]; j++)
39              {
40                reg_stack[i][j]._val     = false;
41                reg_stack[i][j]._predict = false;
42                reg_stack[i][j]._miss    = false;
43              }
44          }
45      }
46    else
47      {
48        // ===================================================================
49        // =====[ PREDICT ]===================================================
50        // ===================================================================
51        for (uint32_t i=0; i<_param->_nb_inst_predict; i++)
52          if (PORT_READ(in_PREDICT_VAL [i]) and internal_PREDICT_ACK [i])
53            {
54              log_printf(TRACE,Return_Address_Stack,FUNCTION,"PREDICT[%d] : Transaction",i);
55              Tcontext_t context    = (_param->_have_port_context_id)?PORT_READ(in_PREDICT_CONTEXT_ID [i]):0;
56              Tcontrol_t push       = PORT_READ(in_PREDICT_PUSH [i]);
57              Tptr_t     top_old    = reg_PREDICT_TOP    [context];
58              Tptr_t     top_new    = top_old;
59              Tptr_t     bottom_old = reg_PREDICT_BOTTOM [context];
60
61              log_printf(TRACE,Return_Address_Stack,FUNCTION," * context : %d",context);
62
63              // Hit  : push or (val and not miss and not empty)
64              // Miss : ifetch is stall, no update
65              if (internal_PREDICT_HIT [i])
66                {
67                  log_printf(TRACE,Return_Address_Stack,FUNCTION," * before");
68                  log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_predict_top     : %d",reg_PREDICT_TOP    [context]);
69                  log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_predict_bottom  : %d",reg_PREDICT_BOTTOM [context]);
70                  log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_predict_nb_elt  : %d",reg_PREDICT_NB_ELT [context]);
71
72                  if (push)
73                    {
74                      // push : increase the top (circular)
75                      top_new = (top_old+1)%_param->_size_queue[context];
76                     
77                      reg_stack [context][top_new]._val     = true; // New addr
78                      reg_stack [context][top_new]._predict = true; // Is speculative (erase a old addr (or not))
79                    //reg_stack [context][top_new]._miss    = ;
80                      reg_stack [context][top_new]._address = PORT_READ(in_PREDICT_ADDRESS_PUSH [i]);
81
82                      // the stack is full, erase the most old stack
83
84                      // Test if full
85                      if (reg_PREDICT_NB_ELT[context]==_param->_size_queue[context])
86                        reg_PREDICT_BOTTOM [context] = (bottom_old+1)%_param->_size_queue[context];
87                      // A new data is write : the stack is not empty
88                      if (reg_PREDICT_NB_ELT[context]< _param->_size_queue[context])
89                        reg_PREDICT_NB_ELT[context]++;
90                    }
91                  else
92                    {
93                      // pop
94//                    top_new = (top_old==0)?(_param->_size_queue[context]-1):(top_old-1);
95                     
96                    //reg_stack [context][top_new]._val     = ;
97                    //reg_stack [context][top_new]._predict = ;
98                    //reg_stack [context][top_new]._miss    = ;
99                    //reg_stack [context][top_new]._address = ;
100
101                      // the stack is empty
102                      if (reg_PREDICT_NB_ELT[context]>0)
103                        {
104                          top_new = (top_old==0)?(_param->_size_queue[context]-1):(top_old-1);
105                          reg_PREDICT_NB_ELT[context] --;
106                        }
107                    }
108                 
109                  reg_PREDICT_TOP [context] = top_new;
110
111                  log_printf(TRACE,Return_Address_Stack,FUNCTION," * after");
112                  log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_predict_top     : %d",reg_PREDICT_TOP    [context]);
113                  log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_predict_bottom  : %d",reg_PREDICT_BOTTOM [context]);
114                  log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_predict_nb_elt  : %d",reg_PREDICT_NB_ELT [context]);
115                }
116            }
117
118        // ===================================================================
119        // =====[ DECOD ]=====================================================
120        // ===================================================================
121        for (uint32_t i=0; i<_param->_nb_inst_decod; i++)
122          if (PORT_READ(in_DECOD_VAL [i]) and internal_DECOD_ACK [i])
123            {
124              log_printf(TRACE,Return_Address_Stack,FUNCTION,"DECOD[%d] : Transaction",i);
125              Tcontext_t context    = (_param->_have_port_context_id)?PORT_READ(in_DECOD_CONTEXT_ID [i]):0;
126              Tcontrol_t push       = PORT_READ(in_DECOD_PUSH [i]);
127              Tptr_t     top_old    = reg_TOP    [context];
128              Tptr_t     top_new    = top_old;
129              Tptr_t     bottom_old = reg_BOTTOM [context];
130              //Tcontrol_t hit        = internal_DECOD_HIT [i];
131              Tcontrol_t miss       = PORT_READ(in_DECOD_MISS_PREDICTION [i]);
132
133              log_printf(TRACE,Return_Address_Stack,FUNCTION," * context : %d",context);
134
135              log_printf(TRACE,Return_Address_Stack,FUNCTION," * before");
136              log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_top     : %d",reg_TOP    [context]);
137              log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_bottom  : %d",reg_BOTTOM [context]);
138              log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_nb_elt  : %d",reg_NB_ELT [context]);
139
140              if (push)
141                {
142                  // push : increase the top (circular)
143                  top_new = (top_old+1)%_param->_size_queue[context];
144                 
145                  reg_stack [context][top_new]._val     = true;  // New address
146                  reg_stack [context][top_new]._predict = false; // No speculative
147                  reg_stack [context][top_new]._miss    = false;
148                  reg_stack [context][top_new]._address = PORT_READ(in_DECOD_ADDRESS_PUSH [i]);
149                 
150                  // Test if full : if true, then icrease the bottom (erase the most old stack)
151                  if (reg_NB_ELT[context]==_param->_size_queue[context])
152                    reg_BOTTOM [context] = (bottom_old+1)%_param->_size_queue[context];
153                  // A new data is write : the stack is not empty
154                  if (reg_NB_ELT[context]< _param->_size_queue[context])
155                    reg_NB_ELT[context]++;
156                }
157              else
158                {
159                  // pop
160//                top_new = (top_old==0)?(_param->_size_queue[context]-1):(top_old-1);
161
162                  //reg_stack [context][top_new]._val     = ;
163                  //reg_stack [context][top_new]._predict = ;
164                  //reg_stack [context][top_new]._miss    = ;
165                  //reg_stack [context][top_new]._address = ;
166                 
167                  // the stack is empty
168                  if (reg_NB_ELT[context]>0)
169                    {
170                      top_new = (top_old==0)?(_param->_size_queue[context]-1):(top_old-1);
171                      reg_NB_ELT[context] --;
172                    }
173                }
174             
175              reg_TOP [context] = top_new;
176             
177              log_printf(TRACE,Return_Address_Stack,FUNCTION," * after");
178              log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_top     : %d",reg_TOP    [context]);
179              log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_bottom  : %d",reg_BOTTOM [context]);
180              log_printf(TRACE,Return_Address_Stack,FUNCTION,"   * reg_nb_elt  : %d",reg_NB_ELT [context]);
181
182              // have previous miss of ifetch ?
183              // 2 miss :
184              //   1) miss predict : is very limited (local at context), can be update very quickly
185              //   2) miss decod   : result is in commit stage ...
186              if (miss)
187                {
188                  reg_PREDICT_BOTTOM [context] = reg_BOTTOM [context];
189                  reg_PREDICT_TOP    [context] = reg_TOP    [context];
190                  reg_PREDICT_NB_ELT [context] = reg_NB_ELT [context];
191                 
192                  // Scan full assoc !!!
193                  for (uint32_t j=0; j<_param->_size_queue [context]; j++)
194                    // Test if this slot is tagged with "predict" : if true, tagged as miss
195                    if (reg_stack [context][j]._predict)
196                      {
197                        reg_stack [context][j]._predict = false;
198                        reg_stack [context][j]._miss    = true;
199                      }
200                }
201            }
202
203        // ===================================================================
204        // =====[ UPDATE ]===================================================
205        // ===================================================================
206        for (uint32_t i=0; i<_param->_nb_inst_update; i++)
207          if (PORT_READ(in_UPDATE_VAL [i]) and internal_UPDATE_ACK [i])
208            {
209              throw ERRORMORPHEO(FUNCTION,"Fonction à implémenter !!!!!!!!!!!!");
210             
211
212//            Tcontrol_t miss   = PORT_READ(in_UPDATE_MISS_PREDICTION [i]);
213//            //
214//            if (miss)
215//              {
216//                Tcontrol_t context = (_param->_have_port_context_id)?PORT_READ(in_UPDATE_CONTEXT_ID [i]):0;
217//                Tcontrol_t ifetch  = PORT_READ(in_UPDATE_PREDICTION_IFETCH [i]);
218//                Tcontrol_t push    = PORT_READ(in_UPDATE_PUSH             [i]);
219//                Tcontrol_t flush   = PORT_READ(in_UPDATE_FLUSH            [i]);
220//                Tptr_t     index   = PORT_READ(in_UPDATE_INDEX            [i]);
221//                Taddress_t address = PORT_READ(in_UPDATE_ADDRESS          [i]);
222                 
223//                if (push)
224//                  {
225// //                 // push
226// //                 top_new = (top_old+1)%_param->_size_queue[context];
227                     
228// //                 reg_stack [context][index]._val     = true;
229// //                 reg_stack [context][index]._predict = false;
230// //                 reg_stack [context][index]._miss    = false;
231// //                 reg_stack [context][index]._address = PORT_READ(in_UPDATE_ADDRESS [i]);
232
233//                  }
234//                else
235//                  {
236// //               //reg_stack [context][top_new]._val     = ;
237// //               //reg_stack [context][top_new]._predict = ;
238// //               //reg_stack [context][top_new]._miss    = ;
239// //               //reg_stack [context][top_new]._address = ;
240//                  }
241                 
242// // //                  // Mouais bof .......
243// // //                  reg_PREDICT_TOP [context] = index;
244//              }
245            }
246      }
247
248#if defined(STATISTICS) or defined(VHDL_TESTBENCH)
249    end_cycle ();
250#endif
251
252    log_printf(FUNC,Return_Address_Stack,FUNCTION,"End");
253  };
254
255}; // end namespace return_address_stack
256}; // end namespace prediction_unit
257}; // end namespace front_end
258}; // end namespace multi_front_end
259}; // end namespace core
260
261}; // end namespace behavioural
262}; // end namespace morpheo             
263#endif
Note: See TracBrowser for help on using the repository browser.