source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Decod_unit/Decod/src/Decod_genMealy.cpp @ 120

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

1) Context_state : Add statistics
2) Add configuration with multi front_end
3) Add optionnal pid at log filename

  • Property svn:keywords set to Id
File size: 14.4 KB
Line 
1#ifdef SYSTEMC
2/*
3 * $Id: Decod_genMealy.cpp 120 2009-05-26 19:01:47Z rosiere $
4 *
5 * [ Description ]
6 *
7 */
8
9#include "Behavioural/Core/Multi_Front_end/Front_end/Decod_unit/Decod/include/Decod.h"
10
11namespace morpheo                    {
12namespace behavioural {
13namespace core {
14namespace multi_front_end {
15namespace front_end {
16namespace decod_unit {
17namespace decod {
18
19
20#undef  FUNCTION
21#define FUNCTION "Decod::genMealy"
22  void Decod::genMealy (void)
23  {
24    log_begin(Decod,FUNCTION);
25    log_function(Decod,FUNCTION,_name.c_str());
26
27    //-----------------------------------
28    // Initialization
29    //-----------------------------------
30    Tcontrol_t context_event_val = false;
31    Tcontrol_t ifetch_ack [_param->_nb_context][_param->_max_nb_inst_fetch];
32    for (uint32_t i=0; i<_param->_nb_context; i++)
33      for (uint32_t j=0; j<_param->_nb_inst_fetch[i]; j++)
34        ifetch_ack [i][j] = false;
35
36    Tcontrol_t predict_val [_param->_nb_inst_decod];
37    Tcontrol_t decod_val   [_param->_nb_inst_decod];
38    for (uint32_t i=0; i<_param->_nb_inst_decod; i++)
39      {
40        decod_val   [i] = false;
41        predict_val [i] = false;
42      }
43
44    Tcontrol_t can_continue      [_param->_nb_context];
45    Tcontrol_t have_decod_branch [_param->_nb_context];
46
47    for (uint32_t i=0; i<_param->_nb_context; i++)
48      {
49        internal_CONTEXT_HAVE_TRANSACTION [i] = false;
50        internal_CONTEXT_ADDRESS_PREVIOUS [i] = reg_CONTEXT_ADDRESS_PREVIOUS [i];
51        internal_CONTEXT_IS_DELAY_SLOT    [i] = reg_CONTEXT_IS_DELAY_SLOT    [i];
52       
53        can_continue                      [i] = PORT_READ(in_CONTEXT_DECOD_ENABLE [i]);
54        have_decod_branch                 [i] = false;
55      }
56   
57    //-----------------------------------
58    // Loop of decod
59    //-----------------------------------
60    // scan all decod "slot_out"
61    std::list<generic::priority::select_t> * select = _priority->select();
62    std::list<generic::priority::select_t>::iterator it=select->begin();
63    for (uint32_t i=0; i<_param->_nb_inst_decod; i++)
64      {
65        log_printf(TRACE,Decod,FUNCTION,"  * DECOD [%d]",i);   
66
67        while ((it != select->end())    and  // have a no scanned "slot_in" ?
68               (decod_val [i] == false) and  // have not a previous selected entry?
69               (context_event_val == false)) // Have not a context_event (spr_access, exception, ...)
70          {
71//          predict_val [i] = false;
72
73            Tcontext_t x = it->grp;
74            uint32_t   y = it->elt;
75
76            log_printf(TRACE,Decod,FUNCTION,"    * IFETCH [%d][%d]",x,y);   
77            log_printf(TRACE,Decod,FUNCTION,"      * in_IFETCH_VAL          : %d",PORT_READ(in_IFETCH_VAL [x][y]));
78            log_printf(TRACE,Decod,FUNCTION,"      * can_continue           : %d",can_continue [x]               );
79
80            // Test if this instruction is valid
81            if ((PORT_READ(in_IFETCH_VAL [x][y]) == 1) and // entry is valid
82                (can_continue [x]                == 1))    // context can decod instruction (have not a previous event)
83              {
84                log_printf(TRACE,Decod,FUNCTION,"      * decod_ack              : %d",PORT_READ(in_DECOD_ACK [i]));
85
86                decod_val  [i]    = true;                        // fetch_val and decod_enable
87                ifetch_ack [x][y] = PORT_READ(in_DECOD_ACK [i]); // fetch_val and decod_enable and decod_ack
88
89                Tgeneral_data_t addr = PORT_READ(in_IFETCH_ADDRESS [x])+y;
90
91                _decod_instruction->_instruction      = PORT_READ(in_IFETCH_INSTRUCTION [x][y]);
92                _decod_instruction->_context_id       = x;
93                _decod_instruction->_address_previous = internal_CONTEXT_ADDRESS_PREVIOUS [x];
94                _decod_instruction->_address          = addr; //Compute the current address
95                _decod_instruction->_address_next     = addr+1;
96                _decod_instruction->_is_delay_slot    = internal_CONTEXT_IS_DELAY_SLOT [x];
97
98                // Test IFetch exception
99                Texception_t ifetch_exception = PORT_READ(in_IFETCH_EXCEPTION [x]);
100
101                if (ifetch_exception == EXCEPTION_IFETCH_NONE)
102                  {
103                    // Decod !
104                    log_printf(TRACE,Decod,FUNCTION,"      * address                : %.8x (%.8x)",addr,(addr<<2));
105                    log_printf(TRACE,Decod,FUNCTION,"      * is_delay_slot          : %d",internal_CONTEXT_IS_DELAY_SLOT [x]);
106                   
107                    instruction_decod (_decod_instruction, _decod_param[x]);
108
109                    log_printf(TRACE,Decod,FUNCTION,"      * address_next           : %.8x (%.8x)",_decod_instruction->_address_next,(_decod_instruction->_address_next<<2));
110                  }
111                else
112                  {
113                    // No decod : nop
114                    instruction_l_nop (_decod_instruction, _decod_param[x]);
115
116                    _decod_instruction->_exception_use = EXCEPTION_USE_NONE;
117                    _decod_instruction->_exception     = exception_ifetch_to_exception_decod(ifetch_exception);
118                   
119                    // INSTRUCTION_TLB 
120                    // INSTRUCTION_PAGE
121                    // BUS_ERROR       
122                    if (_decod_instruction->_is_delay_slot)
123                      _decod_instruction->_address_next       = _decod_instruction->_address_previous;
124                    else
125                      _decod_instruction->_address_next       = _decod_instruction->_address;
126                   
127                    _decod_instruction->_event_type         = EVENT_TYPE_EXCEPTION;
128                  }
129
130                Ttype_t      type      = _decod_instruction->_type;
131                // Depth current. If have decod a branch and i can continue : depth = depth_next
132                Tdepth_t     depth     = (_param->_have_port_depth)?PORT_READ(in_CONTEXT_DEPTH [x]):0;
133
134                if ((_param->_nb_branch_speculated[x] > 0) and have_decod_branch [x])
135                  depth = (depth+1)%_param->_nb_branch_speculated[x];
136               
137                if (_param->_have_port_context_id)
138                PORT_WRITE(out_DECOD_CONTEXT_ID    [i], x);
139                if (_param->_have_port_depth)
140                PORT_WRITE(out_DECOD_DEPTH         [i], depth);
141                PORT_WRITE(out_DECOD_TYPE          [i], type);
142                PORT_WRITE(out_DECOD_OPERATION     [i], _decod_instruction->_operation     );
143                PORT_WRITE(out_DECOD_NO_EXECUTE    [i], _decod_instruction->_no_execute    );
144                PORT_WRITE(out_DECOD_IS_DELAY_SLOT [i], _decod_instruction->_is_delay_slot );
145#ifdef DEBUG
146                PORT_WRITE(out_DECOD_ADDRESS       [i], addr);
147#endif
148//                 if ((type == TYPE_BRANCH) and
149//                     ((_decod_instruction->_branch_condition = BRANCH_CONDITION_FLAG_SET) or
150//                      (_decod_instruction->_branch_condition = BRANCH_CONDITION_FLAG_UNSET)))
151//                 PORT_WRITE(out_DECOD_ADDRESS_NEXT  [i], _decod_instruction->_address+2);
152//                 else
153                PORT_WRITE(out_DECOD_ADDRESS_NEXT  [i], _decod_instruction->_address_next  );
154                PORT_WRITE(out_DECOD_HAS_IMMEDIAT  [i], _decod_instruction->_has_immediat  );
155                PORT_WRITE(out_DECOD_IMMEDIAT      [i], _decod_instruction->_immediat      );
156                PORT_WRITE(out_DECOD_READ_RA       [i], _decod_instruction->_read_ra       );
157                PORT_WRITE(out_DECOD_NUM_REG_RA    [i], _decod_instruction->_num_reg_ra    );
158                PORT_WRITE(out_DECOD_READ_RB       [i], _decod_instruction->_read_rb       );
159                PORT_WRITE(out_DECOD_NUM_REG_RB    [i], _decod_instruction->_num_reg_rb    );
160                PORT_WRITE(out_DECOD_READ_RC       [i], _decod_instruction->_read_rc       );
161                PORT_WRITE(out_DECOD_NUM_REG_RC    [i], _decod_instruction->_num_reg_rc    );
162                PORT_WRITE(out_DECOD_WRITE_RD      [i],(_decod_instruction->_num_reg_rd!=0)?_decod_instruction->_write_rd:0);
163                PORT_WRITE(out_DECOD_NUM_REG_RD    [i], _decod_instruction->_num_reg_rd    );
164                PORT_WRITE(out_DECOD_WRITE_RE      [i], _decod_instruction->_write_re      );
165                PORT_WRITE(out_DECOD_NUM_REG_RE    [i], _decod_instruction->_num_reg_re    );
166                PORT_WRITE(out_DECOD_EXCEPTION_USE [i], _decod_instruction->_exception_use );
167//              PORT_WRITE(out_DECOD_EXCEPTION     [i], _decod_instruction->_exception     );
168
169                // Branch predictor can accept : the depth is valid
170                log_printf(TRACE,Decod,FUNCTION,"      * context_depth_val      : %d",PORT_READ(in_CONTEXT_DEPTH_VAL [x]));
171                decod_val   [i]    &= PORT_READ(in_CONTEXT_DEPTH_VAL [x]);
172                ifetch_ack  [x][y] &= PORT_READ(in_CONTEXT_DEPTH_VAL [x]);
173
174                if (type == TYPE_BRANCH)
175                  {
176                    log_printf(TRACE,Decod,FUNCTION,"      * Instruction is branch");
177                    log_printf(TRACE,Decod,FUNCTION,"        * predict_val       : %d",ifetch_ack [x][y]);
178                    log_printf(TRACE,Decod,FUNCTION,"        * predict_ack       : %d",PORT_READ(in_PREDICT_ACK [i]));
179                                                         
180                    log_printf(TRACE,Decod,FUNCTION,"        * address src       : %.8x (%.8x)",_decod_instruction->_address     ,_decod_instruction->_address     <<2);
181                    log_printf(TRACE,Decod,FUNCTION,"        * address dest      : %.8x (%.8x)",_decod_instruction->_address_next,_decod_instruction->_address_next<<2);
182                   
183                    // test if have already decod an branch : one branch per context
184                    predict_val [i]     = not have_decod_branch [x] and ifetch_ack  [x][y] // and decod_val [i]
185                      ;
186                    decod_val   [i]    &= not have_decod_branch [x] and PORT_READ(in_PREDICT_ACK [i]);// predict_ack and fetch_val and decod_enable                 
187                    ifetch_ack  [x][y] &= not have_decod_branch [x] and PORT_READ(in_PREDICT_ACK [i]);// predict_ack and fetch_val and decod_enable and decod_ack
188               
189                    if (_param->_have_port_context_id)
190                    PORT_WRITE(out_PREDICT_CONTEXT_ID                  [i],x);
191                    PORT_WRITE(out_PREDICT_MATCH_INST_IFETCH_PTR       [i],y == ((_param->_have_port_inst_ifetch_ptr)?PORT_READ(in_IFETCH_INST_IFETCH_PTR [x]):0));
192                    PORT_WRITE(out_PREDICT_BRANCH_STATE                [i],PORT_READ(in_IFETCH_BRANCH_STATE                [x]));
193                    if (_param->_have_port_depth)
194                    PORT_WRITE(out_PREDICT_BRANCH_UPDATE_PREDICTION_ID [i],PORT_READ(in_IFETCH_BRANCH_UPDATE_PREDICTION_ID [x]));
195                    PORT_WRITE(out_PREDICT_BRANCH_CONDITION            [i],_decod_instruction->_branch_condition  );
196//                  PORT_WRITE(out_PREDICT_BRANCH_STACK_WRITE          [i],_decod_instruction->_branch_stack_write);
197                    PORT_WRITE(out_PREDICT_BRANCH_DIRECTION            [i],_decod_instruction->_branch_direction  );
198                    PORT_WRITE(out_PREDICT_ADDRESS_SRC                 [i],_decod_instruction->_address           );
199                    PORT_WRITE(out_PREDICT_ADDRESS_DEST                [i],_decod_instruction->_address_next      );
200               
201                    // can continue is set if direction is "not take" (also, continue is sequential order)
202
203//                  can_continue [x] = false; // one branch per context, the DS don't execute
204                    can_continue [x]&= PORT_READ(in_PREDICT_CAN_CONTINUE [i]); // one branch per context, the DS don't execute
205                    have_decod_branch [x] = true;
206                   
207                    log_printf(TRACE,Decod,FUNCTION,"      * predict_can_continue   : %d",PORT_READ(in_PREDICT_CAN_CONTINUE [i]));
208                  }
209
210                Tevent_type_t event_type = _decod_instruction->_event_type;
211                if (event_type != EVENT_TYPE_NONE)
212                  {
213                    log_printf(TRACE,Decod,FUNCTION,"      * Instruction make an EVENT (%s)",toString(event_type).c_str());
214                    log_printf(TRACE,Decod,FUNCTION,"        * context_event_ack : %d",PORT_READ(in_CONTEXT_EVENT_ACK));
215
216                    // speculative jump at the exception handler
217                    // if type = TYPE_BRANCH, also event_type == EVENT_TYPE_NONE
218                    context_event_val   = ifetch_ack  [x][y] // and decod_val [i]
219                      ;
220                    decod_val   [i]    &= PORT_READ(in_CONTEXT_EVENT_ACK);// context_event_ack and fetch_val and decod_enable             
221                    ifetch_ack  [x][y] &= PORT_READ(in_CONTEXT_EVENT_ACK);// context_event_ack and fetch_val and decod_enable and decod_ack
222
223                    if (_param->_have_port_context_id)
224                    PORT_WRITE(out_CONTEXT_EVENT_CONTEXT_ID   , x);
225                    if (_param->_have_port_depth)
226                    PORT_WRITE(out_CONTEXT_EVENT_DEPTH        , depth);
227                    PORT_WRITE(out_CONTEXT_EVENT_TYPE         , _decod_instruction->_event_type    );
228                    PORT_WRITE(out_CONTEXT_EVENT_IS_DELAY_SLOT, _decod_instruction->_is_delay_slot );
229                    PORT_WRITE(out_CONTEXT_EVENT_ADDRESS      , _decod_instruction->_address       );
230                    PORT_WRITE(out_CONTEXT_EVENT_ADDRESS_EPCR , _decod_instruction->_address_next  );
231                  }
232
233                // fetch_ack =
234                //   ((event_type == EVENT_TYPE_NONE) or ((event_type != EVENT_TYPE_NONE) and context_event_ack)) and
235                //   ((type       == TYPE_BRANCH    ) or ((type       != TYPE_BRANCH    ) and predict_ack      )) and
236                //   fetch_val and decod_ack and decod_enable and true (is decod_val)
237
238                // To compute the "next previous" address
239                Tcontrol_t have_transaction = ifetch_ack [x][y];
240
241                internal_CONTEXT_HAVE_TRANSACTION [x] |= have_transaction;
242                if (have_transaction)
243                  {
244                    internal_CONTEXT_ADDRESS_PREVIOUS [x] = addr;
245                    internal_CONTEXT_IS_DELAY_SLOT    [x] = (type == TYPE_BRANCH); // next is a delay slot if current have branch type
246                  }
247
248                can_continue [x] &= have_transaction; // to have a in order decod !!! if a previous instruction can decod, also next instruction can't decod.
249
250                log_printf(TRACE,Decod,FUNCTION,"      * have_transaction       : %d",have_transaction);
251
252              }
253
254            log_printf(TRACE,Decod,FUNCTION,"    - num_(decod, context, fetch) : %d %d %d",i, x, y);
255            log_printf(TRACE,Decod,FUNCTION,"      - ifetch_ack             : %d",ifetch_ack  [x][y]);
256            log_printf(TRACE,Decod,FUNCTION,"      - context_event_val      : %d",context_event_val );
257            log_printf(TRACE,Decod,FUNCTION,"      - predict_val            : %d",predict_val [i]   );
258            log_printf(TRACE,Decod,FUNCTION,"      - decod_val              : %d",decod_val   [i]   );
259           
260            it ++;
261          }
262      }
263    //-----------------------------------
264    // Write output
265    //-----------------------------------
266
267    for (uint32_t i=0; i<_param->_nb_context; i++)
268      for (uint32_t j=0; j<_param->_nb_inst_fetch[i]; j++)
269        PORT_WRITE(out_IFETCH_ACK [i][j], ifetch_ack [i][j]);
270
271    PORT_WRITE(out_CONTEXT_EVENT_VAL, context_event_val);
272
273    for (uint32_t i=0; i<_param->_nb_inst_decod; i++)
274      {
275        PORT_WRITE(out_PREDICT_VAL [i], predict_val [i]);
276        PORT_WRITE(out_DECOD_VAL   [i], decod_val   [i]);
277       
278#ifdef STATISTICS
279        internal_DECOD_VAL [i] = decod_val [i];
280#endif
281      }
282
283    log_end(Decod,FUNCTION);
284  };
285
286}; // end namespace decod
287}; // end namespace decod_unit
288}; // end namespace front_end
289}; // end namespace multi_front_end
290}; // end namespace core
291
292}; // end namespace behavioural
293}; // end namespace morpheo             
294#endif
Note: See TracBrowser for help on using the repository browser.