sniper/common/core/memory_subsystem/cache/cache_set_kruger.cc
/* 
 * Selects the index to be removed.
 * 
 * Valid only for KRUGER, not KRUGER_QBS.
 * For KRUGER_QBS, consult getReplacementIndex method in cache_set_lru.cc
 */
Selects the index to be removed.

Valid only for KRUGER, not KRUGER_QBS.
Selects the index to be removed . Valid only for KRUGER not KRUGER_QBS .
UInt32
CacheSetKruger::getReplacementIndex(CacheCntlr *cntlr)
{
   UInt32 index = 0, num_modified = 0;
   UInt8 max_bits = 0;
   for (UInt32 i = 0; i < m_associativity; i++)
   {
      if (!m_cache_block_info_array[i]->isValid())
      {
         moveToMRU(i);
         return i;
      }
      if (m_lru_bits[i] > max_bits && isValidReplacement(i))
      {
         index = i;
         max_bits = m_lru_bits[i];
      }
      if (m_cache_block_info_array[i]->getCState() == CacheState::MODIFIED)
         num_modified++;
   }
   if (num_modified >= m_associativity * m_percentage_to_wb)
   {
      max_bits = m_associativity - 1;
      for (UInt32 i = 0; i < m_associativity; i++)
      {
         if (m_lru_bits[i] == max_bits)
         {
            cntlr->checkpoint();
            return i;
         }
      }
   }
   LOG_ASSERT_ERROR(index < m_associativity, "Error Finding LRU bits");
   moveToMRU(index);
   m_set_info->incrementAttempt(0);
   return index;
}
UInt32 CacheSetKruger :: getReplacementIndex ( CacheCntlr * cntlr ) { UInt32 index = 0 , num_modified = 0 ; UInt8 max_bits = 0 ; for ( UInt32 i = 0 ; i < m_associativity ; i ++ ) { if ( ! m_cache_block_info_array [ i ] -> isValid ( ) ) { moveToMRU ( i ) ; return i ; } if ( m_lru_bits [ i ] > max_bits && isValidReplacement ( i ) ) { index = i ; max_bits = m_lru_bits [ i ] ; } if ( m_cache_block_info_array [ i ] -> getCState ( ) == CacheState :: MODIFIED ) num_modified ++ ; } if ( num_modified >= m_associativity * m_percentage_to_wb ) { max_bits = m_associativity - 1 ; for ( UInt32 i = 0 ; i < m_associativity ; i ++ ) { if ( m_lru_bits [ i ] == max_bits ) { cntlr -> checkpoint ( ) ; return i ; } } } LOG_ASSERT_ERROR ( index < m_associativity , " " ) ; moveToMRU ( index ) ; m_set_info -> incrementAttempt ( 0 ) ; return index ; }
Selects the index to be removed.
Selects the index to be removed .
// First try to find an invalid block // Mark our newly-inserted line as most-recently used // Find the last recently used between modified blocks // Check if all blocks are modified // Return the oldest block among the modified ones // Mark our newly-inserted line as most-recently used