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

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

Decod :

  • Correct selftest
  • Set Instruction address on (32/64)-2 bits,
  • Decod Custom Instruction : valid and tested. (add an test to verify the decod information)
  • Property svn:keywords set to Id
File size: 9.2 KB
Line 
1#ifdef SYSTEMC
2/*
3 * $Id: Decod_genMealy.cpp 86 2008-05-14 17:08:56Z 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_printf(TRACE,Decod,FUNCTION,"Begin");
25
26    //-----------------------------------
27    // Initialization
28    //-----------------------------------
29    Tcontrol_t context_event_val = false;
30    Tcontrol_t ifetch_ack [_param->_nb_context][_param->_max_nb_inst_fetch];
31    for (uint32_t i=0; i<_param->_nb_context; i++)
32      for (uint32_t j=0; j<_param->_nb_inst_fetch[i]; j++)
33        ifetch_ack [i][j] = false;
34
35    Tcontrol_t predict_val [_param->_nb_inst_decod];
36    Tcontrol_t decod_val   [_param->_nb_inst_decod];
37    for (uint32_t i=0; i<_param->_nb_inst_decod; i++)
38      {
39        decod_val   [i] = false;
40      }
41
42    Tcontrol_t can_continue      [_param->_nb_context];
43    Tcontrol_t can_continue_next [_param->_nb_context];   
44
45    for (uint32_t i=0; i<_param->_nb_context; i++)
46      {
47        internal_CONTEXT_HAVE_TRANSACTION [i] = false;
48        internal_CONTEXT_ADDRESS_PREVIOUS [i] = reg_CONTEXT_ADDRESS_PREVIOUS [i];
49        internal_CONTEXT_IS_DELAY_SLOT    [i] = reg_CONTEXT_IS_DELAY_SLOT    [i];
50
51        can_continue                      [i] = PORT_READ(in_CONTEXT_DECOD_ENABLE [i]);
52        can_continue_next                 [i] = PORT_READ(in_CONTEXT_DECOD_ENABLE [i]);
53      }
54   
55    //-----------------------------------
56    // Loop of decod
57    //-----------------------------------
58    // scan all decod "slot_out"
59    std::list<select_t>::iterator it=select.begin();
60    for (uint32_t i=0; i<_param->_nb_inst_decod; i++)
61      {
62        while ((it != select.end())     and  // have a no scanned "slot_in" ?
63               (decod_val [i] == false) and  // have not a previous selected entry?
64               (context_event_val == false)) // Have not a context_event (spr_access, exception, ...)
65          {
66            predict_val [i] = false;
67            context_event_val = false;
68
69            Tcontext_t x = it->_context ;
70            uint32_t   y = it->_inst_fetch;
71
72            // Test if this instruction is valid
73            if ((PORT_READ(in_IFETCH_VAL [x][y]) == 1) and // entry is valid
74                (can_continue [x]                == 1))    // context can decod instruction (have not a previous event)
75              {
76                can_continue      [x] = can_continue_next [x];
77
78                decod_val  [i]    = true;                        // fetch_val and decod_enable
79                ifetch_ack [x][y] = PORT_READ(in_DECOD_ACK [i]); // fetch_val and decod_enable and decod_ack
80
81                Tgeneral_data_t addr = PORT_READ(in_IFETCH_ADDRESS [x])+y;
82
83                _decod_instruction->_instruction      = PORT_READ(in_IFETCH_INSTRUCTION [x][y]);
84                _decod_instruction->_context_id       = x;
85                _decod_instruction->_address_previous = internal_CONTEXT_ADDRESS_PREVIOUS [x];
86                _decod_instruction->_address          = addr; //Compute the current address
87                _decod_instruction->_address_next     = addr+1;
88                _decod_instruction->_is_delay_slot    = internal_CONTEXT_IS_DELAY_SLOT [x];
89
90                // Decod !
91                log_printf(TRACE,Decod,FUNCTION,"DECOD [%d]",i);
92                log_printf(TRACE,Decod,FUNCTION,"  * context       : %d",x);
93                log_printf(TRACE,Decod,FUNCTION,"  * fetch         : %d",y);
94                log_printf(TRACE,Decod,FUNCTION,"  * address       : %.8x",addr);
95                log_printf(TRACE,Decod,FUNCTION,"  * is_delay_slot : %d",internal_CONTEXT_IS_DELAY_SLOT [x]);
96
97                instruction_decod (_decod_instruction, _decod_param[x]);
98
99                Ttype_t type = _decod_instruction->_type;
100
101                if (_param->_have_port_context_id)
102                PORT_WRITE(out_DECOD_CONTEXT_ID    [i], x);
103                if (_param->_have_port_depth)
104                PORT_WRITE(out_DECOD_DEPTH         [i], PORT_READ(in_CONTEXT_DEPTH [x]));
105                PORT_WRITE(out_DECOD_TYPE          [i], type);
106                PORT_WRITE(out_DECOD_OPERATION     [i], _decod_instruction->_operation     );
107                PORT_WRITE(out_DECOD_IS_DELAY_SLOT [i], _decod_instruction->_is_delay_slot );
108                PORT_WRITE(out_DECOD_ADDRESS       [i], addr);
109                PORT_WRITE(out_DECOD_HAS_IMMEDIAT  [i], _decod_instruction->_has_immediat  );
110                PORT_WRITE(out_DECOD_IMMEDIAT      [i], _decod_instruction->_immediat      );
111                PORT_WRITE(out_DECOD_READ_RA       [i], _decod_instruction->_read_ra       );
112                PORT_WRITE(out_DECOD_NUM_REG_RA    [i], _decod_instruction->_num_reg_ra    );
113                PORT_WRITE(out_DECOD_READ_RB       [i], _decod_instruction->_read_rb       );
114                PORT_WRITE(out_DECOD_NUM_REG_RB    [i], _decod_instruction->_num_reg_rb    );
115                PORT_WRITE(out_DECOD_READ_RC       [i], _decod_instruction->_read_rc       );
116                PORT_WRITE(out_DECOD_NUM_REG_RC    [i], _decod_instruction->_num_reg_rc    );
117                PORT_WRITE(out_DECOD_WRITE_RD      [i], _decod_instruction->_write_rd      );
118                PORT_WRITE(out_DECOD_NUM_REG_RD    [i], _decod_instruction->_num_reg_rd    );
119                PORT_WRITE(out_DECOD_WRITE_RE      [i], _decod_instruction->_write_re      );
120                PORT_WRITE(out_DECOD_NUM_REG_RE    [i], _decod_instruction->_num_reg_re    );
121                PORT_WRITE(out_DECOD_EXCEPTION_USE [i], _decod_instruction->_exception_use );
122
123                if (type == TYPE_BRANCH)
124                  {
125                    predict_val [i]     = ifetch_ack  [x][y] // and decod_val [i]
126                      ;
127                    decod_val   [i]    &= PORT_READ(in_PREDICT_ACK [i]);// predict_ack and fetch_val and decod_enable               
128                    ifetch_ack  [x][y] &= PORT_READ(in_PREDICT_ACK [i]);// predict_ack and fetch_val and decod_enable and decod_ack
129
130                    if (_param->_have_port_context_id)
131                    PORT_WRITE(out_PREDICT_CONTEXT_ID                  [i],x);
132                    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));
133                    PORT_WRITE(out_PREDICT_BRANCH_STATE                [i],PORT_READ(in_IFETCH_BRANCH_STATE                [x]));
134                    if (_param->_have_port_branch_update_prediction_id)
135                    PORT_WRITE(out_PREDICT_BRANCH_UPDATE_PREDICTION_ID [i],PORT_READ(in_IFETCH_BRANCH_UPDATE_PREDICTION_ID [x]));
136                    PORT_WRITE(out_PREDICT_BRANCH_CONDITION            [i],_decod_instruction->_branch_condition  );
137//                  PORT_WRITE(out_PREDICT_BRANCH_STACK_WRITE          [i],_decod_instruction->_branch_stack_write);
138                    PORT_WRITE(out_PREDICT_BRANCH_DIRECTION            [i],_decod_instruction->_branch_direction  );
139                    PORT_WRITE(out_PREDICT_ADDRESS_SRC                 [i],_decod_instruction->_address           );
140                    PORT_WRITE(out_PREDICT_ADDRESS_DEST                [i],_decod_instruction->_address_next      );
141               
142                    //can_continue_next [x] = PORT_READ(in_PREDICT_CAN_CONTINUE [i]); // can continue is set if direction is "not take" (also, continue is sequential order)
143                    can_continue_next [x] = false; // one branch per context
144                  }
145
146                Tevent_type_t event_type = _decod_instruction->_event_type;
147                if (event_type != EVENT_TYPE_NONE)
148                  {
149                    // speculative jump at the exception handler
150                    // if type = TYPE_BRANCH, also event_type == EVENT_TYPE_NONE
151                    context_event_val   = ifetch_ack  [x][y] // and decod_val [i]
152                      ;
153                    decod_val   [i]    &= PORT_READ(in_CONTEXT_EVENT_ACK);// context_event_ack and fetch_val and decod_enable             
154                    ifetch_ack  [x][y] &= PORT_READ(in_CONTEXT_EVENT_ACK);// context_event_ack and fetch_val and decod_enable and decod_ack
155
156                    if (_param->_have_port_context_id)
157                    PORT_WRITE(out_CONTEXT_EVENT_CONTEXT_ID   , x);
158                    PORT_WRITE(out_CONTEXT_EVENT_TYPE         , _decod_instruction->_event_type    );
159                    PORT_WRITE(out_CONTEXT_EVENT_IS_DELAY_SLOT, _decod_instruction->_is_delay_slot );
160                    PORT_WRITE(out_CONTEXT_EVENT_ADDRESS      , _decod_instruction->_address       );
161                    PORT_WRITE(out_CONTEXT_EVENT_ADDRESS_EPCR , _decod_instruction->_address_next  );
162                  }
163
164                // fetch_ack =
165                //   ((event_type == EVENT_TYPE_NONE) or ((event_type != EVENT_TYPE_NONE) and context_event_ack)) and
166                //   ((type       == TYPE_BRANCH    ) or ((type       != TYPE_BRANCH    ) and predict_ack      )) and
167                //   fetch_val and decod_ack and decod_enable and true (is decod_val)
168
169                // To compute the "next previous" address
170                Tcontrol_t have_transaction = ifetch_ack [x][y];
171
172                internal_CONTEXT_HAVE_TRANSACTION [x] |= have_transaction;
173                if (have_transaction)
174                  {
175#ifdef STATISTICS
176                    (*_stat_sum_inst_decod) ++;
177#endif
178                    internal_CONTEXT_ADDRESS_PREVIOUS [x] = addr;
179                    internal_CONTEXT_IS_DELAY_SLOT    [x] = (type == TYPE_BRANCH); // next is a delay slot if current have branch type
180                  }
181
182                can_continue [x] &= have_transaction; // to have a in order decod !!! if a previous instruction can decod, also next instruction can't decod.
183              }
184           
185            it ++;
186          }
187      }
188
189    //-----------------------------------
190    // Write output
191    //-----------------------------------
192
193    for (uint32_t i=0; i<_param->_nb_context; i++)
194      for (uint32_t j=0; j<_param->_nb_inst_fetch[i]; j++)
195        PORT_WRITE(out_IFETCH_ACK [i][j], ifetch_ack [i][j]);
196
197    PORT_WRITE(out_CONTEXT_EVENT_VAL, context_event_val);
198
199    for (uint32_t i=0; i<_param->_nb_inst_decod; i++)
200      {
201        PORT_WRITE(out_PREDICT_VAL [i], predict_val [i]);
202        PORT_WRITE(out_DECOD_VAL   [i], decod_val   [i]);
203      }
204
205    log_printf(FUNC,Decod,FUNCTION,"End");
206  };
207
208}; // end namespace decod
209}; // end namespace decod_unit
210}; // end namespace front_end
211}; // end namespace multi_front_end
212}; // end namespace core
213
214}; // end namespace behavioural
215}; // end namespace morpheo             
216#endif
Note: See TracBrowser for help on using the repository browser.