缓存 Mips 中的偏移量

Offset in cache Mips

我知道偏移量是:块大小=2^n(偏移量=n)。但是我已经看到当块大小 = 8 字节时我们做:8=2^n 所以 offset=n=3 位,这是正确的,但是当块大小 = 1 字时,我看到 1=2^n (offset= n = 0)。知道cache是​​32位的内存地址,是不是还需要把word转bytes呢? (所以我们有 32bit=4bytes,在这种情况下 4=2^n 偏移量为 2)。

你做对了,凭直觉应该知道 word 在 32 位处理器中是 4 字节,在 64 位处理器中是 8 字节。

byte offset也可以这样查,假设你的地址大小是32位那么 byte_offset = 32-tag_bits-set_bits.

为了解决这类问题,了解一些有用的参数和方程是很好的。

要知道的参数

C = cache capacity
b = block size
B = number of blocks
N = degree of associativity
S = number of set
tag_bits
set_bits (also called index)
byte_offset
v = valid bits

要知道的方程

B = C/b
S = B/N
b = 2^(byte_offset)
S = 2^(set_bits)

内存地址

|___tag________|____set___|___byte offset_|