Index: trunk/lib/generic_llsc_global_table/include/generic_llsc_global_table.h
===================================================================
--- trunk/lib/generic_llsc_global_table/include/generic_llsc_global_table.h	(revision 524)
+++ trunk/lib/generic_llsc_global_table/include/generic_llsc_global_table.h	(revision 527)
@@ -28,6 +28,4 @@
 #define SOCLIB_GENERIC_LLSC_GLOBAL_TABLE_H
 
-#include <systemc>
-#include <arithmetics.h>
 #include <cassert>
 #include <cstring>
@@ -35,4 +33,5 @@
 #include <iostream>
 #include <iomanip>
+#include <stdint.h>
 
 namespace soclib
@@ -70,15 +69,16 @@
 
     uint32_t                    r_next_key        ; // value of the next key
-    sc_dt::sc_uint<nb_slots>    r_block_mask      ; // mask for the slots blocks
-    sc_dt::sc_uint<nb_slots>    r_last_counter    ; // mask for the slots blocks
+    uint64_t                    r_block_mask      ; // mask for the slots blocks
+    uint64_t                    r_last_counter    ; // mask for the slots blocks
     size_t                      r_write_ptr       ; // index of next slot to replace
     size_t                      r_last_empty      ; // index of last empty slot used
 
-    uint32_t                    m_cpt_evic        ; // number of eviction in the table
-    uint32_t                    m_cpt_ll          ; // number of ll accesses to the table
-    uint32_t                    m_cpt_ll_update   ; // number of ll accesses to the table that trigger an update TODO check that
-    uint32_t                    m_cpt_sc          ; // number of sc accesses to the table
-    uint32_t                    m_cpt_sc_success  ; // number of sc accesses to the table that are successful
-    uint32_t                    m_cpt_sw          ; // number of sw accesses to the table
+    mutable uint32_t            m_cpt_evic        ; // number of eviction in the table
+    mutable uint32_t            m_cpt_ll          ; // number of ll accesses to the table
+    mutable uint32_t            m_cpt_ll_update   ; // number of ll accesses to the table that trigger an update TODO check that
+    mutable uint32_t            m_cpt_sc          ; // number of sc accesses to the table
+    mutable uint32_t            m_cpt_sc_success  ; // number of sc accesses to the table that are successful
+    mutable uint32_t            m_cpt_check       ; // number of check accesses to the table
+    mutable uint32_t            m_cpt_sw          ; // number of sw accesses to the table
 
     ////////////////////////////////////////////////////////////////////////////
@@ -121,6 +121,6 @@
     //  This is done by updating the value of r_write_ptr
     {
-        sc_dt::sc_uint<nb_slots> new_counter;
-        sc_dt::sc_uint<nb_slots> xor_counter;
+        uint64_t new_counter;
+        uint64_t xor_counter;
 
         new_counter = newCounter(r_block_mask, r_last_counter);
@@ -129,5 +129,5 @@
         for (size_t i = nb_slots - 1; i >= 0; --i)
         {
-            if(xor_counter[i])
+            if(xor_counter & (1 << i))
             {
                 r_write_ptr = i;
@@ -140,9 +140,8 @@
 
     ////////////////////////////////////////////////////////////////////////////
-    inline sc_dt::sc_uint<nb_slots> newCounter(const sc_dt::sc_uint<nb_slots>& mask,
-                                               const sc_dt::sc_uint<nb_slots>& counter)
+    inline uint64_t newCounter(const uint64_t& mask,
+                               const uint64_t& counter) const
     // This function generates the new counter //TODO comment more
     {
-        //
         return ((((~counter) & (counter << 1)) & mask) | (counter + 1));
     }
@@ -164,44 +163,44 @@
         {
             case 12:
-            r_block_mask = sc_dt::sc_uint<nb_slots>("0x000");
+            r_block_mask = (uint64_t)0x000ULL;
             break;
             case 16 :
-            r_block_mask = sc_dt::sc_uint<nb_slots>("0xA800");
+            r_block_mask = (uint64_t)0xA800ULL;
             break;
             case 20 :
-            r_block_mask = sc_dt::sc_uint<nb_slots>("0xD5500");
+            r_block_mask = (uint64_t)0xD5500ULL;
             break;
             case 24 :
-            r_block_mask = sc_dt::sc_uint<nb_slots>("0xDB5540");
+            r_block_mask = (uint64_t)0xDB5540ULL;
             break;
             case 28 :
-            r_block_mask = sc_dt::sc_uint<nb_slots>("0xEEDAAA0");
+            r_block_mask = (uint64_t)0xEEDAAA0ULL;
             break;
             case 32 :
-            r_block_mask = sc_dt::sc_uint<nb_slots>("0xF776D550");
+            r_block_mask = (uint64_t)0xF776D550ULL;
             break;
             case 36 :
-            r_block_mask = sc_dt::sc_uint<nb_slots>("0xFBDDDB550");
+            r_block_mask = (uint64_t)0xFBDDDB550ULL;
             break;
             case 40 :
-            r_block_mask = sc_dt::sc_uint<nb_slots>("0xFDF7BB6D50");
+            r_block_mask = (uint64_t)0xFDF7BB6D50ULL;
             break;
             case 44 :
-            r_block_mask = sc_dt::sc_uint<nb_slots>("0xFEFBDEEDAA8");
+            r_block_mask = (uint64_t)0xFEFBDEEDAA8ULL;
             break;
             case 48 :
-            r_block_mask = sc_dt::sc_uint<nb_slots>("0xFF7EFBDDDAA8");
+            r_block_mask = (uint64_t)0xFF7EFBDDDAA8ULL;
             break;
             case 52 :
-            r_block_mask = sc_dt::sc_uint<nb_slots>("0xFFBFBF7BBB6A8");
+            r_block_mask = (uint64_t)0xFFBFBF7BBB6A8ULL;
             break;
             case 56 :
-            r_block_mask = sc_dt::sc_uint<nb_slots>("0xFFDFEFDF7BB6A8");
+            r_block_mask = (uint64_t)0xFFDFEFDF7BB6A8ULL;
             break;
             case 60 :
-            r_block_mask = sc_dt::sc_uint<nb_slots>("0xFFF7FDFDF7BB6A8");
+            r_block_mask = (uint64_t)0xFFF7FDFDF7BB6A8ULL;
             break;
             case 64 :
-            r_block_mask = sc_dt::sc_uint<nb_slots>("0xFFFBFF7FBF7BB6A8");
+            r_block_mask = (uint64_t)0xFFFBFF7FBF7BB6A8ULL;
             break;
             default:
@@ -211,5 +210,5 @@
 
     ////////////////////////////////////////////////////////////////////////////
-    inline int nextEmptySlot()
+    inline int nextEmptySlot() const
     //  This function returns :
     //  - the position of the first next empty slot in the table
@@ -218,26 +217,15 @@
     //  - -1 if the table is full
     {
-        size_t i = r_last_empty;
-        do
-        {
-            // checking if current slot is empty
-            if(!r_val[i])
-            {
-                // updating last empty slot and returning its position
-                r_last_empty = i;
-                return i;
-            }
-            // selecting next slot
-            i = (i+1) % nb_slots;
-        }
-        // stop if all slots have been tested
-        while(i != r_last_empty);
-
-        // the table is full
+        uint64_t i; 
+        for(i = 0; i < nb_slots; i++)
+        {
+            if (!r_val[i]) return i;
+        }
+
         return -1;
     }
 
     ////////////////////////////////////////////////////////////////////////////
-    inline int hitAddr(const addr_t ad)
+    inline int hitAddr(const addr_t ad) const
     //  HIT on the address only
     //  This function takes an addr_t ad
@@ -259,5 +247,5 @@
 
     ////////////////////////////////////////////////////////////////////////////
-    inline int hitAddrKey(const addr_t ad, const uint32_t key)
+    inline int hitAddrKey(const addr_t ad, const uint32_t key) const
     //  HIT on the address AND the on the signature
     //  This function takes an addr_t ad and a uint32_t key
@@ -291,4 +279,5 @@
         m_cpt_sc            = 0;
         m_cpt_sc_success    = 0;
+        m_cpt_check         = 0;
         m_cpt_sw            = 0;
     }
@@ -301,8 +290,5 @@
     :   name(n)
     {
-        #define L2 soclib::common::uint32_log2
         assert(nb_procs > 1); 
-        assert((int)nb_slots >= L2(nb_procs));
-        #undef L2
         init();
         init_block_mask();
@@ -362,9 +348,14 @@
         if (pos >= 0)
         {
-            if(r_key[pos] - r_next_key > life_span)
-                return r_key[pos];
+            uint32_t absdiff = ( r_key[pos] > r_next_key) ?
+                                 r_key[pos] - r_next_key  :
+                                 r_next_key - r_key[pos];
+
+            if(absdiff < life_span) return r_key[pos];
+
             r_key[pos] = r_next_key;
             upNextKey();
             m_cpt_ll_update++;
+
             return r_key[pos];
         }
@@ -377,8 +368,10 @@
         if (pos == -1)
         {
+            //  update the victim slot for the next eviction
+            updateVictimSlot();
+
             //  get the position of the evicted registration
             pos = r_write_ptr;
-            //  update the victim slot for the next eviction
-            updateVictimSlot();
+
             // increment the eviction counter (for stats)
             m_cpt_evic++;
@@ -434,4 +427,16 @@
 
     ////////////////////////////////////////////////////////////////////////////
+    inline bool check(const addr_t ad, const uint32_t key) const
+    //  This method checks if there is a valid registration for the SC (ad &&
+    //  key)
+    //  The return value can be used to tell if the SC is atomic
+    {
+        // increment the check access counter (for stats)
+        m_cpt_check++;
+
+        return (hitAddrKey(ad, key) >= 0);
+    }
+
+    ////////////////////////////////////////////////////////////////////////////
     /*
     inline void sw(const addr_t ad)
@@ -489,25 +494,16 @@
     inline void print_trace(std::ostream& out = std::cout)
     {
-        out <<  " ___________________________________" << std::endl
-            <<  "| " << std::setw(33) << "generic_llsc_global_table" << " |" << std::endl
-            <<  "| " << std::setw(33) << name << " |" << std::endl
-            <<  " ===================================" << std::endl
-            <<  "| "
-            <<  std::setw(11) << "addr"   << " | "
-            <<  std::setw(11) << "key"    << " | "
-            <<  std::setw(5)  << "val"
-            << " |" << std::endl
-            <<  " -----------------------------------" << std::endl;
         for ( size_t i = 0; i < nb_slots ; i++ )
         {
-            out << "| "
-                << std::showbase
-                << std::setw(11) << std::setfill('0')   << std::hex       << r_addr[i]    << " | "
+            out << std::setw(3)   << std::setfill(' ') << std::dec << i
                 << std::noshowbase
-                << std::setw(11) << std::setfill('0')   << std::dec       << r_key[i]     << " | "
-                << std::setw(5)  << std::setfill(' ')   << std::boolalpha << r_val[i]     << " |" << std::endl ;
-        }
-        out <<  " -----------------------------------" << std::endl
-            << std::noshowbase << std::dec << std::endl ;
+                << " VLD_RX = "   << r_val[i]
+                << std::uppercase
+                << " ADR_RX = 0x" << std::setw(8) << std::setfill('0') << std::hex << (r_addr[i] >> 2)
+                << " SGN_RX = 0x" << std::setw(8) << std::setfill('0') << std::hex << r_key[i]
+                << std::endl;
+        }
+        out << "NEXT_SGN_RX = 0x" << std::setw(8) << std::setfill('0') << std::hex << r_next_key     << std::endl
+            << "CNT_RX = 0x"      << std::setw(8) << std::setfill('0') << std::hex << r_last_counter << std::endl;
     }
 
