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

Last change on this file since 141 was 141, checked in by rosiere, 14 years ago

Add statistics in stage IFETCH, DECODE and COMMIT (insert, retire and commit)

  • Property svn:keywords set to Id
File size: 8.4 KB
Line 
1#ifdef SYSTEMC
2/*
3 * $Id: Ifetch_queue_function_no_assoc_transition.cpp 141 2010-08-02 18:56:05Z 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_no_assoc_transition"
22  void Ifetch_queue::function_no_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#ifdef STATISTICS
54        uint32_t stat_nb_inst_fetch=0;
55#endif
56
57        if (PORT_READ(in_ADDRESS_VAL) and internal_ADDRESS_ACK)
58          {
59            log_printf(TRACE,Ifetch_queue,FUNCTION,"  * ADDRESS : Transaction");
60            log_printf(TRACE,Ifetch_queue,FUNCTION,"    * reg_PTR_WRITE : %d",reg_PTR_WRITE);
61            log_printf(TRACE,Ifetch_queue,FUNCTION,"    * ADDRESS       : 0x%x",PORT_READ(in_ADDRESS_INSTRUCTION_ADDRESS));
62
63            // New slot in ifetch_queue is allocated
64           
65            _queue[reg_PTR_WRITE]->_state = IFETCH_QUEUE_STATE_WAIT_RSP;
66             
67#ifdef STATISTICS
68            if (usage_is_set(_usage,USE_STATISTICS))
69              (*_sum_transaction_address) ++;
70#endif
71
72            for (uint32_t i=0; i<_param->_nb_instruction; i++)
73              {
74                Tcontrol_t enable = PORT_READ(in_ADDRESS_INSTRUCTION_ENABLE [i]);
75#ifdef STATISTICS
76                 stat_nb_inst_fetch += enable;
77#endif
78                _queue[reg_PTR_WRITE]->_instruction_enable [i]      = enable;
79              }
80
81            _queue[reg_PTR_WRITE]->_address                     = PORT_READ(in_ADDRESS_INSTRUCTION_ADDRESS);
82            _queue[reg_PTR_WRITE]->_inst_ifetch_ptr             = (_param->_have_port_inst_ifetch_ptr)?PORT_READ(in_ADDRESS_INST_IFETCH_PTR            ):0;
83            _queue[reg_PTR_WRITE]->_branch_state                = PORT_READ(in_ADDRESS_BRANCH_STATE);
84            _queue[reg_PTR_WRITE]->_branch_update_prediction_id = (_param->_have_port_depth)?PORT_READ(in_ADDRESS_BRANCH_UPDATE_PREDICTION_ID):0;
85           
86            reg_PTR_WRITE = (reg_PTR_WRITE+1)%_param->_size_queue;
87          }
88#ifdef STATISTICS
89        if (usage_is_set(_usage,USE_STATISTICS))
90          (*_stat_nb_inst_fetch) += stat_nb_inst_fetch;
91#endif
92
93        // ==========================================================
94        // =====[ DECOD ]============================================
95        // ==========================================================
96        bool have_instruction_decod  = false;
97        bool have_instruction_enable = false;
98        for (uint32_t i=0; i<_param->_nb_instruction; i++)
99          {
100            if (internal_DECOD_VAL [i] and PORT_READ(in_DECOD_ACK[i]))
101              {
102                log_printf(TRACE,Ifetch_queue,FUNCTION,"  * DECOD [%d] : Transaction",i);
103
104                have_instruction_decod = true;
105                _queue[reg_PTR_READ]->_instruction_enable [i] = 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 and not have_instruction_enable)
112          {
113            // all is decod
114            _queue[reg_PTR_READ]->_state = IFETCH_QUEUE_STATE_EMPTY;
115            reg_PTR_READ = (reg_PTR_READ+1)%_param->_size_queue;
116          }
117         
118        // ==========================================================
119        // =====[ ICACHE_RSP ]=======================================
120        // ==========================================================
121        if (PORT_READ(in_ICACHE_RSP_VAL) and internal_ICACHE_RSP_ACK)
122          {
123            log_printf(TRACE,Ifetch_queue,FUNCTION,"  * ICACHE_RSP : Transaction");
124
125            Tpacket_t ptr = (_param->_have_port_ifetch_queue_ptr)?PORT_READ(in_ICACHE_RSP_PACKET_ID):0;
126           
127            for (uint32_t i=0; i<_param->_nb_instruction; i++)
128              _queue[ptr]->_instruction [i]      = PORT_READ(in_ICACHE_RSP_INSTRUCTION [i]);
129           
130            switch (PORT_READ(in_ICACHE_RSP_ERROR))
131              {
132              case ICACHE_ERROR_NONE      : _queue[ptr]->_exception = EXCEPTION_IFETCH_NONE     ; break;
133              case ICACHE_ERROR_BUS_ERROR : _queue[ptr]->_exception = EXCEPTION_IFETCH_BUS_ERROR; break;
134              default : ERRORMORPHEO(FUNCTION,"icache_rsp_error : unknow value.");
135              }
136
137            switch (_queue[ptr]->_state)
138              {
139              case IFETCH_QUEUE_STATE_WAIT_RSP       : _queue[ptr]->_state = IFETCH_QUEUE_STATE_HAVE_RSP; break;
140              case IFETCH_QUEUE_STATE_ERROR_WAIT_RSP : _queue[ptr]->_state = IFETCH_QUEUE_STATE_EMPTY   ; break;
141              default : ERRORMORPHEO(FUNCTION,"icache_rsp : invalid ifetch_queue state.");
142              }
143          }
144
145        // ==========================================================
146        // =====[ EVENT_RESET ]======================================
147        // ==========================================================
148        if (PORT_READ(in_EVENT_RESET_VAL) and internal_EVENT_RESET_ACK)
149          {
150            log_printf(TRACE,Ifetch_queue,FUNCTION,"  * EVENT_RESET : Transaction");
151
152            // Scan all entry of queue and test the status
153            for (uint32_t i=0; i<_param->_size_queue; i++)
154              switch (_queue[i]->_state)
155              {
156              case IFETCH_QUEUE_STATE_ERROR_WAIT_RSP :                                                        break;
157              case IFETCH_QUEUE_STATE_WAIT_RSP       : _queue[i]->_state = IFETCH_QUEUE_STATE_ERROR_WAIT_RSP; break;
158              default                                : _queue[i]->_state = IFETCH_QUEUE_STATE_EMPTY         ; break;
159              }
160
161            // all entry is empty (or wait respons to flush)
162            // reset ptr
163            //   1) reg_PTR_READ = reg_PTR_WRITE =  = 0
164            //   2) reg_PTR_READ = reg_PTR_WRITE
165            // 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)
166            reg_PTR_READ = reg_PTR_WRITE;
167          }
168
169#if defined(DEBUG) and (DEBUG >= DEBUG_TRACE)
170        log_printf(TRACE,Ifetch_queue,FUNCTION,"  * Dump ifetch_queue");
171        log_printf(TRACE,Ifetch_queue,FUNCTION,"    * reg_PTR_WRITE : %d",reg_PTR_WRITE);
172        log_printf(TRACE,Ifetch_queue,FUNCTION,"    * reg_PTR_READ  : %d",reg_PTR_READ );
173        for (uint32_t i=0; i<_param->_size_queue; i++)
174          {
175            log_printf(TRACE,Ifetch_queue,FUNCTION,"    * [%d] 0x%.8x (0x%.8x) %d - %d %d %d - %s",
176                       i, 
177                       _queue [i]->_address,
178                       _queue [i]->_address<<2,
179                       _queue [i]->_inst_ifetch_ptr,
180                       _queue [i]->_branch_state,
181                       _queue [i]->_branch_update_prediction_id,
182                       _queue [i]->_exception,
183                       toString(_queue [i]->_state).c_str()
184                       );
185           
186            for (uint32_t j=0; j<_param->_nb_instruction; j++)
187              log_printf(TRACE,Ifetch_queue,FUNCTION,"      * %d 0x%.8x", _queue [i]->_instruction_enable[j], _queue [i]->_instruction[j]);
188          }
189#endif
190
191#ifdef STATISTICS
192        if (usage_is_set(_usage,USE_STATISTICS))
193          for (uint32_t i=0; i<_param->_size_queue; i++)
194            switch (_queue[i]->_state)
195              {
196              case IFETCH_QUEUE_STATE_EMPTY          : break;
197              case IFETCH_QUEUE_STATE_WAIT_RSP       : (*_sum_use_queue_wait_rsp      ) ++; break;
198              case IFETCH_QUEUE_STATE_HAVE_RSP       : (*_sum_use_queue_have_rsp      ) ++; break;
199              case IFETCH_QUEUE_STATE_ERROR_WAIT_RSP : (*_sum_use_queue_error_wait_rsp) ++; break;
200              default : break;
201              }
202#endif
203      }
204
205    log_end(Ifetch_queue,FUNCTION);
206  };
207
208}; // end namespace ifetch_queue
209}; // end namespace ifetch_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.