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 @ 145

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

1) add test with SPECINT2K
2) new config of Selftest
3) modif RAT to support multiple depth_save ... but not finish (need fix Update Prediction Table)
4) add Function_pointer but need fix

  • Property svn:keywords set to Id
File size: 9.5 KB
Line 
1#ifdef SYSTEMC
2/*
3 * $Id: Ifetch_queue_function_full_assoc_transition.cpp 145 2010-10-13 18:15:51Z 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#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
89#ifdef STATISTICS
90        if (usage_is_set(_usage,USE_STATISTICS))
91          (*_stat_nb_inst_fetch)+=stat_nb_inst_fetch;
92#endif
93
94
95        // ==========================================================
96        // =====[ DECOD ]============================================
97        // ==========================================================
98        bool have_instruction_decod  = false;
99        bool have_instruction_enable = false;
100        uint32_t last_ptr = reg_PTR_READ;
101
102        for (uint32_t i=0; i<_param->_nb_instruction; ++i)
103          {
104            if (internal_DECOD_VAL [i] and PORT_READ(in_DECOD_ACK[i]))
105              {
106                log_printf(TRACE,Ifetch_queue,FUNCTION,"  * DECOD [%d] : Transaction",i);
107
108                uint32_t ptr  = internal_DECOD_PTR [i];
109                uint32_t slot = internal_DECOD_SLOT[i];
110
111                have_instruction_decod = true;
112                last_ptr               = ptr;
113
114                _queue[ptr]->_instruction_enable [slot] = false;
115              }
116            have_instruction_enable |= _queue[reg_PTR_READ]->_instruction_enable [i];
117          }
118
119        // Test if all is decoded
120        if (have_instruction_decod)
121          {
122            // Invalid all ptr
123            while (reg_PTR_READ != last_ptr)
124              {
125#ifdef DEBUG_TEST
126                bool have_instruction_enable = false;
127                for (uint32_t i=0; i<_param->_nb_instruction; ++i)
128                  have_instruction_enable |= _queue[reg_PTR_READ]->_instruction_enable [i];
129               
130                if (have_instruction_enable)
131                  throw ERRORMORPHEO(FUNCTION,toString("Can't free : Ifetch_queue[%d] content an valid instruction.\n",reg_PTR_READ));
132#endif
133               
134                _queue[reg_PTR_READ]->_state = IFETCH_QUEUE_STATE_EMPTY;
135                reg_PTR_READ = (reg_PTR_READ+1)%_param->_size_queue;
136              }
137           
138            // For last ptr, test if all instruction is disable
139            bool have_instruction_enable = false;
140            for (uint32_t i=0; i<_param->_nb_instruction; ++i)
141              have_instruction_enable |= _queue[reg_PTR_READ]->_instruction_enable [i];
142           
143            if (not have_instruction_enable)
144              {
145                _queue[reg_PTR_READ]->_state = IFETCH_QUEUE_STATE_EMPTY;
146                reg_PTR_READ = (reg_PTR_READ+1)%_param->_size_queue;
147              }
148          }
149         
150        // ==========================================================
151        // =====[ ICACHE_RSP ]=======================================
152        // ==========================================================
153        if (PORT_READ(in_ICACHE_RSP_VAL) and internal_ICACHE_RSP_ACK)
154          {
155            log_printf(TRACE,Ifetch_queue,FUNCTION,"  * ICACHE_RSP : Transaction");
156
157            Tpacket_t ptr = (_param->_have_port_ifetch_queue_ptr)?PORT_READ(in_ICACHE_RSP_PACKET_ID):0;
158           
159            for (uint32_t i=0; i<_param->_nb_instruction; i++)
160              _queue[ptr]->_instruction [i]      = PORT_READ(in_ICACHE_RSP_INSTRUCTION [i]);
161           
162            switch (PORT_READ(in_ICACHE_RSP_ERROR))
163              {
164              case ICACHE_ERROR_NONE      : _queue[ptr]->_exception = EXCEPTION_IFETCH_NONE     ; break;
165              case ICACHE_ERROR_BUS_ERROR : _queue[ptr]->_exception = EXCEPTION_IFETCH_BUS_ERROR; break;
166              default : throw ERRORMORPHEO(FUNCTION,"icache_rsp_error : unknow value.");
167              }
168
169            switch (_queue[ptr]->_state)
170              {
171              case IFETCH_QUEUE_STATE_WAIT_RSP       : _queue[ptr]->_state = IFETCH_QUEUE_STATE_HAVE_RSP; break;
172              case IFETCH_QUEUE_STATE_ERROR_WAIT_RSP : _queue[ptr]->_state = IFETCH_QUEUE_STATE_EMPTY   ; break;
173              default : throw ERRORMORPHEO(FUNCTION,"icache_rsp : invalid ifetch_queue state.");
174              }
175          }
176
177        // ==========================================================
178        // =====[ EVENT_RESET ]======================================
179        // ==========================================================
180        if (PORT_READ(in_EVENT_RESET_VAL) and internal_EVENT_RESET_ACK)
181          {
182            log_printf(TRACE,Ifetch_queue,FUNCTION,"  * EVENT_RESET : Transaction");
183
184            // Scan all entry of queue and test the status
185            for (uint32_t i=0; i<_param->_size_queue; i++)
186              switch (_queue[i]->_state)
187              {
188              case IFETCH_QUEUE_STATE_ERROR_WAIT_RSP :                                                        break;
189              case IFETCH_QUEUE_STATE_WAIT_RSP       : _queue[i]->_state = IFETCH_QUEUE_STATE_ERROR_WAIT_RSP; break;
190              default                                : _queue[i]->_state = IFETCH_QUEUE_STATE_EMPTY         ; break;
191              }
192
193            // all entry is empty (or wait respons to flush)
194            // reset ptr
195            //   1) reg_PTR_READ = reg_PTR_WRITE =  = 0
196            //   2) reg_PTR_READ = reg_PTR_WRITE
197            // 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)
198            reg_PTR_READ = reg_PTR_WRITE;
199          }
200
201#if defined(DEBUG) and (DEBUG >= DEBUG_TRACE)
202        log_printf(TRACE,Ifetch_queue,FUNCTION,"  * Dump ifetch_queue");
203        log_printf(TRACE,Ifetch_queue,FUNCTION,"    * reg_PTR_WRITE : %d",reg_PTR_WRITE);
204        log_printf(TRACE,Ifetch_queue,FUNCTION,"    * reg_PTR_READ  : %d",reg_PTR_READ );
205        for (uint32_t i=0; i<_param->_size_queue; i++)
206          {
207            uint32_t index=(i+reg_PTR_READ)%_param->_size_queue;
208
209            log_printf(TRACE,Ifetch_queue,FUNCTION,"    * [%d] 0x%.8x (0x%.8x) %d - %d %d %d - %s",
210                       index, 
211                       _queue [index]->_address,
212                       _queue [index]->_address<<2,
213                       _queue [index]->_inst_ifetch_ptr,
214                       _queue [index]->_branch_state,
215                       _queue [index]->_branch_update_prediction_id,
216                       _queue [index]->_exception,
217                       toString(_queue [index]->_state).c_str()
218                       );
219           
220            if (_queue [index]->_state != IFETCH_QUEUE_STATE_EMPTY)
221              for (uint32_t j=0; j<_param->_nb_instruction; j++)
222                log_printf(TRACE,Ifetch_queue,FUNCTION,"      * %d 0x%.8x (0x%.8x)", _queue [index]->_instruction_enable[j], _queue [index]->_instruction[j],(_queue [index]->_address+j)<<2);
223          }
224#endif
225
226#ifdef STATISTICS
227        if (usage_is_set(_usage,USE_STATISTICS))
228          for (uint32_t i=0; i<_param->_size_queue; i++)
229            switch (_queue[i]->_state)
230              {
231              case IFETCH_QUEUE_STATE_EMPTY          : break;
232              case IFETCH_QUEUE_STATE_WAIT_RSP       : (*_sum_use_queue_wait_rsp      ) ++; break;
233              case IFETCH_QUEUE_STATE_HAVE_RSP       : (*_sum_use_queue_have_rsp      ) ++; break;
234              case IFETCH_QUEUE_STATE_ERROR_WAIT_RSP : (*_sum_use_queue_error_wait_rsp) ++; break;
235              default : break;
236              }
237#endif
238      }
239
240    log_end(Ifetch_queue,FUNCTION);
241  };
242
243}; // end namespace ifetch_queue
244}; // end namespace ifetch_unit
245}; // end namespace front_end
246}; // end namespace multi_front_end
247}; // end namespace core
248
249}; // end namespace behavioural
250}; // end namespace morpheo             
251#endif
Note: See TracBrowser for help on using the repository browser.