缓存寻址:索引长度、块偏移、字节偏移和标签? [英] Cache Addressing: Length of Index, Block offset, Byte offset & Tag?

查看:223
本文介绍了缓存寻址:索引长度、块偏移、字节偏移和标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我知道以下值:

W = Word length (= 32 bits)
S = Cache size in words
B = Block size in words
M = Main memory size in words

我如何计算需要多少位:

How do I calculate how many bits are needed for:

- Index
- Block offset
- Byte offset
- Tag

a) 在直接映射缓存中b) 在全关联缓存中?

a) in Direct Mapped Cache b) in Fully Associative Cache?

推荐答案

地址可能分为以下几部分:

The address may be split up into the following parts:

[ tag | index | block or line offset | byte offset ]

字节偏移位数

0 为字可寻址内存,log2(每字字节数)为字节可寻址内存

Number of byte offset bits

0 for word-addressable memory, log2(bytes per word) for byte addressable memory

log2(每行字数)

log2(CS),其中 CS 是缓存集的数量.

log2(CS), where CS is the number of cache sets.

  • 对于完全关联,CS 为 1.由于 log2(1) 为 0,因此没有索引位.
  • 对于 Direct Mapped,CS 等于 CL,即缓存行数,因此索引位数为 log2(CS) === log2(CL).
  • 对于 n 路关联 CS = CL ÷ n:log2(CL ÷ n) 个索引位.
  • For Fully Associative, CS is 1. Since log2(1) is 0, there are no index bits.
  • For Direct Mapped, CS is equal to CL, the number of cache lines, so the number of index bits is log2(CS) === log2(CL).
  • For n-way Associative CS = CL ÷ n: log2(CL ÷ n) index bits.

可以通过将缓存大小除以块大小 = S/B(假设它们都不包括标记和有效位的大小)来计算您拥有的缓存行数.

How many cache lines you have got can be calculated by dividing the cache size by the block size = S/B (assuming they both do not include the size for tag and valid bits).

地址长度减去用于偏移量和索引的位数.地址的长度可以使用主存储器的大小来计算,例如任何字节都需要寻址,如果它是一个字节可寻址内存.

Length of address minus number of bits used for offset(s) and index. The Length of the the addresses can be calculated using the size of the main memory, as e.g. any byte needs to be addressed, if it's a byte addressable memory.

来源:http://babbage.cs.qc.edu/courses/cs343/cache_parameters.xhtml

这篇关于缓存寻址:索引长度、块偏移、字节偏移和标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆