在关联映射中计算内存跟踪地址的索引时,我使用以下代码:
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++;
但是这段代码给出了错误的未命中数,这种计算关联映射缓存索引的方法是否正确。