source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Direction/Meta_Predictor/Two_Level_Branch_Predictor/src/Two_Level_Branch_Predictor_transition.cpp @ 124

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

1) Add test and configuration
2) Fix Bug
3) Add log file in load store unit
4) Fix Bug in environment

  • Property svn:keywords set to Id
File size: 11.2 KB
Line 
1#ifdef SYSTEMC
2/*
3 * $Id: Two_Level_Branch_Predictor_transition.cpp 124 2009-06-17 12:11:25Z rosiere $
4 *
5 * [ Description ]
6 *
7 */
8
9#include "Behavioural/Core/Multi_Front_end/Front_end/Prediction_unit/Direction/Meta_Predictor/Two_Level_Branch_Predictor/include/Two_Level_Branch_Predictor.h"
10// #include <assert.h>
11
12namespace morpheo                    {
13namespace behavioural {
14namespace core {
15namespace multi_front_end {
16namespace front_end {
17namespace prediction_unit {
18namespace direction {
19namespace meta_predictor {
20namespace two_level_branch_predictor {
21
22
23#undef  FUNCTION
24#define FUNCTION "Two_Level_Branch_Predictor::transition"
25  void Two_Level_Branch_Predictor::transition (void)
26  {
27    log_begin(Two_Level_Branch_Predictor,FUNCTION);
28    log_function(Two_Level_Branch_Predictor,FUNCTION,_name.c_str());
29
30    if (PORT_READ(in_NRESET) == 0)
31      {
32      }
33    else
34      {
35        // ===================================================================
36        // =====[ PREDICT ]===================================================
37        // ===================================================================
38
39        for (uint32_t i=0; i<_param->_nb_inst_predict; ++i)
40          if (PORT_READ(in_PREDICT_VAL[i]) and internal_PREDICT_ACK[i])
41            {
42              log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"  * PREDICT [%d]",i);
43
44              // Predict if
45              //  * update_on_prediction and direction is valid
46              if (_param->_update_on_prediction)
47                if (PORT_READ(in_PREDICT_DIRECTION_VAL [i]))
48                  {
49                    Tcontrol_t direction = PORT_READ(in_PREDICT_DIRECTION [i]);
50                   
51                    if (_param->_have_bht)
52                      {
53                        Thistory_t bht_num_reg = internal_PREDICT_BHT_NUM_REG [i];
54                        log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"  * bht_num_reg      : %lld",bht_num_reg);
55
56// #ifdef DEBUG_TEST
57//                         assert(bht_num_reg < _param->_bht_nb_shifter);
58// #endif
59
60                        Thistory_t bht_history = reg_BHT[bht_num_reg];
61                        log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"  * bht_history (old): %llx",bht_history);
62
63                       
64                        bht_history = ((bht_history<<1) | direction)&_param->_bht_history_mask ;
65                        log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"  * bht_history (new): %llx",bht_history);
66                        reg_BHT [bht_num_reg] = bht_history;
67                      }
68
69                    if (_param->_have_pht)
70                      {
71                        Thistory_t pht_num_reg = internal_PREDICT_PHT_NUM_REG  [i];
72                        Thistory_t pht_num_bank= internal_PREDICT_PHT_NUM_BANK [i];
73                        log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"  * pht_num_reg      : %lld",pht_num_reg);
74                        log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"  * pht_num_bank     : %lld",pht_num_bank);
75
76                        Thistory_t pht_history = reg_PHT [pht_num_bank][pht_num_reg];
77                        log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"  * pht_history (old): %llx",pht_history);
78                       
79                        // PHT : saturation counter
80                        pht_history = (direction==1)?((pht_history<_param->_pht_counter_max)?(pht_history+1):(pht_history)):((pht_history>0)?(pht_history-1):(pht_history));
81                       
82                        log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"  * pht_history (new): %llx",pht_history);
83                       
84                        reg_PHT [pht_num_bank][pht_num_reg] = pht_history;
85                      }
86                  }
87            }       
88
89        // ===================================================================
90        // =====[ UPDATE ]====================================================
91        // ===================================================================
92       
93        for (uint32_t i=0; i<_param->_nb_inst_update; ++i)
94          if (PORT_READ(in_UPDATE_VAL[i]) and internal_UPDATE_ACK[i])
95            {
96              log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"  * UPDATE [%d]",i);
97              if (_param->_update_on_prediction)
98              log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"  * miss             : %d",PORT_READ(in_UPDATE_MISS [i]));
99              log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"  * update_on_predict: %d",_param->_update_on_prediction);
100             
101              // Update if
102              //  * update_on_prediction and miss
103              //  * not update_on_prediction
104              Tcontrol_t history_val = PORT_READ(in_UPDATE_HISTORY_VAL [i]);
105
106              if (not _param->_update_on_prediction or
107                  (_param->_update_on_prediction and PORT_READ(in_UPDATE_MISS [i])) or
108                  not history_val // static_prediction
109                  )
110                {
111                  Taddress_t address     = PORT_READ(in_UPDATE_ADDRESS     [i]);
112                  Thistory_t history     = PORT_READ(in_UPDATE_HISTORY     [i]);
113                  Tcontrol_t direction   = PORT_READ(in_UPDATE_DIRECTION   [i])&1;
114
115                  log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"  * address          : %.8x",address);
116                  log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"  * direction        : %d",direction);
117                  log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"  * history_val      : %d",direction);
118
119                  Thistory_t pht_bht_history = 0;
120
121                  if (_param->_have_bht)
122                    {
123                      log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"  * bht");
124
125                      Thistory_t bht_history = (history>>_param->_bht_history_shift )&_param->_bht_history_mask;
126                      Thistory_t bht_num_reg = address & _param->_bht_address_mask;
127                     
128                      log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"    * bht_history (old): %llx",bht_history);
129                      log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"    * bht_num_reg      : %llx",bht_num_reg);
130                     
131                      // BHT : shift register
132                      if (not history_val)
133                        {
134                          bht_history = (direction)?_param->_bht_init_take:_param->_bht_init_ntake;
135                        }
136                      else
137                        {
138                          bht_history = ((bht_history<<1) | direction)&_param->_bht_history_mask ;
139                        }
140                       
141                      pht_bht_history = bht_history;
142                      log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"    * bht_history (new): %llx",bht_history);
143
144// #ifdef DEBUG_TEST
145//                         assert(bht_num_reg < _param->_bht_nb_shifter);
146// #endif
147
148                      reg_BHT [bht_num_reg]               = bht_history;
149                    }
150
151                  if (_param->_have_pht)
152                    {
153                      log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"  * pht");
154
155                      Thistory_t pht_history = (history>>_param->_pht_history_shift )&_param->_pht_history_mask;
156                      Thistory_t pht_num_bank= (address>>_param->_pht_address_bank_shift )&_param->_pht_address_bank_mask;
157                      Thistory_t pht_num_reg = pht_bht_history xor ((address&_param->_pht_address_share_mask)<<_param->_pht_address_share_shift);
158                     
159                      log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"    * bht_history (old): %llx",pht_bht_history);
160                      log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"    * pht_history (old): %llx",pht_history);
161                      log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"    * pht_num_reg      : %llx",pht_num_reg);
162                      log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"    * pht_num_bank     : %llx",pht_num_bank);
163                     
164                      // PHT : saturation counter
165                      if (not history_val)
166                        {
167                          pht_history = (direction)?_param->_pht_init_take:_param->_pht_init_ntake;
168                        }
169                      else
170                        {
171                          pht_history = (direction==1)?((pht_history<_param->_pht_counter_max)?(pht_history+1):(pht_history)):((pht_history>0)?(pht_history-1):(pht_history));
172                        }
173                     
174                      log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"    * pht_history (new): %llx",pht_history);
175                     
176                      reg_PHT [pht_num_bank][pht_num_reg] = pht_history;
177                    }
178                }
179            }
180      }
181
182#if defined(DEBUG) and DEBUG_Two_Level_Branch_Predictor and (DEBUG >= DEBUG_TRACE)
183
184# if 0
185    {
186      log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"  * Dump Two_Level_Branch_Predictor");
187
188      if (_param->_have_bht)
189        {
190          log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"  * Dump BHT");
191
192          uint32_t limit = 4;
193
194          for (uint32_t i=0; i<_param->_bht_nb_shifter; i+=limit)
195            {
196              std::string str = "";
197
198              for (uint32_t j=0; j<limit; j++)
199                {
200                  uint32_t index = i+j;
201                  if (index >= _param->_bht_nb_shifter)
202                    break;
203                  else
204                    {
205                      str+=toString("[%.4d] %.4x ",index,reg_BHT[index]);
206                    }
207                }
208             
209              log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"    %s",str.c_str());
210            }
211        }
212
213      if (_param->_have_pht)
214        {
215          log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"  * Dump PHT");
216
217          uint32_t limit = 4;
218
219          for (uint32_t num_bank=0; num_bank <_param->_pht_nb_bank; ++num_bank)
220            {
221              if (_param->_pht_size_bank == 1)
222                {
223                  log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"  [%.4d][0000] %4x",num_bank,reg_PHT[num_bank][0]);
224                }
225              else
226                {
227                  log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"  [%.4d]",num_bank);
228                 
229                  for (uint32_t i=0; i<_param->_pht_size_bank; i+=limit)
230                    {
231                      std::string str = "";
232                     
233                      for (uint32_t j=0; j<limit; j++)
234                        {
235                          uint32_t index = i+j;
236                          if (index >= _param->_pht_size_bank)
237                            break;
238                          else
239                            str+=toString("[%.4d] %.4x ",index,reg_PHT[num_bank][index]);
240                        }
241                     
242                      log_printf(TRACE,Two_Level_Branch_Predictor,FUNCTION,"    %s",str.c_str());
243                    }
244                }
245            }
246        }
247    }
248# endif
249#endif
250
251#if defined(STATISTICS) or defined(VHDL_TESTBENCH)
252    end_cycle ();
253#endif
254
255    log_end(Two_Level_Branch_Predictor,FUNCTION);
256  };
257
258}; // end namespace two_level_branch_predictor
259}; // end namespace meta_predictor
260}; // end namespace direction
261}; // end namespace prediction_unit
262}; // end namespace front_end
263}; // end namespace multi_front_end
264}; // end namespace core
265
266}; // end namespace behavioural
267}; // end namespace morpheo             
268#endif
Note: See TracBrowser for help on using the repository browser.