直接映射缓存

发布于 2024-09-16 07:03:59 字数 117 浏览 10 评论 0原文

直接映射缓存由 16 个块组成。主存包含 16K 块,每个块 8 字节。主存地址格式是什么(意思是每个字段的大小)。

我知道这些字段是 Tag|Block|Offset 。我只是不知道如何获得每个的尺寸。

A direct mapped cache consists of 16 blocks. main memory contains 16K blocks of 8 bytes each. What is the main memory address format (meaning the size of each field).

I know the fields are Tag|Block|Offset . I just don't know how to get the sizes of each.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

为人所爱 2024-09-23 07:03:59

这是作业吗?

为了解决这个问题,您需要知道相关架构的地址大小。一般解决方案:

令 C 为缓存的大小(以位为单位)。
设 A 为地址的大小(以位为单位)。
令 B 为缓存块的大小(以位为单位)。
令S为高速缓存的关联性(在某种程度上,直接映射为S=1,完全关联为S=C/B)

L,即高速缓存中的行数,等于C/B。这是缓存位数除以每行位数。
Q,缓存中的组数,等于L/S。这是行数除以关联性。这条线和上面的原因应该是显而易见的;如果不是,请在阅读下面之前再次阅读教科书。

现在,让我们解决三件事:位移位、块位和标记位。

位移位用于查找高速缓存行内的特定项目。假设字节可寻址存储器 D(位移位数)为 ceil(log2(ceil(B/8)))。这是缓存行中字节数的以 2 为底的对数,在每个步骤中四舍五入。如果内存是两字节可寻址的,则内部部分将是B/16等。

块位是为了在缓存中找到我们想要的缓存集。因此,块位数 O 为 ceil(log2(Q))。这是缓存中集合数量的以二为底的对数。

标记位是剩下的任何内容。因此,T(标记位数)是 ADO。在英语中,地址中的位数减去用于其他两个部分的位数。我们在这里不必考虑关联性,因为我们已经在上面使用 Q 而不是 L 处理了它。

总之:

  • 位移位与您在一行中指定特定字节所需的数量一样多
  • 块位与您需要的数量一样多需要在缓存中指定特定的一组
  • 标记位是剩下的任何位

最后计算标记长度。这绝对更容易。

PS - 请注意,实际上,缓存还将在每行中存储一个脏位和一些其他元数据。然而,这些问题通常会忽略这样的事情,所以我也这样做了。

Is this homework?

In order to solve this problem, you'd need to know the address size of the architecture in question. General solution:

Let C be the size of the cache in bits.
Let A be the size of an address in bits.
Let B be the size of a cache block in bits.
Let S be the associativity of the cache (in ways, direct-mapped being S=1 and fully associative being S=C/B)

L, the number of lines in the cache, is equal to C/B. That's the number of cache bits divided by the number of bits per line.
Q, the number of sets in the cache, is equal to L/S. That's the number of lines divided by the associativity. The reasons for this line and the above should be obvious; if they aren't, hit the textbook again before reading below.

Now, let's work out three things: the displacement bits, the block bits, and the tag bits.

The displacement bits are to find a particular item within a cache line. Assuming byte-addressable memory, D, the number of displacement bits, is ceil(log2(ceil(B/8))). That's the log base two of the number of bytes in a cache line, rounded up at each step. If memory is two-byte addressable, the inner portion there would be B/16, etc.

The block bits are to find the cache set we want within the cache. Thus, O, the number of block bits, is ceil(log2(Q)). That's the log base two of the number of sets in the cache.

The tag bits are whatever is left. So, T, the number of tag bits, is A-D-O. In English, the number of bits in an address minus the number of bits used for the other two portions. We don't have to consider associativity here because we already handled it above in using Q instead of L.

In summary:

  • The displacement bits are as many as you need to specify a particular byte within a line
  • The block bits are as many as you need to specify a particular set in the cache
  • The tag bits are any bits left over

Calculate the tag length last. This is definitely easier.

P.S. - Note that in reality, the cache will also store a dirty bit and some other metadata with each line. However, these questions usually ignore things like that, so I did too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文