-b // b bits来表示block大小
-E // 一个set里有E项,即E-way associativity
-s // s bits来表示set大小
-t / /测试文件
在测试文件里有4种类型的命令:
1234
I 0400d7d4,8 // Instruction load
M 0421c7f0,4 // Modify, i.e, a data load followed by a data store
L 04f6b868,8 // a data load
S 7ff0005c8,8 // a data store
struct oneSet
{
int *v;
clock_t *last_access_time;
long *tag;
};
// the global pointer to the cache, setptr[n] stands for the nth set entry
struct oneSet *setptr;
其中oneSet这个struct中的指针都需要根据参数动态分配,所有数组的大小为E。
Load operation
如果当前指令是load,那么处理的伪代码伪:
12345678
if cache hit:
hit++
else: //cache miss:
if cache is not full:
miss++
else: // cache is full
miss++
evict++
Store operation
如果当前指令是store,那么处理的伪代码伪:
1234
if cache hit:
hit++
else: //cache miss
do a load operation
Modify operation
如果当前指令是Modify,那么处理的伪代码伪:
12
do a load operation
do a store operation
如果把上面的逻辑想通了,那么就可以编码了。
函数设计
以下是我所有函数的原型:
1234567891011121314151617181920212223
// to get the opt from the command line
void get_opt();
// do init work, i.e, malloc space
void do_init();
// do deinit work, i.e, free space
void do_deinit();
// do a load operation
void do_L(void *addr, int size);
// do a modify operation
void do_M(void *addr, int size);
// do a store operation
void do_S(void *addr, int size);
// get set number according to the address of data
int getset(void *addr);
// get tag number according to the address of data
long gettag(void *addr);