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

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

1) Prediction unit : static prediction not blocking

  • Property svn:keywords set to Id
File size: 55.7 KB
Line 
1#ifdef SYSTEMC
2/*
3 * $Id: Load_store_unit_function_speculative_load_commit_transition.cpp 119 2009-05-25 17:40:26Z 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]",reg_STORE_QUEUE_PTR_READ);
278           
279                  // Entry flush and increase the read pointer
280                  _store_queue [reg_STORE_QUEUE_PTR_READ]._state = STORE_QUEUE_EMPTY;
281                 
282                  reg_STORE_QUEUE_PTR_READ = (reg_STORE_QUEUE_PTR_READ+1)%_param->_size_store_queue;
283
284                  break;
285                }
286              case SELECT_LOAD_QUEUE :
287                {
288                  // ======================
289                  // ===== LOAD_QUEUE =====
290                  // ======================
291                 
292                  log_printf(TRACE,Load_store_unit,FUNCTION,"    * load_queue  [%d]",internal_MEMORY_OUT_PTR);
293                 
294                  // Entry flush and increase the read pointer
295                 
296                  _load_queue [internal_MEMORY_OUT_PTR]._state = LOAD_QUEUE_EMPTY;
297                 
298                  // reg_LOAD_QUEUE_PTR_READ = (reg_LOAD_QUEUE_PTR_READ+1)%_param->_size_load_queue;
299
300                  break;
301                }
302              case SELECT_LOAD_QUEUE_SPECULATIVE :
303                {
304                  log_printf(TRACE,Load_store_unit,FUNCTION,"    * load_queue  [%d] (speculative)",internal_MEMORY_OUT_PTR);
305                 
306                  // !!! WARNING !!!
307                  // !!! Test special case :
308                  // !!! in a cycle an instruction can check the last store AND commit instruction
309                  // !!! also the memory_out is before the port_check
310
311                  _load_queue [internal_MEMORY_OUT_PTR]._state    = LOAD_QUEUE_CHECK;
312                  // NOTE : a speculative load write in the register file.
313                  // if the speculation is a miss, write_rd is re set at 1.
314                  _load_queue [internal_MEMORY_OUT_PTR]._write_rd = 0;
315
316#ifdef STATISTICS
317                  if (usage_is_set(_usage,USE_STATISTICS))
318                    (*_stat_nb_inst_load_commit_speculative) ++;
319#endif
320
321                  break;
322                }
323
324                break;
325              }
326          }
327
328        //================================================================
329        // Interface "PORT_CHECK"
330        //================================================================
331       
332        // Plusieurs moyens de faire la verification de dépendance entre les loads et les stores.
333        //  1) un load ne peut vérifier qu'un store par cycle. Dans ce cas port_check <= size_load_queue
334        //  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.
335
336        // solution 1)
337        log_printf(TRACE,Load_store_unit,FUNCTION,"  * CHECK");
338        for (uint32_t i=0, nb_check=0; (nb_check<_param->_nb_port_check) and (i<_param->_size_load_queue); i++)
339          {
340            // Get an index from load queue
341            uint32_t index_load = (i + reg_LOAD_QUEUE_CHECK_PRIORITY)%_param->_size_load_queue;
342
343            // Test if this load must ckecked store queue
344            if (((_load_queue[index_load]._state == LOAD_QUEUE_WAIT_CHECK) or
345                 (_load_queue[index_load]._state == LOAD_QUEUE_COMMIT_CHECK) or
346                 (_load_queue[index_load]._state == LOAD_QUEUE_CHECK)) and
347                is_operation_memory_load(_load_queue[index_load]._operation))
348              {
349                log_printf(TRACE,Load_store_unit,FUNCTION,"    * Find a load : %d",index_load);
350
351                nb_check++; // use one port
352
353                // find a entry that it need a check
354                Tlsq_ptr_t index_store     = _load_queue[index_load]._store_queue_ptr_write;
355//              Tlsq_ptr_t index_store_old = index_store;
356
357                // Init variable
358                bool       end_check    = false;
359                bool       change_state = false;
360                bool       next         = false;
361
362                // At the first store queue empty, stop check.
363                // Explication :
364                //  * rename logic keep a empty case in the store queue (also size_store_queue > 1)
365                //  * when a store is out of store queue, also it was in head of re order buffer. Also, they are none previous load.
366
367                log_printf(TRACE,Load_store_unit,FUNCTION,"    * index_store : %d",index_store);
368                log_printf(TRACE,Load_store_unit,FUNCTION,"    * ptr_read    : %d",reg_STORE_QUEUE_PTR_READ);
369
370                if (index_store == reg_STORE_QUEUE_PTR_READ)
371                  {
372                    log_printf(TRACE,Load_store_unit,FUNCTION,"      * index_store == reg_STORE_QUEUE_PTR_READ");
373                    end_check    = true;
374                    change_state = true;
375                  }
376                else
377                  {
378                    log_printf(TRACE,Load_store_unit,FUNCTION,"      * index_store != reg_STORE_QUEUE_PTR_READ");
379
380                    index_store = (index_store-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
381
382                    log_printf(TRACE,Load_store_unit,FUNCTION,"      * index_store : %d",index_store);
383                   
384                    // switch on store_queue state
385                    switch (_store_queue[index_store]._state)
386                      {
387                      case STORE_QUEUE_VALID_NO_SPECULATIVE : 
388                      case STORE_QUEUE_COMMIT :
389                      case STORE_QUEUE_VALID_SPECULATIVE :
390                        {
391                         
392                          log_printf(TRACE,Load_store_unit,FUNCTION,"      * store have a valid entry");
393                         
394                          // TODO : MMU - nous considérons que les adresses sont physique
395                          bool test_thread_id = true;
396                         
397                          // Test thread id
398                          if (_param->_have_port_context_id)
399                            test_thread_id &= (_load_queue[index_load]._context_id    == _store_queue[index_store]._context_id);
400                          if (_param->_have_port_front_end_id)
401                            test_thread_id &= (_load_queue[index_load]._front_end_id  == _store_queue[index_store]._front_end_id);
402                          if (_param->_have_port_ooo_engine_id)
403                            test_thread_id &= (_load_queue[index_load]._ooo_engine_id == _store_queue[index_store]._ooo_engine_id);
404                         
405                          if (test_thread_id)
406                            {
407                              // the load and store are in the same thread. Now, we must test address.
408
409                              log_printf(TRACE,Load_store_unit,FUNCTION,"        * load and store is the same thread.");
410                              Tdcache_address_t load_addr  = _load_queue [index_load ]._address;
411                              Tdcache_address_t store_addr = _store_queue[index_store]._address;
412                             
413                              log_printf(TRACE,Load_store_unit,FUNCTION,"          * load_addr                     : %.8x.",load_addr );
414                              log_printf(TRACE,Load_store_unit,FUNCTION,"          * store_addr                    : %.8x.",store_addr);
415                              log_printf(TRACE,Load_store_unit,FUNCTION,"          * load_addr  & mask_address_msb : %.8x.",load_addr  & _param->_mask_address_msb);
416                              log_printf(TRACE,Load_store_unit,FUNCTION,"          * store_addr & mask_address_msb : %.8x.",store_addr & _param->_mask_address_msb);
417                              // Test if the both address target the same "word"
418                              if ((load_addr  & _param->_mask_address_msb) == 
419                                  (store_addr & _param->_mask_address_msb))
420                                {
421                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * address_msb is the same.");
422                                  // all case - [] : store, () : load
423                                  // (1) store_max >= load_max and store_min <= load_min  ...[...(...)...]... Ok - inclusion in store
424                                  // (2) store_min >  load_max                            ...[...]...(...)... Ok - no conflit
425                                  // (3) store_max <  load_min                            ...(...)...[...]... Ok - no conflit
426                                  // (4) store_max <  load_max and store_min >  load_min  ...(...[...]...)... Ko - inclusion in load
427                                  // (5) store_max >= load_max and store_min >  load_min  ...[...(...]...)... Ko - conflit
428                                  // (6) store_max <  load_max and store_min <= load_min  ...(...[...)...]... Ko - conflit
429                                  // but :
430                                  // load in the cache is a word !
431                                  // the mask can be make when the load is commited. Also, the rdata content a full word.
432                                  // the only case is (4)
433                                 
434                                  // Read data
435                                  bool is_big_endian = true;
436
437                                  Tgeneral_data_t   load_data      = _load_queue [index_load ]._rdata  ;
438                                  Tgeneral_data_t   store_data     = _store_queue[index_store]._wdata  ;
439                                  Tdcache_address_t check_hit_byte = _load_queue [index_load ]._check_hit_byte;
440                                  Tcontrol_t        check_hit      = _load_queue [index_load ]._check_hit;
441                                  uint32_t          load_size_access  = memory_size(_load_queue [index_load ]._operation)>>3;
442                                  uint32_t          store_size_access = memory_size(_store_queue[index_store]._operation)>>3;
443
444                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * is_big_endian           : %d",is_big_endian);
445                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * load_data               : 0x%.8x",load_data);
446                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * store_data              : 0x%.8x",store_data);
447                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * check_hit_byte          : %x",check_hit_byte);
448                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * check_hit               : %d",check_hit);
449
450                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * load_size_access        : %d",load_size_access );
451                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * store_size_access       : %d",store_size_access);
452
453                                  if (is_big_endian)
454                                    {
455                                      // swap in little endian
456                                      load_data      = swapBytes<Tgeneral_data_t  >(load_data     , _param->_size_general_data>>3,load_size_access);
457                                      store_data     = swapBytes<Tgeneral_data_t  >(store_data    , _param->_size_general_data>>3,store_size_access);
458                                      check_hit_byte = swapBits <Tdcache_address_t>(check_hit_byte, _param->_size_general_data>>3,load_size_access);
459                                     
460                                     
461                                      log_printf(TRACE,Load_store_unit,FUNCTION,"            * load_data      (swap 1) : 0x%.8x",load_data);
462                                      log_printf(TRACE,Load_store_unit,FUNCTION,"            * store_data     (swap 1) : 0x%.8x",store_data);
463                                      log_printf(TRACE,Load_store_unit,FUNCTION,"            * check_hit_byte (swap 1) : %x",check_hit_byte);
464                                    }
465
466                                  uint32_t store_nb_byte     = (1<<memory_access(_store_queue[index_store]._operation));
467
468                                  // Take interval to the store
469                                  uint32_t store_num_byte_min = (store_addr & _param->_mask_address_lsb);
470                                  uint32_t store_num_byte_max = store_num_byte_min+store_nb_byte;
471
472                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * store_num_byte_min      : %d",store_num_byte_min);
473                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * store_num_byte_max      : %d",store_num_byte_max);
474
475//                                   uint32_t load_nb_byte      = (1<<memory_access(_load_queue[index_load]._operation));
476
477//                                uint32_t load_num_byte_min = (load_addr & _param->_mask_address_lsb);
478//                                uint32_t load_num_byte_max = load_num_byte_min+load_nb_byte;
479
480//                                log_printf(TRACE,Load_store_unit,FUNCTION,"            * load_num_byte_min       : %d",load_num_byte_min);
481//                                log_printf(TRACE,Load_store_unit,FUNCTION,"            * load_num_byte_max       : %d",load_num_byte_max);
482
483//                                for (uint32_t num_load_byte=load_num_byte_min; num_load_byte<load_num_byte_max; num_load_byte ++)
484//                                  {
485//                                       // Make a mask
486//                                       uint32_t num_store_byte = num_load_byte;
487                                     
488
489
490                                  // The bypass is checked byte per byte
491                                  // Is same endianness : because to change endianness, we must write in special register. Also the pipeline is flushed.
492                                  for (uint32_t num_store_byte=store_num_byte_min; num_store_byte<store_num_byte_max; num_store_byte ++)
493                                    {
494                                      // Make a mask
495                                      uint32_t num_load_byte = num_store_byte;
496
497//                                       if (is_big_endian)
498//                                         {
499//                                           // sd 0 : 0 1 2 3 4 5 6 7
500//                                           // ld 0 : 0 1 2 3 4 5 6 7 >>  0
501//                                           // lw 0 :         0 1 2 3 >>  0 -4
502//                                           // lw 4 : 4 5 6 7         >> 32 +4
503//                                           // lh 0 :             0 1 >>  0 -6
504//                                           // lh 2 :         2 3     >> 16 -2
505//                                           // lh 4 :     4 5         >> 32 +2
506//                                           // lh 6 : 6 7             >> 48 +6
507//                                           // lb 0 :               0 >>  0 -7
508//                                           // lb 1 :             1   >>  8 -5
509//                                           // lb 2 :           2     >> 16 -3
510//                                           // lb 3 :         3       >> 24 -1
511//                                           // lb 4 :       4         >> 32 +1
512//                                           // lb 5 :     5           >> 40 +3
513//                                           // lb 6 :   6             >> 48 +5
514//                                           // lb 7 : 7               >> 56 +7
515
516//                                           // diff : (store_nb_byte + load_nb_byte) - 2*nb_load_byte*((num_store_byte+1)
517
518//                                           // store duplicate = all store access can be see as full size_data store
519// //                                           uint32_t load_nb_byte = (1<<memory_access(_load_queue [index_load ]._operation));
520
521// //                                           int32_t diff = ((_param->_size_general_data>>3)+load_nb_byte-2*load_nb_byte*((num_store_byte/load_nb_byte)+1));
522
523// //                                           num_load_byte =num_store_byte+diff;
524
525// //                                           log_printf(TRACE,Load_store_unit,FUNCTION,"              * load_nb_byte   : %d",load_nb_byte);
526// //                                           log_printf(TRACE,Load_store_unit,FUNCTION,"              * diff           : %d",diff);
527
528
529//                                           num_load_byte = num_store_byte;
530//                                         }
531//                                       else
532//                                         {
533//                                           // sd 0 : 0 1 2 3 4 5 6 7
534//                                           // ld 0 : 0 1 2 3 4 5 6 7 >>  0
535//                                           // lw 0 :         4 5 6 7 >>  0
536//                                           // lw 4 : 0 1 2 3         >> 32
537//                                           // lh 0 :             6 7 >>  0
538//                                           // lh 2 :         4 5     >> 16
539//                                           // lh 4 :     2 3         >> 32
540//                                           // lh 6 : 0 1             >> 48
541//                                           // lb 0 :               7 >>  0
542//                                           // lb 1 :             6   >>  8
543//                                           // lb 2 :           5     >> 16
544//                                           // lb 3 :         4       >> 24
545//                                           // lb 4 :       3         >> 32
546//                                           // lb 5 :     2           >> 40
547//                                           // lb 6 :   1             >> 48
548//                                           // lb 7 : 0               >> 56
549                                         
550//                                           num_load_byte = num_store_byte;
551//                                         }
552
553                                      uint32_t mask  = 1<<num_load_byte;
554
555                                      log_printf(TRACE,Load_store_unit,FUNCTION,"              * num_store_byte : %d",num_store_byte);
556                                      log_printf(TRACE,Load_store_unit,FUNCTION,"              * num_load_byte  : %d",num_load_byte);
557                                      log_printf(TRACE,Load_store_unit,FUNCTION,"              * mask           : %d",mask);
558
559                                      // Accept the bypass if :
560                                      //   * they have not a previous bypass with an another store
561                                      //   * it's a valid request of load
562                                      if ((check_hit_byte&mask)==0)
563                                        {
564                                          // Note : Store is duplicate = all store access can be see as full size_data store
565
566                                          uint32_t num_store_bit_min = num_store_byte<<3; //*8
567//                                        uint32_t num_store_bit_max = num_store_bit_min+8-1;
568                                          uint32_t num_load_bit_min  = num_load_byte <<3; //*8
569                                          uint32_t num_load_bit_max  = num_load_bit_min+8-1;
570
571                                          log_printf(TRACE,Load_store_unit,FUNCTION,"              * bypass !!!");
572//                                        log_printf(TRACE,Load_store_unit,FUNCTION,"              * interval store : [%d:%d]",num_store_bit_max,num_store_bit_min);
573                                          log_printf(TRACE,Load_store_unit,FUNCTION,"              * interval store : [..:%d]",num_store_bit_min);
574                                          log_printf(TRACE,Load_store_unit,FUNCTION,"              * interval load  : [%d:%d]",num_load_bit_max,num_load_bit_min);
575                                          log_printf(TRACE,Load_store_unit,FUNCTION,"                * rdata_old : 0x%.8x", load_data);
576
577                                          load_data = ((((store_data>>num_store_bit_min) & 0xff) << num_load_bit_min) |
578                                                       mask_not<Tdcache_data_t>(load_data,num_load_bit_max,num_load_bit_min));
579
580                                          check_hit_byte |= mask;
581                                          check_hit       = 1;
582                                          change_state = true;
583
584                                          log_printf(TRACE,Load_store_unit,FUNCTION,"                * rdata_new : 0x%.8x", load_data);
585                                        }
586                                    }
587
588                                  if (is_big_endian)
589                                    {
590                                      // swap in little endian
591                                      load_data      = swapBytes<Tgeneral_data_t  >(load_data     , _param->_size_general_data>>3,load_size_access);
592                                      check_hit_byte = swapBits <Tdcache_address_t>(check_hit_byte, _param->_size_general_data>>3,load_size_access);
593                                     
594                                     
595                                      log_printf(TRACE,Load_store_unit,FUNCTION,"            * load_data      (swap 2) : 0x%.8x",load_data);
596                                      log_printf(TRACE,Load_store_unit,FUNCTION,"            * check_hit_byte (swap 2) : %x",check_hit_byte);
597                                    }
598
599                                  _load_queue[index_load]._rdata          = load_data;
600                                  _load_queue[index_load]._check_hit_byte = check_hit_byte;
601                                  _load_queue[index_load]._check_hit      = check_hit;
602
603                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * load_data  (after) : 0x%.8x",load_data);
604
605                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * check_hit          : %x",check_hit);
606                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * check_hit_byte     : %x",check_hit_byte);
607
608                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * mask_end_check     : %x",(-1& _param->_mask_address_lsb));
609                                  log_printf(TRACE,Load_store_unit,FUNCTION,"            * mask_check_hit_byte: %x",_param->_mask_check_hit_byte);
610                                  // The check is finish if all bit is set
611                                  end_check = (_load_queue[index_load]._check_hit_byte == _param->_mask_check_hit_byte);
612
613                                }
614                            }
615                         
616                          next = true;
617                          break;
618                        }
619                      case STORE_QUEUE_EMPTY :
620                      case STORE_QUEUE_NO_VALID_NO_SPECULATIVE :
621                        {
622                          log_printf(TRACE,Load_store_unit,FUNCTION,"      * store have an invalid entry");
623                          break;
624                        }
625                      }
626                  }
627
628                if (next)
629                  {
630                    log_printf(TRACE,Load_store_unit,FUNCTION,"              * next");
631                    log_printf(TRACE,Load_store_unit,FUNCTION,"                * new store_queue_ptr_write : %d",index_store);
632
633                    log_printf(TRACE,Load_store_unit,FUNCTION,"              * update reg_STORE_QUEUE_NB_CHECK");
634#ifdef DEBUG
635                    if (reg_STORE_QUEUE_NB_CHECK [index_store] == 0)
636                      throw ERRORMORPHEO(FUNCTION,_("reg_STORE_QUEUE_NB_CHECK must be > 0\n"));
637#endif
638                    reg_STORE_QUEUE_NB_CHECK [index_store] --;
639
640//                  if (_load_queue[index_load]._store_queue_ptr_write == 0)
641//                    _load_queue[index_load]._store_queue_ptr_write = _param->_size_store_queue-1;
642//                  else
643//                    _load_queue[index_load]._store_queue_ptr_write --;
644                    _load_queue[index_load]._store_queue_ptr_write = index_store; // because the index store have be decrease
645
646                    // 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 "reg_STORE_QUEUE_PTR_READ"
647                    if (index_store == reg_STORE_QUEUE_PTR_READ)
648                      {
649                        end_check    = true;
650                        change_state = true;
651                      }
652                  }
653
654                if (change_state)
655                  {
656                    log_printf(TRACE,Load_store_unit,FUNCTION,"              * change_state");
657                    log_printf(TRACE,Load_store_unit,FUNCTION,"              * end_check : %d",end_check);
658
659                    log_printf(TRACE,Load_store_unit,FUNCTION,"                * state old : %s",toString(_load_queue[index_load]._state).c_str());
660
661                    switch (_load_queue[index_load]._state)
662                      {
663                      case LOAD_QUEUE_WAIT_CHECK   : 
664                        {
665                          if (end_check)
666                            _load_queue[index_load]._state = LOAD_QUEUE_WAIT  ; 
667                          break;
668                        }
669                      case LOAD_QUEUE_COMMIT_CHECK : 
670                        {
671                          if (end_check)
672                            _load_queue[index_load]._state = LOAD_QUEUE_COMMIT; 
673                          else
674                            _load_queue[index_load]._state = LOAD_QUEUE_CHECK; // No commit : check hit and no end
675                          break;
676                        }
677                      case LOAD_QUEUE_CHECK        : 
678                        {
679                          if (end_check)
680                            _load_queue[index_load]._state     = LOAD_QUEUE_COMMIT;
681
682                          // check find a bypass. A speculative load have been committed : report a speculation miss.
683                          if ((_load_queue[index_load]._check_hit != 0) and
684                              (_load_queue[index_load]._write_rd  == 0) // is commit
685                              )
686                            {
687                              _load_queue[index_load]._exception = EXCEPTION_MEMORY_MISS_SPECULATION;
688                              _load_queue[index_load]._write_rd  = 1; // write the good result
689
690#ifdef STATISTICS
691                              if (usage_is_set(_usage,USE_STATISTICS))
692                                (*_stat_nb_inst_load_commit_miss) ++;
693#endif
694                            }
695                         
696                          break;
697                        }
698                      default : break;
699                      }
700                    log_printf(TRACE,Load_store_unit,FUNCTION,"                * state new : %s",toString(_load_queue[index_load]._state).c_str());
701                    log_printf(TRACE,Load_store_unit,FUNCTION,"                * exception : %d",_load_queue[index_load]._exception);
702
703                    if (end_check)
704                      {
705                        log_printf(TRACE,Load_store_unit,FUNCTION,"                * end check, decrease all nb_check");
706                       
707                        uint32_t i=index_store;
708                        while (i!=reg_STORE_QUEUE_PTR_READ)
709                          {
710                            i=((i==0)?_param->_size_store_queue:i)-1;
711                           
712#ifdef DEBUG
713                            if (reg_STORE_QUEUE_NB_CHECK [i] == 0)
714                              throw ERRORMORPHEO(FUNCTION,_("reg_STORE_QUEUE_NB_CHECK must be > 0\n"));
715#endif
716                           
717                            reg_STORE_QUEUE_NB_CHECK [i] --;
718                            //i=(i+1)%_param->_size_store_queue;
719                          }
720                      }
721                  }
722              }
723            // else : don't use a port
724          }
725       
726        //================================================================
727        // Interface "MEMORY_IN"
728        //================================================================
729       
730        if ((PORT_READ(in_MEMORY_IN_VAL [internal_MEMORY_IN_PORT]) == 1) and
731            (    internal_MEMORY_IN_ACK  == 1))
732          {
733            log_printf(TRACE,Load_store_unit,FUNCTION,"  * MEMORY_IN [%d]",internal_MEMORY_IN_PORT);
734
735            // Test operation :
736            //~~~~~~~~~~~~~~~~~
737            //  store  in store_queue
738            //  load   in speculation_access_queue
739            //  others in speculation_access_queue
740
741#ifdef DEBUG_TEST
742            if (PORT_READ(in_MEMORY_IN_TYPE [internal_MEMORY_IN_PORT]) != TYPE_MEMORY)
743              throw ERRORMORPHEO(FUNCTION,"The type is different at 'TYPE_MEMORY'");
744#endif
745            Toperation_t    operation            = PORT_READ(in_MEMORY_IN_OPERATION[internal_MEMORY_IN_PORT]);
746            Tgeneral_data_t address              = (PORT_READ(in_MEMORY_IN_IMMEDIAT[internal_MEMORY_IN_PORT]) +
747                                                    PORT_READ(in_MEMORY_IN_DATA_RA [internal_MEMORY_IN_PORT]));
748            bool            exception_alignement = (mask_memory_access(operation) & address) != 0;
749                                                   
750            if (is_operation_memory_store(operation) == true)
751              {
752                // =======================
753                // ===== STORE_QUEUE =====
754                // =======================
755                // There a two store request type :
756                //   - first is operation with address and data
757                //   - second is the information of re order buffer : the store become not speculative and can access at the data cache
758
759                log_printf(TRACE,Load_store_unit,FUNCTION,"    * store_queue");
760                log_printf(TRACE,Load_store_unit,FUNCTION,"      * PUSH");
761               
762                // Write pointer is define in rename stage :
763                Tlsq_ptr_t           index         = PORT_READ(in_MEMORY_IN_STORE_QUEUE_PTR_WRITE[internal_MEMORY_IN_PORT]);
764                log_printf(TRACE,Load_store_unit,FUNCTION,"      * index         : %d",index);
765               
766                // Need read : state and exception.
767                Tstore_queue_state_t old_state     = _store_queue [index]._state;
768                Tstore_queue_state_t new_state     = old_state;
769                bool                 update_info   = false;
770
771                Texception_t         old_exception = _store_queue [index]._exception;
772                Texception_t         new_exception = old_exception;
773
774                // Compute next state
775                switch (old_state)
776                  {
777                  case STORE_QUEUE_EMPTY                   :
778                    {
779                      if (is_operation_memory_store_head(operation) == true)
780                        {
781                          new_state = STORE_QUEUE_NO_VALID_NO_SPECULATIVE;
782
783                          // test if is a speculation
784                          if (operation == OPERATION_MEMORY_STORE_HEAD_KO)
785                            new_exception = EXCEPTION_MEMORY_MISS_SPECULATION;
786                          else
787                            new_exception = EXCEPTION_MEMORY_NONE;
788                        }
789                      else
790                        {
791                          new_state = STORE_QUEUE_VALID_SPECULATIVE;
792
793                          // Test if have an exception
794                          if (exception_alignement == true)
795                            new_exception = EXCEPTION_MEMORY_ALIGNMENT;
796                          else
797                            new_exception = EXCEPTION_MEMORY_NONE;
798
799                          update_info = true;
800                        }
801                      break;
802                    }
803                  case STORE_QUEUE_NO_VALID_NO_SPECULATIVE :
804                    {
805#ifdef DEBUG_TEST
806                      if (is_operation_memory_store_head(operation) == true)
807                        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."));
808#endif
809                      // Test if have a new exception (priority : miss_speculation)
810                      if ((exception_alignement == true) and (old_exception == EXCEPTION_MEMORY_NONE))
811                        new_exception = EXCEPTION_MEMORY_ALIGNMENT;
812                     
813                      if (new_exception != EXCEPTION_MEMORY_NONE)
814                        new_state = STORE_QUEUE_COMMIT;
815                      else
816                        new_state = STORE_QUEUE_VALID_NO_SPECULATIVE;
817                     
818                      update_info = true;
819                      break;
820                    }
821                  case STORE_QUEUE_VALID_SPECULATIVE       :
822                    {
823#ifdef DEBUG_TEST
824                      if (is_operation_memory_store_head(operation) == false)
825                        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."));
826#endif
827                      if (operation == OPERATION_MEMORY_STORE_HEAD_KO)
828                        new_exception = EXCEPTION_MEMORY_MISS_SPECULATION; // great prioritary
829                     
830                      if (new_exception != EXCEPTION_MEMORY_NONE)
831                        new_state = STORE_QUEUE_COMMIT;
832                      else
833                        new_state = STORE_QUEUE_VALID_NO_SPECULATIVE;
834                     
835                      break;
836                    }
837                  case STORE_QUEUE_VALID_NO_SPECULATIVE    :
838                  case STORE_QUEUE_COMMIT                  :
839                    {
840                      throw ERRORMORPHEO(FUNCTION,"<Load_store_unit::function_speculative_load_commit_transition> Invalid state and operation");
841                    }
842                  }
843
844                _store_queue [index]._state     = new_state;
845                _store_queue [index]._exception = new_exception;
846               
847                if (update_info == true)
848                  {
849                    log_printf(TRACE,Load_store_unit,FUNCTION,"      * Update information");
850
851                    _store_queue [index]._context_id           = (not _param->_have_port_context_id   )?0:PORT_READ(in_MEMORY_IN_CONTEXT_ID   [internal_MEMORY_IN_PORT]);
852                    _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]);
853                    _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]);
854                    _store_queue [index]._packet_id            = (not _param->_have_port_rob_ptr      )?0:PORT_READ(in_MEMORY_IN_PACKET_ID    [internal_MEMORY_IN_PORT]);
855                    _store_queue [index]._operation            = operation;
856                    _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]);
857                    _store_queue [index]._address              = address;
858
859                    // reordering data
860                    _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); 
861//                  _store_queue [index]._num_reg_rd           = PORT_READ(in_MEMORY_IN_NUM_REG_RD  [internal_MEMORY_IN_PORT]);
862                  }
863              }
864            else
865              {
866                // ====================================
867                // ===== SPECULATIVE_ACCESS_QUEUE =====
868                // ====================================
869
870                // In speculative access queue, they are many type's request
871                log_printf(TRACE,Load_store_unit,FUNCTION,"    * speculative_access_queue");
872                log_printf(TRACE,Load_store_unit,FUNCTION,"      * PUSH");
873               
874                // Write in reservation station
875                uint32_t     index = _speculative_access_queue_control->push();
876
877                log_printf(TRACE,Load_store_unit,FUNCTION,"      * index : %d", index);
878
879                Texception_t exception;
880
881                if (exception_alignement == true)
882                  exception = EXCEPTION_MEMORY_ALIGNMENT;
883                else
884                  exception = EXCEPTION_MEMORY_NONE;
885                               
886                // if exception, don't access at the cache
887                // NOTE : type "other" (lock, invalidate, flush and sync) can't make an alignement exception (access is equivalent at a 8 bits)
888                _speculative_access_queue [index]._state                = (exception == EXCEPTION_MEMORY_NONE)?SPECULATIVE_ACCESS_QUEUE_WAIT_CACHE:SPECULATIVE_ACCESS_QUEUE_WAIT_LOAD_QUEUE;
889                _speculative_access_queue [index]._context_id           = (not _param->_have_port_context_id   )?0:PORT_READ(in_MEMORY_IN_CONTEXT_ID   [internal_MEMORY_IN_PORT]);
890                _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]);
891                _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]);
892                _speculative_access_queue [index]._packet_id            = (not _param->_have_port_rob_ptr      )?0:PORT_READ(in_MEMORY_IN_PACKET_ID    [internal_MEMORY_IN_PORT]);
893
894                _speculative_access_queue [index]._operation            = operation;
895                _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]);
896                _speculative_access_queue [index]._store_queue_ptr_write= PORT_READ(in_MEMORY_IN_STORE_QUEUE_PTR_WRITE[internal_MEMORY_IN_PORT]);
897                _speculative_access_queue [index]._address              = address;
898                // NOTE : is operation is a load, then they are a result and must write in the register file
899                _speculative_access_queue [index]._write_rd             = is_operation_memory_load(operation);
900                _speculative_access_queue [index]._num_reg_rd           = PORT_READ(in_MEMORY_IN_NUM_REG_RD  [internal_MEMORY_IN_PORT]);
901
902                _speculative_access_queue [index]._exception            = exception;
903              }
904          }
905
906        //================================================================
907        // Interface "DCACHE_REQ"
908        //================================================================
909        if ((    internal_DCACHE_REQ_VAL  == 1) and
910            (PORT_READ(in_DCACHE_REQ_ACK[0]) == 1))
911          {
912            log_printf(TRACE,Load_store_unit,FUNCTION,"  * DCACHE_REQ [0]");
913
914            switch (internal_DCACHE_REQ_SELECT_QUEUE)
915              {
916              case SELECT_STORE_QUEUE :
917                {
918                  // =======================
919                  // ===== STORE_QUEUE =====
920                  // =======================
921                 
922                  // Entry flush and increase the read pointer
923                 
924                  _store_queue [reg_STORE_QUEUE_PTR_READ]._state = STORE_QUEUE_COMMIT;
925
926                  break;
927                }
928              case SELECT_LOAD_QUEUE_SPECULATIVE :
929                {
930                  // =========================================
931                  // ===== SELECT_LOAD_QUEUE_SPECULATIVE =====
932                  // =========================================
933
934                  load_queue_push = true;
935                  break;
936                }
937              case SELECT_LOAD_QUEUE :
938                {
939                  throw ERRORMORPHEO(FUNCTION,_("Invalid selection"));
940                  break;
941                }
942
943                break;
944              }
945          }
946
947        if (load_queue_push)
948          {
949            log_printf(TRACE,Load_store_unit,FUNCTION,"  * load_queue_push");
950
951            Tlsq_ptr_t   ptr_write = _speculative_access_queue[internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._load_queue_ptr_write;
952            Toperation_t operation = _speculative_access_queue[internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._operation;
953            Texception_t exception = _speculative_access_queue[internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._exception;
954            bool         have_exception = (exception != EXCEPTION_MEMORY_NONE);
955            bool         need_check= false;
956           
957            if (have_exception)
958              _load_queue [ptr_write]._state = LOAD_QUEUE_COMMIT;
959            else
960              {
961                if (have_dcache_rsp(operation))
962                  {
963                    // load and synchronisation
964                    if (must_check(operation))
965                      {
966                        // load
967                        need_check = true;
968                        _load_queue [ptr_write]._state = LOAD_QUEUE_WAIT_CHECK;
969                      }
970                    else
971                      {
972                        // synchronisation
973                        _load_queue [ptr_write]._state = LOAD_QUEUE_WAIT;
974                      }
975                  }
976                else
977                  {
978                    // lock, prefecth, flush and invalidate
979                    _load_queue [ptr_write]._state = LOAD_QUEUE_COMMIT;
980                  }
981              }
982
983            Tdcache_address_t address        = _speculative_access_queue [internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._address;
984            Tdcache_address_t address_lsb    = (address & _param->_mask_address_lsb);
985            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;
986            Tlsq_ptr_t        store_queue_ptr_write = _speculative_access_queue [internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._store_queue_ptr_write;
987
988            log_printf(TRACE,Load_store_unit,FUNCTION,"    * address                 : 0x%.8x", address);
989            log_printf(TRACE,Load_store_unit,FUNCTION,"    * address_lsb             : 0x%.8x", address_lsb);
990            log_printf(TRACE,Load_store_unit,FUNCTION,"    * operation               : %d", operation);
991            log_printf(TRACE,Load_store_unit,FUNCTION,"    * memory_size             : %d", memory_size(operation));
992            log_printf(TRACE,Load_store_unit,FUNCTION,"    * check_hit_byte          : 0x%x", check_hit_byte);
993
994            _load_queue [ptr_write]._context_id            = _speculative_access_queue [internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._context_id;
995            _load_queue [ptr_write]._front_end_id          = _speculative_access_queue [internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._front_end_id;
996            _load_queue [ptr_write]._ooo_engine_id         = _speculative_access_queue [internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._ooo_engine_id;
997            _load_queue [ptr_write]._packet_id             = _speculative_access_queue [internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._packet_id;
998            _load_queue [ptr_write]._operation             = operation;
999            _load_queue [ptr_write]._store_queue_ptr_write = store_queue_ptr_write;
1000            _load_queue [ptr_write]._address               = address;
1001            _load_queue [ptr_write]._check_hit_byte        = check_hit_byte;
1002            _load_queue [ptr_write]._check_hit             = 0;
1003            _load_queue [ptr_write]._shift                 = address_lsb<<3;// *8
1004            _load_queue [ptr_write]._is_load_signed        = is_operation_memory_load_signed(operation);
1005            _load_queue [ptr_write]._access_size           = memory_size(operation);
1006            // NOTE : if have an exception, must write in register, because a depend instruction wait the load data.
1007            _load_queue [ptr_write]._write_rd              = _speculative_access_queue [internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._write_rd             ;
1008            _load_queue [ptr_write]._num_reg_rd            = _speculative_access_queue [internal_SPECULATIVE_ACCESS_QUEUE_PTR_READ]._num_reg_rd           ;
1009            _load_queue [ptr_write]._exception             = exception;
1010            _load_queue [ptr_write]._rdata                 = address; // to the exception
1011           
1012            log_printf(TRACE,Load_store_unit,FUNCTION,"    * speculative_access_queue");
1013            log_printf(TRACE,Load_store_unit,FUNCTION,"      * POP[%d]",(*_speculative_access_queue_control)[0]);
1014           
1015            _speculative_access_queue [(*_speculative_access_queue_control)[0]]._state = SPECULATIVE_ACCESS_QUEUE_EMPTY;
1016           
1017            _speculative_access_queue_control->pop();
1018
1019#ifdef STATISTICS
1020            if (usage_is_set(_usage,USE_STATISTICS))
1021              (*_stat_nb_inst_load) ++;
1022#endif
1023
1024            // Only load need check
1025            if (need_check)
1026//             if (is_operation_memory_load(_load_queue [ptr_write]._operation))
1027              {
1028                log_printf(TRACE,Load_store_unit,FUNCTION,"    * update nb_check");
1029                log_printf(TRACE,Load_store_unit,FUNCTION,"      *     store_queue_ptr_write : %d",store_queue_ptr_write);
1030                log_printf(TRACE,Load_store_unit,FUNCTION,"      * reg_STORE_QUEUE_PTR_READ  : %d",reg_STORE_QUEUE_PTR_READ);
1031               
1032                uint32_t i=store_queue_ptr_write;
1033                while (i!=reg_STORE_QUEUE_PTR_READ)
1034                  {
1035                    i=((i==0)?_param->_size_store_queue:i)-1;
1036                   
1037                    log_printf(TRACE,Load_store_unit,FUNCTION,"      * i                         : %d",i);
1038                   
1039                    reg_STORE_QUEUE_NB_CHECK [i] ++;
1040                  }
1041              }
1042          }
1043
1044        //================================================================
1045        // Interface "DCACHE_RSP"
1046        //================================================================
1047        if ((PORT_READ(in_DCACHE_RSP_VAL[0])== 1) and
1048            (    internal_DCACHE_RSP_ACK == 1))
1049          {
1050            log_printf(TRACE,Load_store_unit,FUNCTION,"  * DCACHE_RSP [0]");
1051
1052            // don't use context_id : because there are one queue for all thread
1053            //Tcontext_t      context_id = PORT_READ(in_DCACHE_RSP_CONTEXT_ID[0]);
1054            Tpacket_t       packet_id  = PORT_READ(in_DCACHE_RSP_PACKET_ID [0]);
1055            Tdcache_data_t  rdata      = PORT_READ(in_DCACHE_RSP_RDATA     [0]);
1056            Tdcache_error_t error      = PORT_READ(in_DCACHE_RSP_ERROR     [0]);
1057
1058            log_printf(TRACE,Load_store_unit,FUNCTION,"    * original packet_id : %d"  , packet_id);
1059            log_printf(TRACE,Load_store_unit,FUNCTION,"    * packet_id          : %d"  , packet_id>>1);
1060            log_printf(TRACE,Load_store_unit,FUNCTION,"    * rdata              : %.8x", rdata);
1061            log_printf(TRACE,Load_store_unit,FUNCTION,"    * error              : %d"  , error);
1062           
1063            if (DCACHE_RSP_IS_LOAD(packet_id) == 1)
1064              {
1065                packet_id >>= 1;
1066
1067                log_printf(TRACE,Load_store_unit,FUNCTION,"    * packet is a LOAD");
1068 
1069#ifdef DEBUG_TEST
1070                if (not have_dcache_rsp(_load_queue [packet_id]._operation))
1071                  throw ERRORMORPHEO(FUNCTION,_("Receive of respons, but the corresponding operation don't wait a respons."));
1072#endif
1073
1074                Tdcache_data_t data = _load_queue [packet_id]._rdata;
1075
1076                log_printf(TRACE,Load_store_unit,FUNCTION,"    * data construction");
1077                log_printf(TRACE,Load_store_unit,FUNCTION,"      * data from cache     : 0x%.8x",rdata);
1078                log_printf(TRACE,Load_store_unit,FUNCTION,"      * data (before)       : 0x%.8x", data);
1079                log_printf(TRACE,Load_store_unit,FUNCTION,"      * check_hit_byte      : 0x%x"  ,_load_queue [packet_id]._check_hit_byte);
1080                for (uint32_t i=0;i<(_param->_size_general_data>>3)/*8*/; ++i)
1081                  // Test if this byte has been checked
1082                  if ((_load_queue [packet_id]._check_hit_byte & (1<<i)) == 0)
1083                    {
1084                      log_printf(TRACE,Load_store_unit,FUNCTION,"      * no previous check ]%d:%d]",(i+1)<<3,i<<3);
1085                      data = insert<Tdcache_data_t>(data,rdata,((i+1)<<3)-1,i<<3);
1086                    }
1087                log_printf(TRACE,Load_store_unit,FUNCTION,"      * data (after)        : 0x%.8x", data);
1088               
1089                _load_queue [packet_id]._rdata = data;
1090               
1091                if (error != DCACHE_ERROR_NONE)
1092                  {
1093                    log_printf(TRACE,Load_store_unit,FUNCTION,"    * have a bus error !!!");
1094
1095                    _load_queue [packet_id]._exception = EXCEPTION_MEMORY_BUS_ERROR;
1096                    _load_queue [packet_id]._state     = LOAD_QUEUE_COMMIT;
1097
1098                   
1099                    uint32_t i=_load_queue[packet_id]._store_queue_ptr_write;
1100                    while (i!=reg_STORE_QUEUE_PTR_READ)
1101                      {
1102                        i=((i==0)?_param->_size_store_queue:i)-1;
1103                       
1104#ifdef DEBUG
1105                        if (reg_STORE_QUEUE_NB_CHECK [i] == 0)
1106                          throw ERRORMORPHEO(FUNCTION,_("reg_STORE_QUEUE_NB_CHECK must be > 0\n"));
1107#endif
1108                       
1109                        reg_STORE_QUEUE_NB_CHECK [i] --;
1110                        //i=(i+1)%_param->_size_store_queue;
1111                      }
1112                  }
1113                else
1114                  {
1115                    log_printf(TRACE,Load_store_unit,FUNCTION,"    * have no bus error.");
1116                    log_printf(TRACE,Load_store_unit,FUNCTION,"      * previous state : %s",toString(_load_queue [packet_id]._state).c_str());
1117
1118                    // FIXME : convention : if bus error, the cache return the fautive address !
1119                    // But, the load's address is aligned !
1120
1121                    switch (_load_queue [packet_id]._state)
1122                      {
1123                      case LOAD_QUEUE_WAIT_CHECK : _load_queue [packet_id]._state = LOAD_QUEUE_COMMIT_CHECK; break;
1124                      case LOAD_QUEUE_WAIT       : _load_queue [packet_id]._state = LOAD_QUEUE_COMMIT      ; break;
1125                      default : throw ERRORMORPHEO(FUNCTION,_("Illegal state (dcache_rsp).")); break;
1126                      }
1127                  }
1128              }
1129            else
1130              {
1131                log_printf(TRACE,Load_store_unit,FUNCTION,"    * packet is a STORE");
1132               
1133                // TODO : les stores ne génére pas de réponse sauf quand c'est un bus error !!!
1134                throw ERRORMORPHEO(FUNCTION,_("dcache_rsp : no respons to a write. (TODO : manage bus error to the store operation.)"));
1135              }
1136           
1137          }
1138       
1139        // this register is to manage the priority of check -> Round robin
1140        reg_LOAD_QUEUE_CHECK_PRIORITY = (reg_LOAD_QUEUE_CHECK_PRIORITY+1)%_param->_size_load_queue;
1141       
1142       
1143#if defined(DEBUG) and (DEBUG>=DEBUG_TRACE)
1144        // ***** dump store queue
1145        log_printf(TRACE,Load_store_unit,FUNCTION,"  * Dump STORE_QUEUE");
1146        log_printf(TRACE,Load_store_unit,FUNCTION,"    * ptr_read : %d",reg_STORE_QUEUE_PTR_READ);
1147       
1148        for (uint32_t i=0; i<_param->_size_store_queue; i++)
1149          {
1150            uint32_t j = (reg_STORE_QUEUE_PTR_READ+i)%_param->_size_store_queue;
1151
1152            log_printf(TRACE,Load_store_unit,FUNCTION,"    [%.4d] %.4d %.4d %.4d, %.4d, %.4d, %.4d, %.8x %.8x, %.2d, %.2d %s",
1153                       j,
1154                       _store_queue[j]._context_id          ,
1155                       _store_queue[j]._front_end_id        ,
1156                       _store_queue[j]._ooo_engine_id       ,
1157                       _store_queue[j]._packet_id           ,
1158                       _store_queue[j]._operation           ,
1159                       _store_queue[j]._load_queue_ptr_write,
1160                       _store_queue[j]._address             ,
1161                       _store_queue[j]._wdata               ,
1162                     //_store_queue[j]._write_rd            ,
1163                     //_store_queue[j]._num_reg_rd          ,
1164                       _store_queue[j]._exception           ,
1165                       reg_STORE_QUEUE_NB_CHECK  [j]        ,
1166                       toString(_store_queue[j]._state).c_str());
1167          }
1168
1169        // ***** dump speculative_access queue
1170        log_printf(TRACE,Load_store_unit,FUNCTION,"  * Dump SPECULATIVE_ACCESS_QUEUE");
1171       
1172        for (uint32_t i=0; i<_param->_size_speculative_access_queue; i++)
1173          {
1174            uint32_t j = (*_speculative_access_queue_control)[i];
1175
1176            log_printf(TRACE,Load_store_unit,FUNCTION,"    [%.4d] %.4d %.4d %.4d, %.4d, %.4d, %.4d %.4d, %.8x, %.1d %.4d, %.2d, %s",
1177                       j,
1178                       _speculative_access_queue[j]._context_id          ,
1179                       _speculative_access_queue[j]._front_end_id        ,
1180                       _speculative_access_queue[j]._ooo_engine_id       ,
1181                       _speculative_access_queue[j]._packet_id           ,
1182                       _speculative_access_queue[j]._operation           ,
1183                       _speculative_access_queue[j]._load_queue_ptr_write,
1184                       _speculative_access_queue[j]._store_queue_ptr_write,
1185                       _speculative_access_queue[j]._address             ,
1186                       _speculative_access_queue[j]._write_rd            ,
1187                       _speculative_access_queue[j]._num_reg_rd          ,
1188                       _speculative_access_queue[j]._exception           ,
1189                       toString(_speculative_access_queue[j]._state).c_str());
1190          }
1191
1192        // ***** dump load queue
1193        log_printf(TRACE,Load_store_unit,FUNCTION,"  * Dump LOAD_QUEUE");
1194        log_printf(TRACE,Load_store_unit,FUNCTION,"    * ptr_read_check_priority : %d",reg_LOAD_QUEUE_CHECK_PRIORITY);
1195       
1196        for (uint32_t i=0; i<_param->_size_load_queue; i++)
1197          {
1198            uint32_t j = i;
1199
1200            log_printf(TRACE,Load_store_unit,FUNCTION,"    [%.4d] %.4d %.4d %.4d, %.4d, %.4d, %.4d, %.8x %.1x %.1d %.2d %.1d %.2d, %.8x, %.1d %.4d, %.2d, %s",
1201                       j,
1202                       _load_queue[j]._context_id          ,
1203                       _load_queue[j]._front_end_id        ,
1204                       _load_queue[j]._ooo_engine_id       ,
1205                       _load_queue[j]._packet_id           ,
1206                       _load_queue[j]._operation           ,
1207                       _load_queue[j]._store_queue_ptr_write,
1208                       _load_queue[j]._address             ,
1209                       _load_queue[j]._check_hit_byte      , 
1210                       _load_queue[j]._check_hit           ,
1211                       _load_queue[j]._shift               ,
1212                       _load_queue[j]._is_load_signed      ,
1213                       _load_queue[j]._access_size         ,
1214                       _load_queue[j]._rdata               ,
1215                       _load_queue[j]._write_rd            ,
1216                       _load_queue[j]._num_reg_rd          ,
1217                       _load_queue[j]._exception           ,
1218                       toString(_load_queue[j]._state).c_str());
1219          }
1220#endif
1221       
1222#ifdef STATISTICS
1223        if (usage_is_set(_usage,USE_STATISTICS))
1224          {
1225            for (uint32_t i=0; i<_param->_size_store_queue; i++)
1226              if (_store_queue[i]._state != STORE_QUEUE_EMPTY)
1227                (*_stat_use_store_queue) ++;
1228            for (uint32_t i=0; i<_param->_size_speculative_access_queue; i++)
1229              if (_speculative_access_queue[i]._state != SPECULATIVE_ACCESS_QUEUE_EMPTY)
1230                (*_stat_use_speculative_access_queue) ++;
1231            for (uint32_t i=0; i<_param->_size_load_queue; i++)
1232              if (_load_queue[i]._state != LOAD_QUEUE_EMPTY)
1233                (*_stat_use_load_queue) ++;
1234          }
1235#endif
1236      }
1237
1238    log_end(Load_store_unit,FUNCTION);
1239  };
1240
1241}; // end namespace load_store_unit
1242}; // end namespace execute_unit
1243}; // end namespace multi_execute_unit
1244}; // end namespace execute_loop
1245}; // end namespace multi_execute_loop
1246}; // end namespace core
1247
1248}; // end namespace behavioural
1249}; // end namespace morpheo             
1250#endif
Note: See TracBrowser for help on using the repository browser.