关联映射缓存中的地址索引

时间:2013-05-04 13:24:55

标签: c# caching mapping associative

在Associative Maping中计算内存跟踪地址的索引时,我使用的是以下代码:

address is a trace address read from a memory trace file.
 BLOCK_SHIFT=5 // fro 32bit block size
CACHE_SIZE=1024
associativity=4 // that why i m dividing the index with 2, 2^2=4 associativity
 long index = ((address >> BLOCK_SHIFT) & (CACHE_SIZE - 1)) / 2;

int tag = address >> BLOCK_SHIFT; // the high order bits are the tag
                    /* in the line above we want the high bits (can include index bits) that uniquely identify the contents of a cache-block */
 if (tags[index] != tag)
 {
  // we compare to see if this is our data or other data mapped to the same location in
   cache
   misses++;
   tags[index] = tag;
   }
   references++;

但是这段代码给出了错误的错失次数,这种计算关联映射缓存索引的方法是否正确。

0 个答案:

没有答案