以下是对矩阵进行转置的程序段:
typedef int array[4][4];
void transpose(array dst,arrsy src)
{
int i,j;
for (i=0;i<4;i++)
for (j=0;j<4;j++) dst[j][i]=src[i][j];
}
假设该段程序运行的计算机中sizeof(int)=4,且只有一级cache,其中L1数据cache的数据区大小为32B,采用直接映射、回写方式,块大小为16B,初始为空。数据dst从地址0x804c000开始存放,数组src从地址0x804c010H开始存放。仿照例子填写下表,说明数组元素src[row][col]和dst[row][col]各自映射到cache哪一行,访问是命中(hit)还是缺失(miss)。若L1数据cache的数据区容量改为128B时,重新填写下表中的内容。
| src数组 | dst数组 | ||||||
| col=0 | col=1 | col=2 | col=3 | col=0 | col=1 | col=2 | col=3 |
row=0 | 0/miss | | | | | | | |
row=1 | | | | | | | | |
row=2 | | | | | | | | |
row=3 | | | | | | | | |