source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Core/Multi_Execute_loop/Execute_loop/Multi_Execute_unit/Execute_unit/Load_store_unit/src/Load_store_unit_function_speculative_load_commit_transition.cpp @ 123

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

Modif for performance :
1) Load Store Unit : store send request to valid exeception
2) Commit_unit : retire can bypass store
3) Commit_unit : add stat to manage store instruction
4) Load Store Unit and Load Store Pointer Manager : add store_queue_ptr_read
5) Fix lot of bug

  • Property svn:keywords set to Id
File size: 59.5 KB
Line 
1#ifdef SYSTEMC
2/*
3 * $Id: Load_store_unit_function_speculative_load_commit_transition.cpp 122 2009-06-03 08:15:51Z rosiere $
4 *
5 * [ Description ]
6 *
7 */
8
9#include "Behavioural/Core/Multi_Execute_loop/Execute_loop/Multi_Execute_unit/Execute_unit/Load_store_unit/include/Load_store_unit.h"
10
11namespace morpheo                    {
12namespace behavioural {
13namespace core {
14namespace multi_execute_loop {
15namespace execute_loop {
16namespace multi_execute_unit {
17namespace execute_unit {
18namespace load_store_unit {
19
20template <typename T>
21T swapBytes (T data, uint32_t size_data, uint32_t size_access)
22{
23  uint64_t x = static_cast<uint64_t>(data);
24
25//   switch (size_data)
26//     {
27//     case 2 : // 16 bits
28//       {
29//         switch (size_access)
30//           {
31//           case 2 :
32//             {
33//               x = ((((x>> 8)&0xff) <<  0) |
34//                    (((x>> 0)&0xff) <<  8) );
35//               break;
36//             }
37//           default :
38//             {
39//               break;
40//             }
41//           }
42//         break;
43//       }
44//     case 4 : // 32 bits
45//       {
46//         switch (size_access)
47//           {
48//           case 2 :
49//             {
50//               x = ((((x>> 8)&0xff) <<  0) |
51//                    (((x>> 0)&0xff) <<  8) |
52//                    (((x>>24)&0xff) << 16) |
53//                    (((x>>16)&0xff) << 24) );
54//               break;
55//             }
56//           case 4 :
57//             {
58//               x = ((((x>>24)&0xff) <<  0) |
59//                    (((x>>16)&0xff) <<  8) |
60//                    (((x>> 8)&0xff) << 16) |
61//                    (((x>> 0)&0xff) << 24) );
62//               break;
63//             }
64//           default :
65//             {
66//               break;
67//             }
68//           }
69//         break;
70//       }
71//     case 8 : // 64 bits
72//       {
73//         switch (size_access)
74//           {
75//           case 2 :
76//             {
77//               x = ((((x>> 8)&0xff) <<  0) |
78//                    (((x>> 0)&0xff) <<  8) |
79//                    (((x>>24)&0xff) << 16) |
80//                    (((x>>16)&0xff) << 24) |
81//                    (((x>>40)&0xff) << 32) |
82//                    (((x>>32)&0xff) << 40) |
83//                    (((x>>56)&0xff) << 48) |
84//                    (((x>>48)&0xff) << 56) );
85//               break;
86//             }
87//           case 4 :
88//             {
89//               x = ((((x>>24)&0xff) <<  0) |
90//                    (((x>>16)&0xff) <<  8) |
91//                    (((x>> 8)&0xff) << 16) |
92//                    (((x>> 0)&0xff) << 24) |
93//                    (((x>>56)&0xff) << 32) |
94//                    (((x>>48)&0xff) << 40) |
95//                    (((x>>40)&0xff) << 48) |
96//                    (((x>>32)&0xff) << 56) );
97//               break;
98//             }
99//           case 8 :
100//             {
101//               x = ((((x>>56)&0xff) <<  0) |
102//                    (((x>>48)&0xff) <<  8) |
103//                    (((x>>40)&0xff) << 16) |
104//                    (((x>>32)&0xff) << 24) |
105//                    (((x>>24)&0xff) << 32) |
106//                    (((x>>16)&0xff) << 40) |
107//                    (((x>> 8)&0xff) << 48) |
108//                    (((x>> 0)&0xff) << 56) );
109//               break;
110//             }
111//           default :
112//             {
113//               break;
114//             }
115//           }
116//         break;
117//       }
118//     default :
119//       {
120//         break;
121//       }
122//     }
123
124
125  uint64_t y=0;
126
127  for (uint32_t i=0; i<size_data; i+=size_access)
128    {
129      uint32_t offset = i<<3;
130
131      switch (size_access)
132        {
133        case 1 :
134          {
135            y = x;
136            break;
137          }
138        case 2 : 
139          {
140            y |= ((((x>>( 8+offset))&0xff) << ( 0+offset)) |
141                  (((x>>( 0+offset))&0xff) << ( 8+offset)) );
142            break;
143          }
144        case 4 : 
145          {
146            y |= ((((x>>(24+offset))&0xff) << ( 0+offset)) |
147                  (((x>>(16+offset))&0xff) << ( 8+offset)) |
148                  (((x>>( 8+offset))&0xff) << (16+offset)) |
149                  (((x>>( 0+offset))&0xff) << (24+offset)) );
150            break;
151          }
152        case 8 : 
153          {
154            y |= ((((x>>(56+offset))&0xff) << ( 0+offset)) |
155                  (((x>>(48+offset))&0xff) << ( 8+offset)) |
156                  (((x>>(40+offset))&0xff) << (16+offset)) |
157                  (((x>>(32+offset))&0xff) << (24+offset)) |
158                  (((x>>(24+offset))&0xff) << (32+offset)) |
159                  (((x>>(16+offset))&0xff) << (40+offset)) |
160                  (((x>>( 8+offset))&0xff) << (48+offset)) |
161                  (((x>>( 0+offset))&0xff) << (56+offset)) );
162            break;
163          }
164        default :
165            {
166              break;
167            }
168        }
169    }
170
171  return static_cast<T>(y);
172}
173
174template <typename T>
175T swapBits (T data, uint32_t size_data, uint32_t size_access)
176{
177  uint8_t x = static_cast<uint8_t>(data);
178
179  uint8_t y=0;
180
181  for (uint32_t i=0; i<size_data; i+=size_access)
182    {
183      uint32_t offset = i;
184
185      switch (size_access)
186        {
187        case 1 :
188          {
189            y = x;
190            break;
191          }
192        case 2 : 
193          {
194            y |= ((((x>>( 1+offset))&0x1) << ( 0+offset)) |
195                  (((x>>( 0+offset))&0x1) << ( 1+offset)) );
196            break;
197          }
198        case 4 : 
199          {
200            y |= ((((x>>( 3+offset))&0x1) << ( 0+offset)) |
201                  (((x>>( 2+offset))&0x1) << ( 1+offset)) |
202                  (((x>>( 1+offset))&0x1) << ( 2+offset)) |
203                  (((x>>( 0+offset))&0x1) << ( 3+offset)) );
204            break;
205          }
206        case 8 : 
207          {
208            y |= ((((x>>( 7+offset))&0x1) << ( 0+offset)) |
209                  (((x>>( 6+offset))&0x1) << ( 1+offset)) |
210                  (((x>>( 5+offset))&0x1) << ( 2+offset)) |
211                  (((x>>( 4+offset))&0x1) << ( 3+offset)) |
212                  (((x>>( 3+offset))&0x1) << ( 4+offset)) |
213                  (((x>>( 2+offset))&0x1) << ( 5+offset)) |
214                  (((x>>( 1+offset))&0x1) << ( 6+offset)) |
215                  (((x>>( 0+offset))&0x1) << ( 7+offset)) );
216            break;
217          }
218        default :
219            {
220              break;
221            }
222        }
223    }
224
225  return static_cast<T>(y);
226}
227
228#undef  FUNCTION
229#define FUNCTION "Load_store_unit::function_speculative_load_commit_transition"
230  void Load_store_unit::function_speculative_load_commit_transition (void)
231  {
232    log_begin(Load_store_unit,FUNCTION);
233    log_function(Load_store_unit,FUNCTION,_name.c_str());
234
235    if (PORT_READ(in_NRESET) == 0)
236      {
237        // Reset : clear all queue
238        _speculative_access_queue_control->clear();
239
240        reg_STORE_QUEUE_PTR_READ = 0;
241        reg_LOAD_QUEUE_CHECK_PRIORITY  = 0;
242
243        for (uint32_t i=0; i< _param->_size_store_queue             ; i++)
244          {
245          reg_STORE_QUEUE_NB_CHECK  [i] = 0;
246          _store_queue              [i]._state = STORE_QUEUE_EMPTY;
247          }
248
249        for (uint32_t i=0; i< _param->_size_load_queue              ; i++)
250          _load_queue               [i]._state = LOAD_QUEUE_EMPTY;
251
252        for (uint32_t i=0; i< _param->_size_speculative_access_queue; i++)
253          _speculative_access_queue [i]._state = SPECULATIVE_ACCESS_QUEUE_EMPTY;
254      }
255    else
256      {
257        // load_queue_push if speculative_access_queue have access at the dcache, or they have an event
258        bool load_queue_push = (_speculative_access_queue [internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._state == SPECULATIVE_ACCESS_QUEUE_WAIT_LOAD_QUEUE);
259
260        //================================================================
261        // Interface "MEMORY_OUT"
262        //================================================================
263
264        if ((    internal_MEMORY_OUT_VAL  == 1) and
265            (PORT_READ(in_MEMORY_OUT_ACK[0]) == 1))
266          {
267            log_printf(TRACE,Load_store_unit,FUNCTION,"  * MEMORY_OUT[0] transaction");
268
269            switch (internal_MEMORY_OUT_SELECT_QUEUE)
270              {
271              case SELECT_STORE_QUEUE :
272                {
273                  // =======================
274                  // ===== STORE_QUEUE =====
275                  // =======================
276                 
277                  log_printf(TRACE,Load_store_unit,FUNCTION,"    * store_queue [%d]",internal_MEMORY_OUT_PTR);
278           
279                  // Entry flush and increase the read pointer
280                  if (_store_queue [internal_MEMORY_OUT_PTR]._send_commit)
281                    {
282                      _store_queue [internal_MEMORY_OUT_PTR]._state = STORE_QUEUE_EMPTY;
283                      reg_STORE_QUEUE_PTR_READ = (reg_STORE_QUEUE_PTR_READ+1)%_param->_size_store_queue;
284                    }
285                  else
286                    _store_queue [internal_MEMORY_OUT_PTR]._send_commit = true;
287
288                  break;
289                }
290              case SELECT_LOAD_QUEUE :
291                {
292                  // ======================
293                  // ===== LOAD_QUEUE =====
294                  // ======================
295                 
296                  log_printf(TRACE,Load_store_unit,FUNCTION,"    * load_queue  [%d]",internal_MEMORY_OUT_PTR);
297                 
298                  // Entry flush and increase the read pointer
299                 
300                  _load_queue [internal_MEMORY_OUT_PTR]._state = LOAD_QUEUE_EMPTY;
301                 
302                  // reg_LOAD_QUEUE_PTR_READ = (reg_LOAD_QUEUE_PTR_READ+1)%_param->_size_load_queue;
303
304                  break;
305                }
306              case SELECT_LOAD_QUEUE_SPECULATIVE :
307                {
308                  log_printf(TRACE,Load_store_unit,FUNCTION,"    * load_queue  [%d] (speculative)",internal_MEMORY_OUT_PTR);
309                 
310                  // !!! WARNING !!!
311                  // !!! Test special case :
312                  // !!! in a cycle an instruction can check the last store AND commit instruction
313                  // !!! also the memory_out is before the port_check
314
315                  _load_queue [internal_MEMORY_OUT_PTR]._state    = LOAD_QUEUE_CHECK;
316                  // NOTE : a speculative load write in the register file.
317                  // if the speculation is a miss, write_rd is re set at 1.
318                  _load_queue [internal_MEMORY_OUT_PTR]._write_rd = 0;
319
320#ifdef STATISTICS
321                  if (usage_is_set(_usage,USE_STATISTICS))
322                    (*_stat_nb_inst_load_commit_speculative) ++;
323#endif
324
325                  break;
326                }
327
328                break;
329              }
330          }
331
332        //================================================================
333        // Interface "PORT_CHECK"
334        //================================================================
335       
336        // Plusieurs moyens de faire la verification de dépendance entre les loads et les stores.
337        //  1) un load ne peut vérifier qu'un store par cycle. Dans ce cas port_check <= size_load_queue
338        //  2) un load tente de vérifier le maximum de store par cycle. Dans ce cas ce n'est pas du pointeur d'écriture qu'il lui faut mais un vecteur de bit indiquant quel store à déjà été testé. De plus il faut un bit indiquant qu'il y a un match mais que ce n'est pas forcément le premier.
339
340        // solution 1)
341        log_printf(TRACE,Load_store_unit,FUNCTION,"  * CHECK");
342        for (uint32_t i=0, nb_check=0; (nb_check<_param->_nb_port_check) and (i<_param->_size_load_queue); i++)
343          {
344            // Get an index from load queue
345            uint32_t index_load_queue = (i + reg_LOAD_QUEUE_CHECK_PRIORITY)%_param->_size_load_queue;
346
347            // Test if this load must ckecked store queue
348            if (((_load_queue[index_load_queue]._state == LOAD_QUEUE_WAIT_CHECK) or
349                 (_load_queue[index_load_queue]._state == LOAD_QUEUE_COMMIT_CHECK) or
350                 (_load_queue[index_load_queue]._state == LOAD_QUEUE_CHECK)) and
351                is_operation_memory_load(_load_queue[index_load_queue]._operation))
352              {
353                log_printf(TRACE,Load_store_unit,FUNCTION,"    * Find a load : %d",index_load_queue);
354
355                nb_check++; // use one port
356
357                // find a entry that it need a check
358                Tlsq_ptr_t store_queue_ptr_write = _load_queue[index_load_queue]._store_queue_ptr_write;
359                Tlsq_ptr_t store_queue_ptr_read  = _load_queue[index_load_queue]._store_queue_ptr_read ;
360                Tlsq_ptr_t store_queue_empty     = _load_queue[index_load_queue]._store_queue_empty    ;
361//              Tlsq_ptr_t store_queue_ptr_write_old = store_queue_ptr_write;
362
363                // Init variable
364                bool       end_check    = false;
365                bool       change_state = false;
366                bool       next         = false;
367
368                // At the first store queue empty, stop check.
369                // Explication :
370                //  * rename logic keep a empty case in the store queue (also size_store_queue > 1)
371                //  * when a store is out of store queue, also it was in head of re order buffer. Also, they are none previous load.
372
373                log_printf(TRACE,Load_store_unit,FUNCTION,"    * store_queue_ptr_write    : %d",store_queue_ptr_write);
374                log_printf(TRACE,Load_store_unit,FUNCTION,"    * store_queue_ptr_read     : %d",store_queue_ptr_read );
375//              log_printf(TRACE,Load_store_unit,FUNCTION,"    * store_queue_empty        : %d",store_queue_empty );
376                log_printf(TRACE,Load_store_unit,FUNCTION,"    * reg_STORE_QUEUE_PTR_READ : %d",reg_STORE_QUEUE_PTR_READ);
377
378                if ((store_queue_ptr_write ==     store_queue_ptr_read) or
379                    (store_queue_ptr_write == reg_STORE_QUEUE_PTR_READ))
380//              if (store_queue_empty)
381                  {
382                    log_printf(TRACE,Load_store_unit,FUNCTION,"      * store_queue_ptr_write == store_queue_ptr_read");
383                    end_check    = true;
384                    change_state = true;
385                  }
386                else
387                  {
388                    log_printf(TRACE,Load_store_unit,FUNCTION,"      * store_queue_ptr_write != store_queue_ptr_read");
389
390                    store_queue_ptr_write = (store_queue_ptr_write-1)%(_param->_size_store_queue); // store_queue_ptr_write target the next slot to write, also the slot is not significatif when the load is renaming
391
392                    log_printf(TRACE,Load_store_unit,FUNCTION,"      * store_queue_ptr_write : %d",store_queue_ptr_write);
393                   
394                    // switch on store_queue state
395                    switch (_store_queue[store_queue_ptr_write]._state)
396                      {
397                      case STORE_QUEUE_VALID_NO_SPECULATIVE : 
398                      case STORE_QUEUE_COMMIT :
399                      case STORE_QUEUE_VALID_SPECULATIVE :
400                        {
401                         
402                          log_printf(TRACE,Load_store_unit,FUNCTION,"      * store have a valid entry");
403                         
404                          // TODO : MMU - nous considérons que les adresses sont physique
405                          bool test_thread_id = true;
406                         
407                          // Test thread id
408                          if (_param->_have_port_context_id)
409                            test_thread_id &= (_load_queue[index_load_queue]._context_id    == _store_queue[store_queue_ptr_write]._context_id);
410                          if (_param->_have_port_front_end_id)
411                            test_thread_id &= (_load_queue[index_load_queue]._front_end_id  == _store_queue[store_queue_ptr_write]._front_end_id);
412                          if (_param->_have_port_ooo_engine_id)
413                            test_thread_id &= (_load_queue[index_load_queue]._ooo_engine_id == _store_queue[store_queue_ptr_write]._ooo_engine_id);
414                         
415                          if (test_thread_id)
416                            {
417                              // the load and store are in the same thread. Now, we must test address.
418
419                              log_printf(TRACE,Load_store_unit,FUNCTION,"        * load and store is the same thread.");
420                              Tdcache_address_t load_addr  = _load_queue [index_load_queue ]._address;
421                              Tdcache_address_t store_addr = _store_queue[store_queue_ptr_write]._address;
422                             
423                              log_printf(TRACE,Load_store_unit,FUNCTION,"          * load_addr                     : %.8x.",load_addr );
424                              log_printf(TRACE,Load_store_unit,FUNCTION,"          * store_addr                    : %.8x.",store_addr);
425                              log_printf(TRACE,Load_store_unit,FUNCTION,"          * load_addr  & mask_address_msb : %.8x.",load_addr  & _param->_mask_address_msb);
426                              log_printf(TRACE,Load_store_unit,FUNCTION,"          * store_addr & mask_address_msb : %.8x.",store_addr & _param->_mask_address_msb);
427                              // Test if the both address target the same "word"
428                              if ((load_addr  & _param->_mask_address_msb) == 
429                                  (store_addr & _param->_mask_address_msb))
430                                {
431                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * address_msb is the same.");
432                                  // all case - [] : store, () : load
433                                  // (1) store_max >= load_max and store_min <= load_min  ...[...(...)...]... Ok - inclusion in store
434                                  // (2) store_min >  load_max                            ...[...]...(...)... Ok - no conflit
435                                  // (3) store_max <  load_min                            ...(...)...[...]... Ok - no conflit
436                                  // (4) store_max <  load_max and store_min >  load_min  ...(...[...]...)... Ko - inclusion in load
437                                  // (5) store_max >= load_max and store_min >  load_min  ...[...(...]...)... Ko - conflit
438                                  // (6) store_max <  load_max and store_min <= load_min  ...(...[...)...]... Ko - conflit
439                                  // but :
440                                  // load in the cache is a word !
441                                  // the mask can be make when the load is commited. Also, the rdata content a full word.
442                                  // the only case is (4)
443                                 
444                                  // Read data
445                                  bool is_big_endian = true;
446
447                                  Tgeneral_data_t   load_data      = _load_queue [index_load_queue ]._rdata  ;
448                                  Tgeneral_data_t   store_data     = _store_queue[store_queue_ptr_write]._wdata  ;
449                                  Tdcache_address_t check_hit_byte = _load_queue [index_load_queue ]._check_hit_byte;
450                                  Tcontrol_t        check_hit      = _load_queue [index_load_queue ]._check_hit;
451                                  uint32_t          load_size_access  = memory_size(_load_queue [index_load_queue ]._operation)>>3;
452                                  uint32_t          store_size_access = memory_size(_store_queue[store_queue_ptr_write]._operation)>>3;
453
454                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * is_big_endian           : %d",is_big_endian);
455                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * load_data               : 0x%.8x",load_data);
456                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * store_data              : 0x%.8x",store_data);
457                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * check_hit_byte          : %x",check_hit_byte);
458                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * check_hit               : %d",check_hit);
459
460                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * load_size_access        : %d",load_size_access );
461                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * store_size_access       : %d",store_size_access);
462
463                                  if (is_big_endian)
464                                    {
465                                      // swap in little endian
466                                      load_data      = swapBytes<Tgeneral_data_t  >(load_data     , _param->_size_general_data>>3,load_size_access);
467                                      store_data     = swapBytes<Tgeneral_data_t  >(store_data    , _param->_size_general_data>>3,store_size_access);
468                                      check_hit_byte = swapBits <Tdcache_address_t>(check_hit_byte, _param->_size_general_data>>3,load_size_access);
469                                     
470                                     
471                                      log_printf(TRACE,Load_store_unit,FUNCTION,"            * load_data      (swap 1) : 0x%.8x",load_data);
472                                      log_printf(TRACE,Load_store_unit,FUNCTION,"            * store_data     (swap 1) : 0x%.8x",store_data);
473                                      log_printf(TRACE,Load_store_unit,FUNCTION,"            * check_hit_byte (swap 1) : %x",check_hit_byte);
474                                    }
475
476                                  uint32_t store_nb_byte     = (1<<memory_access(_store_queue[store_queue_ptr_write]._operation));
477
478                                  // Take interval to the store
479                                  uint32_t store_num_byte_min = (store_addr & _param->_mask_address_lsb);
480                                  uint32_t store_num_byte_max = store_num_byte_min+store_nb_byte;
481
482                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * store_num_byte_min      : %d",store_num_byte_min);
483                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * store_num_byte_max      : %d",store_num_byte_max);
484
485//                                   uint32_t load_nb_byte      = (1<<memory_access(_load_queue[index_load_queue]._operation));
486
487//                                uint32_t load_num_byte_min = (load_addr & _param->_mask_address_lsb);
488//                                uint32_t load_num_byte_max = load_num_byte_min+load_nb_byte;
489
490//                                log_printf(TRACE,Load_store_unit,FUNCTION,"            * load_num_byte_min       : %d",load_num_byte_min);
491//                                log_printf(TRACE,Load_store_unit,FUNCTION,"            * load_num_byte_max       : %d",load_num_byte_max);
492
493//                                for (uint32_t num_load_byte=load_num_byte_min; num_load_byte<load_num_byte_max; num_load_byte ++)
494//                                  {
495//                                       // Make a mask
496//                                       uint32_t num_store_byte = num_load_byte;
497                                     
498
499
500                                  // The bypass is checked byte per byte
501                                  // Is same endianness : because to change endianness, we must write in special register. Also the pipeline is flushed.
502                                  for (uint32_t num_store_byte=store_num_byte_min; num_store_byte<store_num_byte_max; num_store_byte ++)
503                                    {
504                                      // Make a mask
505                                      uint32_t num_load_byte = num_store_byte;
506
507//                                       if (is_big_endian)
508//                                         {
509//                                           // sd 0 : 0 1 2 3 4 5 6 7
510//                                           // ld 0 : 0 1 2 3 4 5 6 7 >>  0
511//                                           // lw 0 :         0 1 2 3 >>  0 -4
512//                                           // lw 4 : 4 5 6 7         >> 32 +4
513//                                           // lh 0 :             0 1 >>  0 -6
514//                                           // lh 2 :         2 3     >> 16 -2
515//                                           // lh 4 :     4 5         >> 32 +2
516//                                           // lh 6 : 6 7             >> 48 +6
517//                                           // lb 0 :               0 >>  0 -7
518//                                           // lb 1 :             1   >>  8 -5
519//                                           // lb 2 :           2     >> 16 -3
520//                                           // lb 3 :         3       >> 24 -1
521//                                           // lb 4 :       4         >> 32 +1
522//                                           // lb 5 :     5           >> 40 +3
523//                                           // lb 6 :   6             >> 48 +5
524//                                           // lb 7 : 7               >> 56 +7
525
526//                                           // diff : (store_nb_byte + load_nb_byte) - 2*nb_load_byte*((num_store_byte+1)
527
528//                                           // store duplicate = all store access can be see as full size_data store
529// //                                           uint32_t load_nb_byte = (1<<memory_access(_load_queue [index_load_queue ]._operation));
530
531// //                                           int32_t diff = ((_param->_size_general_data>>3)+load_nb_byte-2*load_nb_byte*((num_store_byte/load_nb_byte)+1));
532
533// //                                           num_load_byte =num_store_byte+diff;
534
535// //                                           log_printf(TRACE,Load_store_unit,FUNCTION,"              * load_nb_byte   : %d",load_nb_byte);
536// //                                           log_printf(TRACE,Load_store_unit,FUNCTION,"              * diff           : %d",diff);
537
538
539//                                           num_load_byte = num_store_byte;
540//                                         }
541//                                       else
542//                                         {
543//                                           // sd 0 : 0 1 2 3 4 5 6 7
544//                                           // ld 0 : 0 1 2 3 4 5 6 7 >>  0
545//                                           // lw 0 :         4 5 6 7 >>  0
546//                                           // lw 4 : 0 1 2 3         >> 32
547//                                           // lh 0 :             6 7 >>  0
548//                                           // lh 2 :         4 5     >> 16
549//                                           // lh 4 :     2 3         >> 32
550//                                           // lh 6 : 0 1             >> 48
551//                                           // lb 0 :               7 >>  0
552//                                           // lb 1 :             6   >>  8
553//                                           // lb 2 :           5     >> 16
554//                                           // lb 3 :         4       >> 24
555//                                           // lb 4 :       3         >> 32
556//                                           // lb 5 :     2           >> 40
557//                                           // lb 6 :   1             >> 48
558//                                           // lb 7 : 0               >> 56
559                                         
560//                                           num_load_byte = num_store_byte;
561//                                         }
562
563                                      uint32_t mask  = 1<<num_load_byte;
564
565                                      log_printf(TRACE,Load_store_unit,FUNCTION,"              * num_store_byte : %d",num_store_byte);
566                                      log_printf(TRACE,Load_store_unit,FUNCTION,"              * num_load_byte  : %d",num_load_byte);
567                                      log_printf(TRACE,Load_store_unit,FUNCTION,"              * mask           : %d",mask);
568
569                                      // Accept the bypass if :
570                                      //   * they have not a previous bypass with an another store
571                                      //   * it's a valid request of load
572                                      if ((check_hit_byte&mask)==0)
573                                        {
574                                          // Note : Store is duplicate = all store access can be see as full size_data store
575
576                                          uint32_t num_store_bit_min = num_store_byte<<3; //*8
577//                                        uint32_t num_store_bit_max = num_store_bit_min+8-1;
578                                          uint32_t num_load_bit_min  = num_load_byte <<3; //*8
579                                          uint32_t num_load_bit_max  = num_load_bit_min+8-1;
580
581                                          log_printf(TRACE,Load_store_unit,FUNCTION,"              * bypass !!!");
582//                                        log_printf(TRACE,Load_store_unit,FUNCTION,"              * interval store : [%d:%d]",num_store_bit_max,num_store_bit_min);
583                                          log_printf(TRACE,Load_store_unit,FUNCTION,"              * interval store : [..:%d]",num_store_bit_min);
584                                          log_printf(TRACE,Load_store_unit,FUNCTION,"              * interval load  : [%d:%d]",num_load_bit_max,num_load_bit_min);
585                                          log_printf(TRACE,Load_store_unit,FUNCTION,"                * rdata_old : 0x%.8x", load_data);
586
587                                          load_data = ((((store_data>>num_store_bit_min) & 0xff) << num_load_bit_min) |
588                                                       mask_not<Tdcache_data_t>(load_data,num_load_bit_max,num_load_bit_min));
589
590                                          check_hit_byte |= mask;
591                                          check_hit       = 1;
592                                          change_state = true;
593
594                                          log_printf(TRACE,Load_store_unit,FUNCTION,"                * rdata_new : 0x%.8x", load_data);
595                                        }
596                                    }
597
598                                  if (is_big_endian)
599                                    {
600                                      // swap in little endian
601                                      load_data      = swapBytes<Tgeneral_data_t  >(load_data     , _param->_size_general_data>>3,load_size_access);
602                                      check_hit_byte = swapBits <Tdcache_address_t>(check_hit_byte, _param->_size_general_data>>3,load_size_access);
603                                     
604                                     
605                                      log_printf(TRACE,Load_store_unit,FUNCTION,"            * load_data      (swap 2) : 0x%.8x",load_data);
606                                      log_printf(TRACE,Load_store_unit,FUNCTION,"            * check_hit_byte (swap 2) : %x",check_hit_byte);
607                                    }
608
609                                  _load_queue[index_load_queue]._rdata          = load_data;
610                                  _load_queue[index_load_queue]._check_hit_byte = check_hit_byte;
611                                  _load_queue[index_load_queue]._check_hit      = check_hit;
612
613                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * load_data  (after) : 0x%.8x",load_data);
614
615                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * check_hit          : %x",check_hit);
616                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * check_hit_byte     : %x",check_hit_byte);
617
618                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * mask_end_check     : %x",(-1& _param->_mask_address_lsb));
619                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * mask_check_hit_byte: %x",_param->_mask_check_hit_byte);
620                                  // The check is finish if all bit is set
621                                  end_check = (_load_queue[index_load_queue]._check_hit_byte == _param->_mask_check_hit_byte);
622
623                                }
624                            }
625                         
626                          next = true;
627                          break;
628                        }
629                      case STORE_QUEUE_EMPTY :
630                      case STORE_QUEUE_NO_VALID_NO_SPECULATIVE :
631                        {
632                          log_printf(TRACE,Load_store_unit,FUNCTION,"      * store have an invalid entry");
633                          break;
634                        }
635                      }
636                  }
637
638                if (next)
639                  {
640                    log_printf(TRACE,Load_store_unit,FUNCTION,"              * next");
641                    log_printf(TRACE,Load_store_unit,FUNCTION,"                * new store_queue_ptr_write : %d",store_queue_ptr_write);
642
643                    log_printf(TRACE,Load_store_unit,FUNCTION,"              * update reg_STORE_QUEUE_NB_CHECK");
644#ifdef DEBUG
645                    if (reg_STORE_QUEUE_NB_CHECK [store_queue_ptr_write] == 0)
646                      throw ERRORMORPHEO(FUNCTION,_("reg_STORE_QUEUE_NB_CHECK must be > 0\n"));
647#endif
648
649                    reg_STORE_QUEUE_NB_CHECK [store_queue_ptr_write] --;
650
651                    log_printf(TRACE,Load_store_unit,FUNCTION,"              * reg_STORE_QUEUE_NB_CHECK 1 [%d] <- %d", store_queue_ptr_write,reg_STORE_QUEUE_NB_CHECK [store_queue_ptr_write]);
652
653                    if ((store_queue_ptr_write ==     store_queue_ptr_read) or
654                        (store_queue_ptr_write == reg_STORE_QUEUE_PTR_READ))
655                      {
656//                      store_queue_empty = true;
657                        end_check         = true;
658                        change_state      = true;
659                      }
660
661//                  if (_load_queue[index_load_queue]._store_queue_ptr_write == 0)
662//                    _load_queue[index_load_queue]._store_queue_ptr_write = _param->_size_store_queue-1;
663//                  else
664//                    _load_queue[index_load_queue]._store_queue_ptr_write --;
665                    _load_queue[index_load_queue]._store_queue_ptr_write = store_queue_ptr_write; // because the index store have be decrease
666                    _load_queue[index_load_queue]._store_queue_empty     = store_queue_empty; // because the index store have be decrease
667
668                    // FIXME : peut n'est pas obliger de faire cette comparaison. Au prochain cycle on le détectera que les pointeur sont égaux. Ceci évitera d'avoir deux comparateurs avec le registre "store_queue_ptr_read"
669                  }
670
671                if (change_state)
672                  {
673                    log_printf(TRACE,Load_store_unit,FUNCTION,"              * change_state");
674                    log_printf(TRACE,Load_store_unit,FUNCTION,"              * end_check : %d",end_check);
675
676                    log_printf(TRACE,Load_store_unit,FUNCTION,"                * state old : %s",toString(_load_queue[index_load_queue]._state).c_str());
677
678                    switch (_load_queue[index_load_queue]._state)
679                      {
680                      case LOAD_QUEUE_WAIT_CHECK   : 
681                        {
682                          if (end_check)
683                            _load_queue[index_load_queue]._state = LOAD_QUEUE_WAIT  ; 
684                          break;
685                        }
686                      case LOAD_QUEUE_COMMIT_CHECK : 
687                        {
688                          if (end_check)
689                            _load_queue[index_load_queue]._state = LOAD_QUEUE_COMMIT; 
690                          else
691                            _load_queue[index_load_queue]._state = LOAD_QUEUE_CHECK; // No commit : check hit and no end
692                          break;
693                        }
694                      case LOAD_QUEUE_CHECK        : 
695                        {
696                          if (end_check)
697                            _load_queue[index_load_queue]._state     = LOAD_QUEUE_COMMIT;
698
699                          // check find a bypass. A speculative load have been committed : report a speculation miss.
700                          if ((_load_queue[index_load_queue]._check_hit != 0) and
701                              (_load_queue[index_load_queue]._write_rd  == 0) // is commit
702                              )
703                            {
704                              _load_queue[index_load_queue]._exception = EXCEPTION_MEMORY_MISS_SPECULATION;
705                              _load_queue[index_load_queue]._write_rd  = 1; // write the good result
706
707#ifdef STATISTICS
708                              if (usage_is_set(_usage,USE_STATISTICS))
709                                (*_stat_nb_inst_load_commit_miss) ++;
710#endif
711                            }
712                         
713                          break;
714                        }
715                      default : break;
716                      }
717                    log_printf(TRACE,Load_store_unit,FUNCTION,"                * state new : %s",toString(_load_queue[index_load_queue]._state).c_str());
718                    log_printf(TRACE,Load_store_unit,FUNCTION,"                * exception : %d",_load_queue[index_load_queue]._exception);
719
720                    if (end_check//  and not store_queue_empty
721                        )
722                      {
723                        log_printf(TRACE,Load_store_unit,FUNCTION,"                * end check, decrease all nb_check");
724                       
725                        uint32_t i=store_queue_ptr_write;
726                        while (i!=store_queue_ptr_read)
727                          {
728                            i=((i==0)?_param->_size_store_queue:i)-1;
729                           
730#ifdef DEBUG
731                            if (reg_STORE_QUEUE_NB_CHECK [i] == 0)
732                              throw ERRORMORPHEO(FUNCTION,_("reg_STORE_QUEUE_NB_CHECK must be > 0\n"));
733#endif
734                           
735                            reg_STORE_QUEUE_NB_CHECK [i] --;
736
737                            log_printf(TRACE,Load_store_unit,FUNCTION,"              * reg_STORE_QUEUE_NB_CHECK 2 [%d] <- %d", i,reg_STORE_QUEUE_NB_CHECK [i]);
738
739                            //i=(i+1)%_param->_size_store_queue;
740                          }
741                       
742                        _load_queue[index_load_queue]._store_queue_empty = true; // end of check
743                      }
744                  }
745              }
746            // else : don't use a port
747          }
748       
749        //================================================================
750        // Interface "MEMORY_IN"
751        //================================================================
752       
753        if ((PORT_READ(in_MEMORY_IN_VAL [internal_MEMORY_IN_PORT]) == 1) and
754            (    internal_MEMORY_IN_ACK  == 1))
755          {
756            log_printf(TRACE,Load_store_unit,FUNCTION,"  * MEMORY_IN [%d]",internal_MEMORY_IN_PORT);
757
758            // Test operation :
759            //~~~~~~~~~~~~~~~~~
760            //  store  in store_queue
761            //  load   in speculation_access_queue
762            //  others in speculation_access_queue
763
764#ifdef DEBUG_TEST
765            if (PORT_READ(in_MEMORY_IN_TYPE [internal_MEMORY_IN_PORT]) != TYPE_MEMORY)
766              throw ERRORMORPHEO(FUNCTION,"The type is different at 'TYPE_MEMORY'");
767#endif
768            Toperation_t    operation            = PORT_READ(in_MEMORY_IN_OPERATION[internal_MEMORY_IN_PORT]);
769            Tgeneral_data_t address              = (PORT_READ(in_MEMORY_IN_IMMEDIAT[internal_MEMORY_IN_PORT]) +
770                                                    PORT_READ(in_MEMORY_IN_DATA_RA [internal_MEMORY_IN_PORT]));
771            bool            exception_alignement = (mask_memory_access(operation) & address) != 0;
772                                                   
773            if (is_operation_memory_store(operation) == true)
774              {
775                // =======================
776                // ===== STORE_QUEUE =====
777                // =======================
778                // There a two store request type :
779                //   - first is operation with address and data
780                //   - second is the information of re order buffer : the store become not speculative and can access at the data cache
781
782                log_printf(TRACE,Load_store_unit,FUNCTION,"    * store_queue");
783                log_printf(TRACE,Load_store_unit,FUNCTION,"      * PUSH");
784               
785                // Write pointer is define in rename stage :
786                Tlsq_ptr_t           index         = PORT_READ(in_MEMORY_IN_STORE_QUEUE_PTR_WRITE[internal_MEMORY_IN_PORT]);
787                log_printf(TRACE,Load_store_unit,FUNCTION,"      * index         : %d",index);
788               
789                // Need read : state and exception.
790                Tstore_queue_state_t old_state     = _store_queue [index]._state;
791                Tstore_queue_state_t new_state     = old_state;
792                bool                 update_info   = false;
793
794                Texception_t         old_exception = _store_queue [index]._exception;
795                Texception_t         new_exception = old_exception;
796
797                // Compute next state
798                switch (old_state)
799                  {
800                  case STORE_QUEUE_EMPTY                   :
801                    {
802                      if (is_operation_memory_store_head(operation) == true)
803                        {
804                          new_state = STORE_QUEUE_NO_VALID_NO_SPECULATIVE;
805
806                          // test if is a speculation
807                          if (operation == OPERATION_MEMORY_STORE_HEAD_KO)
808                            new_exception = EXCEPTION_MEMORY_MISS_SPECULATION;
809                          else
810                            new_exception = EXCEPTION_MEMORY_NONE;
811                        }
812                      else
813                        {
814                          new_state = STORE_QUEUE_VALID_SPECULATIVE;
815
816                          // Test if have an exception
817                          if (exception_alignement == true)
818                            new_exception = EXCEPTION_MEMORY_ALIGNMENT;
819                          else
820                            new_exception = EXCEPTION_MEMORY_NONE;
821
822                          update_info = true;
823                        }
824                      break;
825                    }
826                  case STORE_QUEUE_NO_VALID_NO_SPECULATIVE :
827                    {
828#ifdef DEBUG_TEST
829                      if (is_operation_memory_store_head(operation) == true)
830                        throw ERRORMORPHEO(FUNCTION,_("Transaction in memory_in's interface, actual state of store_queue is \"STORE_QUEUE_NO_VALID_NO_SPECULATIVE\", also a previous store_head have been receiveid. But this operation is a store_head."));
831#endif
832                      // Test if have a new exception (priority : miss_speculation)
833                      if ((exception_alignement == true) and (old_exception == EXCEPTION_MEMORY_NONE))
834                        new_exception = EXCEPTION_MEMORY_ALIGNMENT;
835                     
836                      if (new_exception != EXCEPTION_MEMORY_NONE)
837                        new_state = STORE_QUEUE_COMMIT;
838                      else
839                        new_state = STORE_QUEUE_VALID_NO_SPECULATIVE;
840                     
841                      update_info = true;
842                      break;
843                    }
844                  case STORE_QUEUE_VALID_SPECULATIVE       :
845                    {
846#ifdef DEBUG_TEST
847                      if (is_operation_memory_store_head(operation) == false)
848                        throw ERRORMORPHEO(FUNCTION,_("Transaction in memory_in's interface, actual state of store_queue is \"STORE_QUEUE_VALID_SPECULATIVE\", also a previous access with register and address have been receiveid. But this operation is a not store_head."));
849#endif
850                      if (operation == OPERATION_MEMORY_STORE_HEAD_KO)
851                        new_exception = EXCEPTION_MEMORY_MISS_SPECULATION; // great prioritary
852                     
853                      if (new_exception != EXCEPTION_MEMORY_NONE)
854                        new_state = STORE_QUEUE_COMMIT;
855                      else
856                        new_state = STORE_QUEUE_VALID_NO_SPECULATIVE;
857                     
858                      break;
859                    }
860                  case STORE_QUEUE_VALID_NO_SPECULATIVE    :
861                  case STORE_QUEUE_COMMIT                  :
862                    {
863                      throw ERRORMORPHEO(FUNCTION,"<Load_store_unit::function_speculative_load_commit_transition> Invalid state and operation");
864                    }
865                  }
866
867                _store_queue [index]._state     = new_state;
868                _store_queue [index]._exception = new_exception;
869               
870                if (update_info == true)
871                  {
872                    log_printf(TRACE,Load_store_unit,FUNCTION,"      * Update information");
873
874                    _store_queue [index]._context_id           = (not _param->_have_port_context_id   )?0:PORT_READ(in_MEMORY_IN_CONTEXT_ID   [internal_MEMORY_IN_PORT]);
875                    _store_queue [index]._front_end_id         = (not _param->_have_port_front_end_id )?0:PORT_READ(in_MEMORY_IN_FRONT_END_ID [internal_MEMORY_IN_PORT]);
876                    _store_queue [index]._ooo_engine_id        = (not _param->_have_port_ooo_engine_id)?0:PORT_READ(in_MEMORY_IN_OOO_ENGINE_ID[internal_MEMORY_IN_PORT]);
877                    _store_queue [index]._packet_id            = (not _param->_have_port_rob_ptr      )?0:PORT_READ(in_MEMORY_IN_PACKET_ID    [internal_MEMORY_IN_PORT]);
878                    _store_queue [index]._operation            = operation;
879                    _store_queue [index]._load_queue_ptr_write = (not _param->_have_port_load_queue_ptr)?0:PORT_READ(in_MEMORY_IN_LOAD_QUEUE_PTR_WRITE[internal_MEMORY_IN_PORT]);
880                    _store_queue [index]._address              = address;
881                    _store_queue [index]._send_commit          = false;
882
883                    // reordering data
884                    _store_queue [index]._wdata                = duplicate<Tgeneral_data_t>(_param->_size_general_data,PORT_READ(in_MEMORY_IN_DATA_RB[internal_MEMORY_IN_PORT]), memory_size(operation), 0); 
885//                  _store_queue [index]._num_reg_rd           = PORT_READ(in_MEMORY_IN_NUM_REG_RD  [internal_MEMORY_IN_PORT]);
886                  }
887              }
888            else
889              {
890                // ====================================
891                // ===== SPECULATIVE_ACCESS_QUEUE =====
892                // ====================================
893
894                // In speculative access queue, they are many type's request
895                log_printf(TRACE,Load_store_unit,FUNCTION,"    * speculative_access_queue");
896                log_printf(TRACE,Load_store_unit,FUNCTION,"      * PUSH");
897               
898                // Write in reservation station
899                uint32_t     index = _speculative_access_queue_control->push();
900
901                log_printf(TRACE,Load_store_unit,FUNCTION,"      * index : %d", index);
902
903                Texception_t exception;
904
905                if (exception_alignement == true)
906                  exception = EXCEPTION_MEMORY_ALIGNMENT;
907                else
908                  exception = EXCEPTION_MEMORY_NONE;
909                               
910                // if exception, don't access at the cache
911                // NOTE : type "other" (lock, invalidate, flush and sync) can't make an alignement exception (access is equivalent at a 8 bits)
912                _speculative_access_queue [index]._state                = (exception == EXCEPTION_MEMORY_NONE)?SPECULATIVE_ACCESS_QUEUE_WAIT_CACHE:SPECULATIVE_ACCESS_QUEUE_WAIT_LOAD_QUEUE;
913                _speculative_access_queue [index]._context_id           = (not _param->_have_port_context_id   )?0:PORT_READ(in_MEMORY_IN_CONTEXT_ID   [internal_MEMORY_IN_PORT]);
914                _speculative_access_queue [index]._front_end_id         = (not _param->_have_port_front_end_id )?0:PORT_READ(in_MEMORY_IN_FRONT_END_ID [internal_MEMORY_IN_PORT]);
915                _speculative_access_queue [index]._ooo_engine_id        = (not _param->_have_port_ooo_engine_id)?0:PORT_READ(in_MEMORY_IN_OOO_ENGINE_ID[internal_MEMORY_IN_PORT]);
916                _speculative_access_queue [index]._packet_id            = (not _param->_have_port_rob_ptr      )?0:PORT_READ(in_MEMORY_IN_PACKET_ID    [internal_MEMORY_IN_PORT]);
917
918                _speculative_access_queue [index]._operation            = operation;
919                _speculative_access_queue [index]._load_queue_ptr_write = (not _param->_have_port_load_queue_ptr)?0:PORT_READ(in_MEMORY_IN_LOAD_QUEUE_PTR_WRITE[internal_MEMORY_IN_PORT]);
920                _speculative_access_queue [index]._store_queue_ptr_write= PORT_READ(in_MEMORY_IN_STORE_QUEUE_PTR_WRITE[internal_MEMORY_IN_PORT]);
921                _speculative_access_queue [index]._store_queue_ptr_read = PORT_READ(in_MEMORY_IN_STORE_QUEUE_PTR_READ [internal_MEMORY_IN_PORT]);
922                _speculative_access_queue [index]._store_queue_empty    = PORT_READ(in_MEMORY_IN_STORE_QUEUE_EMPTY    [internal_MEMORY_IN_PORT]);
923                _speculative_access_queue [index]._address              = address;
924                // NOTE : is operation is a load, then they are a result and must write in the register file
925                _speculative_access_queue [index]._write_rd             = is_operation_memory_load(operation);
926                _speculative_access_queue [index]._num_reg_rd           = PORT_READ(in_MEMORY_IN_NUM_REG_RD  [internal_MEMORY_IN_PORT]);
927
928                _speculative_access_queue [index]._exception            = exception;
929              }
930          }
931
932        //================================================================
933        // Interface "DCACHE_REQ"
934        //================================================================
935        if ((    internal_DCACHE_REQ_VAL  == 1) and
936            (PORT_READ(in_DCACHE_REQ_ACK[0]) == 1))
937          {
938            log_printf(TRACE,Load_store_unit,FUNCTION,"  * DCACHE_REQ [0]");
939
940            switch (internal_DCACHE_REQ_SELECT_QUEUE)
941              {
942              case SELECT_STORE_QUEUE :
943                {
944                  // =======================
945                  // ===== STORE_QUEUE =====
946                  // =======================
947                 
948                  // Entry flush and increase the read pointer
949                 
950                  _store_queue [reg_STORE_QUEUE_PTR_READ]._state = STORE_QUEUE_COMMIT;
951
952                  break;
953                }
954              case SELECT_LOAD_QUEUE_SPECULATIVE :
955                {
956                  // =========================================
957                  // ===== SELECT_LOAD_QUEUE_SPECULATIVE =====
958                  // =========================================
959
960                  load_queue_push = true;
961                  break;
962                }
963              case SELECT_LOAD_QUEUE :
964                {
965                  throw ERRORMORPHEO(FUNCTION,_("Invalid selection"));
966                  break;
967                }
968
969                break;
970              }
971          }
972
973        if (load_queue_push)
974          {
975            log_printf(TRACE,Load_store_unit,FUNCTION,"  * load_queue_push");
976
977            Tlsq_ptr_t   ptr_write = _speculative_access_queue[internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._load_queue_ptr_write;
978            Toperation_t operation = _speculative_access_queue[internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._operation;
979            Texception_t exception = _speculative_access_queue[internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._exception;
980            bool         have_exception = (exception != EXCEPTION_MEMORY_NONE);
981            bool         need_check= false;
982            Tlsq_ptr_t        store_queue_ptr_write = _speculative_access_queue [internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._store_queue_ptr_write;
983            Tlsq_ptr_t        store_queue_ptr_read  = _speculative_access_queue [internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._store_queue_ptr_read ;
984            Tcontrol_t        store_queue_empty     = _speculative_access_queue [internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._store_queue_empty    ;
985           
986            if (have_exception)
987              _load_queue [ptr_write]._state = LOAD_QUEUE_COMMIT;
988            else
989              {
990                if (have_dcache_rsp(operation))
991                  {
992                    // load and synchronisation
993                    if (must_check(operation) and not store_queue_empty)
994                      {
995                        // load
996                        need_check = true;
997                       
998                        _load_queue [ptr_write]._state = LOAD_QUEUE_WAIT_CHECK;
999                      }
1000                    else
1001                      {
1002                        // synchronisation
1003                        _load_queue [ptr_write]._state = LOAD_QUEUE_WAIT;
1004                      }
1005                  }
1006                else
1007                  {
1008                    // lock, prefecth, flush and invalidate
1009                    _load_queue [ptr_write]._state = LOAD_QUEUE_COMMIT;
1010                  }
1011              }
1012
1013            Tdcache_address_t address        = _speculative_access_queue [internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._address;
1014            Tdcache_address_t address_lsb    = (address & _param->_mask_address_lsb);
1015            Tdcache_address_t check_hit_byte = gen_mask_not<Tdcache_address_t>(address_lsb+(memory_size(operation)>>3)-1,address_lsb) & _param->_mask_check_hit_byte;
1016
1017            log_printf(TRACE,Load_store_unit,FUNCTION,"    * address                 : 0x%.8x", address);
1018            log_printf(TRACE,Load_store_unit,FUNCTION,"    * address_lsb             : 0x%.8x", address_lsb);
1019            log_printf(TRACE,Load_store_unit,FUNCTION,"    * operation               : %d", operation);
1020            log_printf(TRACE,Load_store_unit,FUNCTION,"    * memory_size             : %d", memory_size(operation));
1021            log_printf(TRACE,Load_store_unit,FUNCTION,"    * check_hit_byte          : 0x%x", check_hit_byte);
1022
1023            _load_queue [ptr_write]._context_id            = _speculative_access_queue [internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._context_id;
1024            _load_queue [ptr_write]._front_end_id          = _speculative_access_queue [internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._front_end_id;
1025            _load_queue [ptr_write]._ooo_engine_id         = _speculative_access_queue [internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._ooo_engine_id;
1026            _load_queue [ptr_write]._packet_id             = _speculative_access_queue [internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._packet_id;
1027            _load_queue [ptr_write]._operation             = operation;
1028            _load_queue [ptr_write]._store_queue_ptr_write = store_queue_ptr_write;
1029            _load_queue [ptr_write]._store_queue_ptr_read  = store_queue_ptr_read ;
1030            _load_queue [ptr_write]._store_queue_empty     = store_queue_empty    ;
1031            _load_queue [ptr_write]._address               = address;
1032            _load_queue [ptr_write]._check_hit_byte        = check_hit_byte;
1033            _load_queue [ptr_write]._check_hit             = 0;
1034            _load_queue [ptr_write]._shift                 = address_lsb<<3;// *8
1035            _load_queue [ptr_write]._is_load_signed        = is_operation_memory_load_signed(operation);
1036            _load_queue [ptr_write]._access_size           = memory_size(operation);
1037            // NOTE : if have an exception, must write in register, because a depend instruction wait the load data.
1038            _load_queue [ptr_write]._write_rd              = _speculative_access_queue [internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._write_rd             ;
1039            _load_queue [ptr_write]._num_reg_rd            = _speculative_access_queue [internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._num_reg_rd           ;
1040            _load_queue [ptr_write]._exception             = exception;
1041            _load_queue [ptr_write]._rdata                 = address; // to the exception
1042           
1043            log_printf(TRACE,Load_store_unit,FUNCTION,"    * speculative_access_queue");
1044            log_printf(TRACE,Load_store_unit,FUNCTION,"      * POP[%d]",(*_speculative_access_queue_control)[0]);
1045           
1046            _speculative_access_queue [(*_speculative_access_queue_control)[0]]._state = SPECULATIVE_ACCESS_QUEUE_EMPTY;
1047           
1048            _speculative_access_queue_control->pop();
1049
1050#ifdef STATISTICS
1051            if (usage_is_set(_usage,USE_STATISTICS))
1052              (*_stat_nb_inst_load) ++;
1053#endif
1054
1055            // Only load need check
1056            if (need_check//  and not store_queue_empty
1057                )
1058//             if (is_operation_memory_load(_load_queue [ptr_write]._operation))
1059              {
1060                log_printf(TRACE,Load_store_unit,FUNCTION,"    * update nb_check");
1061                log_printf(TRACE,Load_store_unit,FUNCTION,"      *     store_queue_ptr_write : %d",store_queue_ptr_write);
1062                log_printf(TRACE,Load_store_unit,FUNCTION,"      *     store_queue_ptr_read  : %d",store_queue_ptr_read );
1063                log_printf(TRACE,Load_store_unit,FUNCTION,"      *     store_queue_empty     : %d",store_queue_empty    );
1064                log_printf(TRACE,Load_store_unit,FUNCTION,"      * reg_STORE_QUEUE_PTR_READ  : %d",reg_STORE_QUEUE_PTR_READ);
1065               
1066                uint32_t i=store_queue_ptr_write;
1067                while (i!=store_queue_ptr_read)
1068                  {
1069                    i=((i==0)?_param->_size_store_queue:i)-1;
1070                   
1071                    log_printf(TRACE,Load_store_unit,FUNCTION,"      * i                         : %d",i);
1072                   
1073                    reg_STORE_QUEUE_NB_CHECK [i] ++;
1074
1075                    log_printf(TRACE,Load_store_unit,FUNCTION,"              * reg_STORE_QUEUE_NB_CHECK 3 [%d] <- %d", i,reg_STORE_QUEUE_NB_CHECK [i]);
1076                  }
1077              }
1078          }
1079
1080        //================================================================
1081        // Interface "DCACHE_RSP"
1082        //================================================================
1083        if ((PORT_READ(in_DCACHE_RSP_VAL[0])== 1) and
1084            (    internal_DCACHE_RSP_ACK == 1))
1085          {
1086            log_printf(TRACE,Load_store_unit,FUNCTION,"  * DCACHE_RSP [0]");
1087
1088            // don't use context_id : because there are one queue for all thread
1089            //Tcontext_t      context_id = PORT_READ(in_DCACHE_RSP_CONTEXT_ID[0]);
1090            Tpacket_t       packet_id  = PORT_READ(in_DCACHE_RSP_PACKET_ID [0]);
1091            Tdcache_data_t  rdata      = PORT_READ(in_DCACHE_RSP_RDATA     [0]);
1092            Tdcache_error_t error      = PORT_READ(in_DCACHE_RSP_ERROR     [0]);
1093
1094            log_printf(TRACE,Load_store_unit,FUNCTION,"    * original packet_id : %d"  , packet_id);
1095            log_printf(TRACE,Load_store_unit,FUNCTION,"    * packet_id          : %d"  , packet_id>>1);
1096            log_printf(TRACE,Load_store_unit,FUNCTION,"    * rdata              : %.8x", rdata);
1097            log_printf(TRACE,Load_store_unit,FUNCTION,"    * error              : %d"  , error);
1098           
1099            if (DCACHE_RSP_IS_LOAD(packet_id) == 1)
1100              {
1101                packet_id >>= 1;
1102
1103                log_printf(TRACE,Load_store_unit,FUNCTION,"    * packet is a LOAD");
1104 
1105#ifdef DEBUG_TEST
1106                if (not have_dcache_rsp(_load_queue [packet_id]._operation))
1107                  throw ERRORMORPHEO(FUNCTION,_("Receive of respons, but the corresponding operation don't wait a respons."));
1108#endif
1109
1110                Tdcache_data_t data = _load_queue [packet_id]._rdata;
1111
1112                log_printf(TRACE,Load_store_unit,FUNCTION,"    * data construction");
1113                log_printf(TRACE,Load_store_unit,FUNCTION,"      * data from cache     : 0x%.8x",rdata);
1114                log_printf(TRACE,Load_store_unit,FUNCTION,"      * data (before)       : 0x%.8x", data);
1115                log_printf(TRACE,Load_store_unit,FUNCTION,"      * check_hit_byte      : 0x%x"  ,_load_queue [packet_id]._check_hit_byte);
1116                for (uint32_t i=0;i<(_param->_size_general_data>>3)/*8*/; ++i)
1117                  // Test if this byte has been checked
1118                  if ((_load_queue [packet_id]._check_hit_byte & (1<<i)) == 0)
1119                    {
1120                      log_printf(TRACE,Load_store_unit,FUNCTION,"      * no previous check ]%d:%d]",(i+1)<<3,i<<3);
1121                      data = insert<Tdcache_data_t>(data,rdata,((i+1)<<3)-1,i<<3);
1122                    }
1123                log_printf(TRACE,Load_store_unit,FUNCTION,"      * data (after)        : 0x%.8x", data);
1124               
1125                _load_queue [packet_id]._rdata = data;
1126               
1127                if (error != DCACHE_ERROR_NONE)
1128                  {
1129                    log_printf(TRACE,Load_store_unit,FUNCTION,"    * have a bus error !!!");
1130
1131                    _load_queue [packet_id]._exception = EXCEPTION_MEMORY_BUS_ERROR;
1132                    _load_queue [packet_id]._state     = LOAD_QUEUE_COMMIT;
1133
1134                   
1135                    log_printf(TRACE,Load_store_unit,FUNCTION,"      * store_queue_ptr_write : %d", _load_queue[packet_id]._store_queue_ptr_write);
1136                    log_printf(TRACE,Load_store_unit,FUNCTION,"      * store_queue_ptr_read  : %d", _load_queue[packet_id]._store_queue_ptr_read );
1137                    log_printf(TRACE,Load_store_unit,FUNCTION,"      * store_queue_empty     : %d", _load_queue[packet_id]._store_queue_empty    );
1138
1139                    if (not _load_queue[packet_id]._store_queue_empty)
1140                      {
1141                        uint32_t i=_load_queue[packet_id]._store_queue_ptr_write;
1142                       
1143                        while (i!=_load_queue[packet_id]._store_queue_ptr_read)
1144                          {
1145                            i=((i==0)?_param->_size_store_queue:i)-1;
1146                           
1147#ifdef DEBUG
1148                            if (reg_STORE_QUEUE_NB_CHECK [i] == 0)
1149                              throw ERRORMORPHEO(FUNCTION,_("reg_STORE_QUEUE_NB_CHECK must be > 0\n"));
1150#endif
1151                           
1152                            reg_STORE_QUEUE_NB_CHECK [i] --;
1153
1154                            log_printf(TRACE,Load_store_unit,FUNCTION,"              * reg_STORE_QUEUE_NB_CHECK 4 [%d] <- %d", i,reg_STORE_QUEUE_NB_CHECK [i]);
1155
1156                            //i=(i+1)%_param->_size_store_queue;
1157                          }
1158                        _load_queue[packet_id]._store_queue_empty = true; // end of check
1159
1160                      }
1161                  }
1162                else
1163                  {
1164                    log_printf(TRACE,Load_store_unit,FUNCTION,"    * have no bus error.");
1165                    log_printf(TRACE,Load_store_unit,FUNCTION,"      * previous state : %s",toString(_load_queue [packet_id]._state).c_str());
1166
1167                    // FIXME : convention : if bus error, the cache return the fautive address !
1168                    // But, the load's address is aligned !
1169
1170                    switch (_load_queue [packet_id]._state)
1171                      {
1172                      case LOAD_QUEUE_WAIT_CHECK : _load_queue [packet_id]._state = LOAD_QUEUE_COMMIT_CHECK; break;
1173                      case LOAD_QUEUE_WAIT       : _load_queue [packet_id]._state = LOAD_QUEUE_COMMIT      ; break;
1174                      default : throw ERRORMORPHEO(FUNCTION,_("Illegal state (dcache_rsp).")); break;
1175                      }
1176                  }
1177              }
1178            else
1179              {
1180                log_printf(TRACE,Load_store_unit,FUNCTION,"    * packet is a STORE");
1181               
1182                // TODO : les stores ne génére pas de réponse sauf quand c'est un bus error !!!
1183                throw ERRORMORPHEO(FUNCTION,_("dcache_rsp : no respons to a write. (TODO : manage bus error to the store operation.)"));
1184              }
1185           
1186          }
1187       
1188        // this register is to manage the priority of check -> Round robin
1189        reg_LOAD_QUEUE_CHECK_PRIORITY = (reg_LOAD_QUEUE_CHECK_PRIORITY+1)%_param->_size_load_queue;
1190       
1191       
1192#if defined(DEBUG) and (DEBUG>=DEBUG_TRACE)
1193        // ***** dump store queue
1194        log_printf(TRACE,Load_store_unit,FUNCTION,"  * Dump STORE_QUEUE");
1195        log_printf(TRACE,Load_store_unit,FUNCTION,"    * ptr_read : %d",reg_STORE_QUEUE_PTR_READ);
1196       
1197        for (uint32_t i=0; i<_param->_size_store_queue; i++)
1198          {
1199            uint32_t j = (reg_STORE_QUEUE_PTR_READ+i)%_param->_size_store_queue;
1200
1201            log_printf(TRACE,Load_store_unit,FUNCTION,"    [%.4d] %.4d %.4d %.4d, %.4d, %.4d, %.4d, %.8x %.8x, %.2d %.1d, %.2d %s",
1202                       j,
1203                       _store_queue[j]._context_id          ,
1204                       _store_queue[j]._front_end_id        ,
1205                       _store_queue[j]._ooo_engine_id       ,
1206                       _store_queue[j]._packet_id           ,
1207                       _store_queue[j]._operation           ,
1208                       _store_queue[j]._load_queue_ptr_write,
1209                       _store_queue[j]._address             ,
1210                       _store_queue[j]._wdata               ,
1211                     //_store_queue[j]._write_rd            ,
1212                     //_store_queue[j]._num_reg_rd          ,
1213                       _store_queue[j]._exception           ,
1214                       _store_queue[j]._send_commit         ,
1215                       reg_STORE_QUEUE_NB_CHECK  [j]        ,
1216                       toString(_store_queue[j]._state).c_str());
1217          }
1218
1219        // ***** dump speculative_access queue
1220        log_printf(TRACE,Load_store_unit,FUNCTION,"  * Dump SPECULATIVE_ACCESS_QUEUE");
1221       
1222        for (uint32_t i=0; i<_param->_size_speculative_access_queue; i++)
1223          {
1224            uint32_t j = (*_speculative_access_queue_control)[i];
1225
1226            log_printf(TRACE,Load_store_unit,FUNCTION,"    [%.4d] %.4d %.4d %.4d, %.4d, %.4d, %.4d %.4d %.4d %.1d, %.8x, %.1d %.4d, %.2d, %s",
1227                       j,
1228                       _speculative_access_queue[j]._context_id          ,
1229                       _speculative_access_queue[j]._front_end_id        ,
1230                       _speculative_access_queue[j]._ooo_engine_id       ,
1231                       _speculative_access_queue[j]._packet_id           ,
1232                       _speculative_access_queue[j]._operation           ,
1233                       _speculative_access_queue[j]._load_queue_ptr_write,
1234                       _speculative_access_queue[j]._store_queue_ptr_write,
1235                       _speculative_access_queue[j]._store_queue_ptr_read ,
1236                       _speculative_access_queue[j]._store_queue_empty    ,
1237                       _speculative_access_queue[j]._address             ,
1238                       _speculative_access_queue[j]._write_rd            ,
1239                       _speculative_access_queue[j]._num_reg_rd          ,
1240                       _speculative_access_queue[j]._exception           ,
1241                       toString(_speculative_access_queue[j]._state).c_str());
1242          }
1243
1244        // ***** dump load queue
1245        log_printf(TRACE,Load_store_unit,FUNCTION,"  * Dump LOAD_QUEUE");
1246        log_printf(TRACE,Load_store_unit,FUNCTION,"    * ptr_read_check_priority : %d",reg_LOAD_QUEUE_CHECK_PRIORITY);
1247       
1248        for (uint32_t i=0; i<_param->_size_load_queue; i++)
1249          {
1250            uint32_t j = i;
1251
1252            log_printf(TRACE,Load_store_unit,FUNCTION,"    [%.4d] %.4d %.4d %.4d, %.4d, %.4d, %.4d %.4d %.1d, %.8x %.1x %.1d %.2d %.1d %.2d, %.8x, %.1d %.4d, %.2d, %s",
1253                       j,
1254                       _load_queue[j]._context_id          ,
1255                       _load_queue[j]._front_end_id        ,
1256                       _load_queue[j]._ooo_engine_id       ,
1257                       _load_queue[j]._packet_id           ,
1258                       _load_queue[j]._operation           ,
1259                       _load_queue[j]._store_queue_ptr_write,
1260                       _load_queue[j]._store_queue_ptr_read ,
1261                       _load_queue[j]._store_queue_empty    ,
1262                       _load_queue[j]._address             ,
1263                       _load_queue[j]._check_hit_byte      , 
1264                       _load_queue[j]._check_hit           ,
1265                       _load_queue[j]._shift               ,
1266                       _load_queue[j]._is_load_signed      ,
1267                       _load_queue[j]._access_size         ,
1268                       _load_queue[j]._rdata               ,
1269                       _load_queue[j]._write_rd            ,
1270                       _load_queue[j]._num_reg_rd          ,
1271                       _load_queue[j]._exception           ,
1272                       toString(_load_queue[j]._state).c_str());
1273          }
1274#endif
1275       
1276#ifdef STATISTICS
1277        if (usage_is_set(_usage,USE_STATISTICS))
1278          {
1279            for (uint32_t i=0; i<_param->_size_store_queue; i++)
1280              if (_store_queue[i]._state != STORE_QUEUE_EMPTY)
1281                (*_stat_use_store_queue) ++;
1282            for (uint32_t i=0; i<_param->_size_speculative_access_queue; i++)
1283              if (_speculative_access_queue[i]._state != SPECULATIVE_ACCESS_QUEUE_EMPTY)
1284                (*_stat_use_speculative_access_queue) ++;
1285            for (uint32_t i=0; i<_param->_size_load_queue; i++)
1286              if (_load_queue[i]._state != LOAD_QUEUE_EMPTY)
1287                (*_stat_use_load_queue) ++;
1288          }
1289#endif
1290      }
1291
1292    log_end(Load_store_unit,FUNCTION);
1293  };
1294
1295}; // end namespace load_store_unit
1296}; // end namespace execute_unit
1297}; // end namespace multi_execute_unit
1298}; // end namespace execute_loop
1299}; // end namespace multi_execute_loop
1300}; // end namespace core
1301
1302}; // end namespace behavioural
1303}; // end namespace morpheo             
1304#endif
Note: See TracBrowser for help on using the repository browser.