Index: trunk/modules/vci_mem_cache/caba/source/include/mem_cache_directory.h
===================================================================
--- trunk/modules/vci_mem_cache/caba/source/include/mem_cache_directory.h	(revision 449)
+++ trunk/modules/vci_mem_cache/caba/source/include/mem_cache_directory.h	(revision 489)
@@ -6,12 +6,4 @@
 #include <cassert>
 #include "arithmetics.h"
-
-// !!!
-// The L1_MULTI_CACHE mechanism does no longer work with the new pktid encoding
-// of TSAR. Turning the define below to a non null value will cause the memcache
-// to behave in an unpredicted way.
-// TODO Either remove the mechanism from the mem cache or update its behaviour.
-
-#define L1_MULTI_CACHE 0
 
 //#define RANDOM_EVICTION
@@ -46,38 +38,25 @@
       bool      inst;       // Is the owner an ICache ?
       size_t    srcid;      // The SRCID of the owner
-#if L1_MULTI_CACHE
-      size_t    cache_id;   // In multi_cache configuration
-#endif
 
     ////////////////////////
     // Constructors
     ////////////////////////
-      Owner(bool   i_inst
-            ,size_t i_srcid
-#if L1_MULTI_CACHE
-            ,size_t i_cache_id
-#endif
-            ){
+      Owner(bool   i_inst,
+            size_t i_srcid)
+      {
         inst    = i_inst;
         srcid   = i_srcid;
-#if L1_MULTI_CACHE
-        cache_id= i_cache_id;
-#endif
-      }
-
-      Owner(const Owner &a){
+      }
+
+      Owner(const Owner &a)
+      {
         inst    = a.inst;
         srcid   = a.srcid;
-#if L1_MULTI_CACHE
-        cache_id= a.cache_id;
-#endif
-      }
-
-      Owner(){
+      }
+
+      Owner()
+      {
         inst    = false;
         srcid   = 0;
-#if L1_MULTI_CACHE
-        cache_id= 0;
-#endif
       }
       // end constructors
@@ -114,7 +93,4 @@
       owner.inst    = 0;
       owner.srcid   = 0;
-#if L1_MULTI_CACHE
-      owner.cache_id= 0;
-#endif
       ptr           = 0;
     }
@@ -171,7 +147,4 @@
                 << " ; Count = " << count 
                 << " ; Owner = " << owner.srcid 
-#if L1_MULTI_CACHE
-                << "." << owner.cache_id 
-#endif
                 << " " << owner.inst 
                 << " ; Pointer = " << ptr << std::endl;
@@ -322,5 +295,7 @@
     // - entry : the entry value
     /////////////////////////////////////////////////////////////////////
-    void write(const size_t &set, const size_t &way, const DirectoryEntry &entry)
+    void write( const size_t         &set, 
+                const size_t         &way, 
+                const DirectoryEntry &entry)
     {
       assert( (set<m_sets) 
@@ -368,40 +343,56 @@
     DirectoryEntry select(const size_t &set, size_t &way)
     {
-      assert( (set < m_sets) 
+        assert( (set < m_sets) 
           && "Cache Directory : (select) The set index is invalid");
 
-      for(size_t i=0; i<m_ways; i++){
-        if(!m_dir_tab[set][i].valid){
-          way=i;
-          return DirectoryEntry(m_dir_tab[set][way]);
+        // looking for an empty slot
+        for(size_t i=0; i<m_ways; i++)
+        {
+            if( not m_dir_tab[set][i].valid )
+            {
+                way=i;
+                return DirectoryEntry(m_dir_tab[set][way]);
+            }
         }
-      }
 
 #ifdef RANDOM_EVICTION
-      lfsr = (lfsr >> 1) ^ ((-(lfsr & 1)) & 0xd0000001);
-      way = lfsr % m_ways;
-      return DirectoryEntry(m_dir_tab[set][way]);
+        lfsr = (lfsr >> 1) ^ ((-(lfsr & 1)) & 0xd0000001);
+        way = lfsr % m_ways;
+        return DirectoryEntry(m_dir_tab[set][way]);
 #endif
 
-      for(size_t i=0; i<m_ways; i++){
-        if(!(m_lru_tab[set][i].recent) && !(m_dir_tab[set][i].lock)){
-          way=i;
-          return DirectoryEntry(m_dir_tab[set][way]);
+        // looking for a not locked and not recently used entry
+        for(size_t i=0; i<m_ways; i++)
+        {
+            if((not m_lru_tab[set][i].recent) && (not m_dir_tab[set][i].lock) )
+            {
+                way=i;
+                return DirectoryEntry(m_dir_tab[set][way]);
+            }
         }
-      }
-      for(size_t i=0; i<m_ways; i++){
-        if( !(m_lru_tab[set][i].recent) && (m_dir_tab[set][i].lock)){
-          way=i;
-          return DirectoryEntry(m_dir_tab[set][way]);
+
+        // looking for a locked not recently used entry
+        for(size_t i=0; i<m_ways; i++)
+        {
+            if( (not m_lru_tab[set][i].recent) && (m_dir_tab[set][i].lock))
+            {
+                way=i;
+                return DirectoryEntry(m_dir_tab[set][way]);
+            }
         }
-      }
-      for(size_t i=0; i<m_ways; i++){
-        if( (m_lru_tab[set][i].recent) && !(m_dir_tab[set][i].lock)){
-          way=i;
-          return DirectoryEntry(m_dir_tab[set][way]);
+
+        // looking for a recently used entry not locked
+        for(size_t i=0; i<m_ways; i++)
+        {
+            if( (m_lru_tab[set][i].recent) && (not m_dir_tab[set][i].lock))
+            {
+                way=i;
+                return DirectoryEntry(m_dir_tab[set][way]);
+            }
         }
-      }
-      way = 0;
-      return DirectoryEntry(m_dir_tab[set][0]);
+
+        // select way 0 (even if entry is locked and recently used)
+        way = 0;
+        return DirectoryEntry(m_dir_tab[set][0]);
     } // end select()
 
@@ -437,9 +428,5 @@
     ////////////////////////
       HeapEntry()
-      :owner(false,0
-#if L1_MULTI_CACHE
-             ,0
-#endif
-             )
+      :owner(false,0)
       {
         next = 0;
@@ -449,10 +436,8 @@
     // Constructor
     ////////////////////////
-      HeapEntry(const HeapEntry &entry){
+      HeapEntry(const HeapEntry &entry)
+      {
         owner.inst  = entry.owner.inst;
         owner.srcid = entry.owner.srcid;
-#if L1_MULTI_CACHE
-        owner.cache_id = entry.owner.cache_id;
-#endif        
         next           = entry.next;
       } // end constructor
@@ -461,10 +446,8 @@
     // The copy() function copies an existing source entry to a target 
     /////////////////////////////////////////////////////////////////////
-      void copy(const HeapEntry &entry){
+      void copy(const HeapEntry &entry)
+      {
         owner.inst     = entry.owner.inst;
         owner.srcid    = entry.owner.srcid;
-#if L1_MULTI_CACHE
-        owner.cache_id = entry.owner.cache_id;
-#endif
         next           = entry.next;
       } // end copy()
@@ -477,7 +460,4 @@
         << " -- owner.inst     : " << std::dec << owner.inst << std::endl
         << " -- owner.srcid    : " << std::dec << owner.srcid << std::endl
-#if L1_MULTI_CACHE
-        << " -- owner.cache_id : " << std::dec << owner.cache_id << std::endl
-#endif
         << " -- next           : " << std::dec << next << std::endl;
 
@@ -640,5 +620,6 @@
   //                        Cache Data 
   ////////////////////////////////////////////////////////////////////////
-  class CacheData {
+  class CacheData 
+  {
     private:
       const uint32_t m_sets;
@@ -650,81 +631,88 @@
     public:
 
+      ///////////////////////////////////////////////////////
       CacheData(uint32_t ways, uint32_t sets, uint32_t words)
-        : m_sets(sets), m_ways(ways), m_words(words) {
-
+        : m_sets(sets), m_ways(ways), m_words(words) 
+      {
           m_cache_data = new uint32_t ** [ways];
-          for ( size_t i=0 ; i < ways ; i++ ) {
-            m_cache_data[i] = new uint32_t * [sets];
+          for ( size_t i=0 ; i < ways ; i++ ) 
+          {
+              m_cache_data[i] = new uint32_t * [sets];
           }
-          for ( size_t i=0; i<ways; i++ ) {
-            for ( size_t j=0; j<sets; j++ ) {
-              m_cache_data[i][j] = new uint32_t [words];
-            }
+          for ( size_t i=0; i<ways; i++ ) 
+          {
+              for ( size_t j=0; j<sets; j++ ) 
+              {
+                  m_cache_data[i][j] = new uint32_t [words];
+              }
           }
-        }
-
-      ~CacheData() {
-          for(size_t i=0; i<m_ways ; i++){
-              for(size_t j=0; j<m_sets ; j++){
+      }
+      ////////////
+      ~CacheData() 
+      {
+          for(size_t i=0; i<m_ways ; i++)
+          {
+              for(size_t j=0; j<m_sets ; j++)
+              {
                   delete [] m_cache_data[i][j];
               }
           }
-          for(size_t i=0; i<m_ways ; i++){
+          for(size_t i=0; i<m_ways ; i++)
+          {
               delete [] m_cache_data[i];
           }
           delete [] m_cache_data;
       }
-
-      uint32_t read (
-          const uint32_t &way,
-          const uint32_t &set,
-          const uint32_t &word) const {
-
-        assert((set  < m_sets ) && "Cache data error: Trying to read a wrong set" );
-        assert((way  < m_ways ) && "Cache data error: Trying to read a wrong way" );
-        assert((word < m_words) && "Cache data error: Trying to read a wrong word");
-
-        return m_cache_data[way][set][word];
-      }
-
-      void read_line(
-          const uint32_t &way,
-          const uint32_t &set,
-          sc_core::sc_signal<uint32_t> * cache_line)
-      {
-        assert((set < m_sets ) && "Cache data error: Trying to read a wrong set" );
-        assert((way < m_ways ) && "Cache data error: Trying to read a wrong way" );
-
-        for (uint32_t word=0; word<m_words; word++)
-          cache_line[word].write(m_cache_data[way][set][word]);
-      }
-
-      void write (
-          const uint32_t &way,
-          const uint32_t &set,
-          const uint32_t &word,
-          const uint32_t &data,
-          const uint32_t &be = 0xF) {
-
-        assert((set  < m_sets ) && "Cache data error: Trying to write a wrong set" );
-        assert((way  < m_ways ) && "Cache data error: Trying to write a wrong way" );
-        assert((word < m_words) && "Cache data error: Trying to write a wrong word");
-        assert((be  <= 0xF    ) && "Cache data error: Trying to write a wrong word cell");
-
-        if (be == 0x0) return;
-
-        if (be == 0xF) {
-            m_cache_data[way][set][word] = data; 
-            return;
-        }
-
-        uint32_t mask = 0;
-        if  (be & 0x1) mask = mask | 0x000000FF;
-        if  (be & 0x2) mask = mask | 0x0000FF00;
-        if  (be & 0x4) mask = mask | 0x00FF0000;
-        if  (be & 0x8) mask = mask | 0xFF000000;
-
-        m_cache_data[way][set][word] = 
-          (data & mask) | (m_cache_data[way][set][word] & ~mask);
+      //////////////////////////////////////////
+      uint32_t read ( const uint32_t &way,
+                      const uint32_t &set,
+                      const uint32_t &word) const 
+      {
+          assert((set  < m_sets ) && "Cache data error: Trying to read a wrong set" );
+          assert((way  < m_ways ) && "Cache data error: Trying to read a wrong way" );
+          assert((word < m_words) && "Cache data error: Trying to read a wrong word");
+
+          return m_cache_data[way][set][word];
+      }
+      //////////////////////////////////////////
+      void read_line( const uint32_t &way,
+                      const uint32_t &set,
+                      sc_core::sc_signal<uint32_t> * cache_line)
+      {
+          assert((set < m_sets ) && "Cache data error: Trying to read a wrong set" );
+          assert((way < m_ways ) && "Cache data error: Trying to read a wrong way" );
+
+          for (uint32_t word=0; word<m_words; word++)
+              cache_line[word].write(m_cache_data[way][set][word]);
+      }
+      /////////////////////////////////////////
+      void write ( const uint32_t &way,
+                   const uint32_t &set,
+                   const uint32_t &word,
+                   const uint32_t &data,
+                   const uint32_t &be = 0xF) 
+      {
+
+          assert((set  < m_sets ) && "Cache data error: Trying to write a wrong set" );
+          assert((way  < m_ways ) && "Cache data error: Trying to write a wrong way" );
+          assert((word < m_words) && "Cache data error: Trying to write a wrong word");
+          assert((be  <= 0xF    ) && "Cache data error: Trying to write a wrong be");
+
+          if (be == 0x0) return;
+
+          if (be == 0xF) 
+          {
+              m_cache_data[way][set][word] = data; 
+              return;
+          }
+
+          uint32_t mask = 0;
+          if  (be & 0x1) mask = mask | 0x000000FF;
+          if  (be & 0x2) mask = mask | 0x0000FF00;
+          if  (be & 0x4) mask = mask | 0x00FF0000;
+          if  (be & 0x8) mask = mask | 0xFF000000;
+
+          m_cache_data[way][set][word] = 
+              (data & mask) | (m_cache_data[way][set][word] & ~mask);
       }
   }; // end class CacheData
