source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Front_end/Front_end/Ifetch_unit/Ifetch_queue/src/Ifetch_queue_function_full_assoc_transition.cpp @ 136

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

1) Add new algo in ifetch queue
2) Add Cancel bit
3) new config

  • Property svn:keywords set to Id
File size: 9.2 KB
Line 
1#ifdef SYSTEMC
2/*
3 * $Id: Ifetch_queue_function_full_assoc_transition.cpp 136 2009-10-20 18:52:15Z rosiere $
4 *
5 * [ Description ]
6 *
7 */
8
9#include "Behavioural/Core/Multi_Front_end/Front_end/Ifetch_unit/Ifetch_queue/include/Ifetch_queue.h"
10
11namespace morpheo                    {
12namespace behavioural {
13namespace core {
14namespace multi_front_end {
15namespace front_end {
16namespace ifetch_unit {
17namespace ifetch_queue {
18
19
20#undef  FUNCTION
21#define FUNCTION "Ifetch_queue::function_full_assoc_transition"
22  void Ifetch_queue::function_full_assoc_transition (void)
23  {
24    log_begin(Ifetch_queue,FUNCTION);
25    log_function(Ifetch_queue,FUNCTION,_name.c_str());
26
27    if (PORT_READ(in_NRESET) == 0)
28      {
29        reg_PTR_READ  = 0;
30        reg_PTR_WRITE = 0;
31
32        for (uint32_t i=0; i<_param->_size_queue; i++)
33          {
34            _queue [i]->_state = IFETCH_QUEUE_STATE_EMPTY;
35            _queue [i]->_address                     = 0; // not necessary
36            _queue [i]->_inst_ifetch_ptr             = 0; // not necessary
37            _queue [i]->_branch_state                = 0; // not necessary
38            _queue [i]->_branch_update_prediction_id = 0; // not necessary
39            _queue [i]->_exception                   = 0; // not necessary
40
41            for (uint32_t j=0; j<_param->_nb_instruction; j++)
42              {
43            _queue [i]->_instruction             [j] = 0; // not necessary
44            _queue [i]->_instruction_enable      [j] = 0; // not necessary
45              }
46          }
47      }
48    else
49      {
50        // ==========================================================
51        // =====[ ADDRESS ]==========================================
52        // ==========================================================
53        if (PORT_READ(in_ADDRESS_VAL) and internal_ADDRESS_ACK)
54          {
55            log_printf(TRACE,Ifetch_queue,FUNCTION,"  * ADDRESS : Transaction");
56            log_printf(TRACE,Ifetch_queue,FUNCTION,"    * reg_PTR_WRITE : %d",reg_PTR_WRITE);
57            log_printf(TRACE,Ifetch_queue,FUNCTION,"    * ADDRESS       : 0x%x",PORT_READ(in_ADDRESS_INSTRUCTION_ADDRESS));
58
59            // New slot in ifetch_queue is allocated
60           
61            _queue[reg_PTR_WRITE]->_state = IFETCH_QUEUE_STATE_WAIT_RSP;
62             
63#ifdef STATISTICS
64            if (usage_is_set(_usage,USE_STATISTICS))
65              (*_sum_transaction_address) ++;
66#endif
67
68            for (uint32_t i=0; i<_param->_nb_instruction; i++)
69              {
70                Tcontrol_t enable = PORT_READ(in_ADDRESS_INSTRUCTION_ENABLE [i]);
71#ifdef STATISTICS
72                if (usage_is_set(_usage,USE_STATISTICS))
73                  (*_sum_inst_enable) += enable;
74#endif
75                _queue[reg_PTR_WRITE]->_instruction_enable [i]      = enable;
76              }
77
78            _queue[reg_PTR_WRITE]->_address                     = PORT_READ(in_ADDRESS_INSTRUCTION_ADDRESS);
79            _queue[reg_PTR_WRITE]->_inst_ifetch_ptr             = (_param->_have_port_inst_ifetch_ptr)?PORT_READ(in_ADDRESS_INST_IFETCH_PTR            ):0;
80            _queue[reg_PTR_WRITE]->_branch_state                = PORT_READ(in_ADDRESS_BRANCH_STATE);
81            _queue[reg_PTR_WRITE]->_branch_update_prediction_id = (_param->_have_port_depth)?PORT_READ(in_ADDRESS_BRANCH_UPDATE_PREDICTION_ID):0;
82           
83            reg_PTR_WRITE = (reg_PTR_WRITE+1)%_param->_size_queue;
84          }
85
86        // ==========================================================
87        // =====[ DECOD ]============================================
88        // ==========================================================
89        bool have_instruction_decod  = false;
90        bool have_instruction_enable = false;
91        uint32_t last_ptr = reg_PTR_READ;
92
93        for (uint32_t i=0; i<_param->_nb_instruction; ++i)
94          {
95            if (internal_DECOD_VAL [i] and PORT_READ(in_DECOD_ACK[i]))
96              {
97                log_printf(TRACE,Ifetch_queue,FUNCTION,"  * DECOD [%d] : Transaction",i);
98
99                uint32_t ptr  = internal_DECOD_PTR [i];
100                uint32_t slot = internal_DECOD_SLOT[i];
101
102                have_instruction_decod = true;
103                last_ptr               = ptr;
104
105                _queue[ptr]->_instruction_enable [slot] = false;
106              }
107            have_instruction_enable |= _queue[reg_PTR_READ]->_instruction_enable [i];
108          }
109
110        // Test if all is decoded
111        if (have_instruction_decod)
112          {
113            // Invalid all ptr
114            while (reg_PTR_READ != last_ptr)
115              {
116#ifdef DEBUG_TEST
117                bool have_instruction_enable = false;
118                for (uint32_t i=0; i<_param->_nb_instruction; ++i)
119                  have_instruction_enable |= _queue[reg_PTR_READ]->_instruction_enable [i];
120               
121                if (have_instruction_enable)
122                  throw ERRORMORPHEO(FUNCTION,toString("Can't free : Ifetch_queue[%d] content an valid instruction.\n",reg_PTR_READ));
123#endif
124               
125                _queue[reg_PTR_READ]->_state = IFETCH_QUEUE_STATE_EMPTY;
126                reg_PTR_READ = (reg_PTR_READ+1)%_param->_size_queue;
127              }
128           
129            // For last ptr, test if all instruction is disable
130            bool have_instruction_enable = false;
131            for (uint32_t i=0; i<_param->_nb_instruction; ++i)
132              have_instruction_enable |= _queue[reg_PTR_READ]->_instruction_enable [i];
133           
134            if (not have_instruction_enable)
135              {
136                _queue[reg_PTR_READ]->_state = IFETCH_QUEUE_STATE_EMPTY;
137                reg_PTR_READ = (reg_PTR_READ+1)%_param->_size_queue;
138              }
139          }
140         
141        // ==========================================================
142        // =====[ ICACHE_RSP ]=======================================
143        // ==========================================================
144        if (PORT_READ(in_ICACHE_RSP_VAL) and internal_ICACHE_RSP_ACK)
145          {
146            log_printf(TRACE,Ifetch_queue,FUNCTION,"  * ICACHE_RSP : Transaction");
147
148            Tpacket_t ptr = (_param->_have_port_ifetch_queue_ptr)?PORT_READ(in_ICACHE_RSP_PACKET_ID):0;
149           
150            for (uint32_t i=0; i<_param->_nb_instruction; i++)
151              _queue[ptr]->_instruction [i]      = PORT_READ(in_ICACHE_RSP_INSTRUCTION [i]);
152           
153            switch (PORT_READ(in_ICACHE_RSP_ERROR))
154              {
155              case ICACHE_ERROR_NONE      : _queue[ptr]->_exception = EXCEPTION_IFETCH_NONE     ; break;
156              case ICACHE_ERROR_BUS_ERROR : _queue[ptr]->_exception = EXCEPTION_IFETCH_BUS_ERROR; break;
157              default : throw ERRORMORPHEO(FUNCTION,"icache_rsp_error : unknow value.");
158              }
159
160            switch (_queue[ptr]->_state)
161              {
162              case IFETCH_QUEUE_STATE_WAIT_RSP       : _queue[ptr]->_state = IFETCH_QUEUE_STATE_HAVE_RSP; break;
163              case IFETCH_QUEUE_STATE_ERROR_WAIT_RSP : _queue[ptr]->_state = IFETCH_QUEUE_STATE_EMPTY   ; break;
164              default : throw ERRORMORPHEO(FUNCTION,"icache_rsp : invalid ifetch_queue state.");
165              }
166          }
167
168        // ==========================================================
169        // =====[ EVENT_RESET ]======================================
170        // ==========================================================
171        if (PORT_READ(in_EVENT_RESET_VAL) and internal_EVENT_RESET_ACK)
172          {
173            log_printf(TRACE,Ifetch_queue,FUNCTION,"  * EVENT_RESET : Transaction");
174
175            // Scan all entry of queue and test the status
176            for (uint32_t i=0; i<_param->_size_queue; i++)
177              switch (_queue[i]->_state)
178              {
179              case IFETCH_QUEUE_STATE_ERROR_WAIT_RSP :                                                        break;
180              case IFETCH_QUEUE_STATE_WAIT_RSP       : _queue[i]->_state = IFETCH_QUEUE_STATE_ERROR_WAIT_RSP; break;
181              default                                : _queue[i]->_state = IFETCH_QUEUE_STATE_EMPTY         ; break;
182              }
183
184            // all entry is empty (or wait respons to flush)
185            // reset ptr
186            //   1) reg_PTR_READ = reg_PTR_WRITE =  = 0
187            //   2) reg_PTR_READ = reg_PTR_WRITE
188            // In method 1), the probalitie than the entry pointed by reg_PTR_WRITE is a slot with state "error_wait_rsp" is more importate that the method 2)
189            reg_PTR_READ = reg_PTR_WRITE;
190          }
191
192#if defined(DEBUG) and (DEBUG >= DEBUG_TRACE)
193        log_printf(TRACE,Ifetch_queue,FUNCTION,"  * Dump ifetch_queue");
194        log_printf(TRACE,Ifetch_queue,FUNCTION,"    * reg_PTR_WRITE : %d",reg_PTR_WRITE);
195        log_printf(TRACE,Ifetch_queue,FUNCTION,"    * reg_PTR_READ  : %d",reg_PTR_READ );
196        for (uint32_t i=0; i<_param->_size_queue; i++)
197          {
198            log_printf(TRACE,Ifetch_queue,FUNCTION,"    * [%d] 0x%.8x (0x%.8x) %d - %d %d %d - %s",
199                       i, 
200                       _queue [i]->_address,
201                       _queue [i]->_address<<2,
202                       _queue [i]->_inst_ifetch_ptr,
203                       _queue [i]->_branch_state,
204                       _queue [i]->_branch_update_prediction_id,
205                       _queue [i]->_exception,
206                       toString(_queue [i]->_state).c_str()
207                       );
208           
209            for (uint32_t j=0; j<_param->_nb_instruction; j++)
210              log_printf(TRACE,Ifetch_queue,FUNCTION,"      * %d 0x%.8x", _queue [i]->_instruction_enable[j], _queue [i]->_instruction[j]);
211          }
212#endif
213
214#ifdef STATISTICS
215        if (usage_is_set(_usage,USE_STATISTICS))
216          for (uint32_t i=0; i<_param->_size_queue; i++)
217            switch (_queue[i]->_state)
218              {
219              case IFETCH_QUEUE_STATE_EMPTY          : break;
220              case IFETCH_QUEUE_STATE_WAIT_RSP       : (*_sum_use_queue_wait_rsp      ) ++; break;
221              case IFETCH_QUEUE_STATE_HAVE_RSP       : (*_sum_use_queue_have_rsp      ) ++; break;
222              case IFETCH_QUEUE_STATE_ERROR_WAIT_RSP : (*_sum_use_queue_error_wait_rsp) ++; break;
223              default : break;
224              }
225#endif
226      }
227
228    log_end(Ifetch_queue,FUNCTION);
229  };
230
231}; // end namespace ifetch_queue
232}; // end namespace ifetch_unit
233}; // end namespace front_end
234}; // end namespace multi_front_end
235}; // end namespace core
236
237}; // end namespace behavioural
238}; // end namespace morpheo             
239#endif
Note: See TracBrowser for help on using the repository browser.