直接映射缓存 [英] Direct Mapped Cache

查看:131
本文介绍了直接映射缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我知道字段是Tag | Block | Offset。我只是不知道如何获取它们的大小。

解决方案

这是家庭作业吗?



为了解决此问题,您需要知道所讨论体系结构的地址大小。通用解决方案:



让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))。这就是缓存中套数的对数基数2。因此,标记位的数量T为A-D-O。用英语来说,地址中的位数减去用于其他两个部分的位数。



总而言之:




  • 位移位是您在一行中指定特定字节所需的位数

  • 块位是所需的指定缓存中的特定集合

  • 标记位是剩余的任何位



计算标签长度最后。



P.S。 -请注意,实际上,缓存还将在每行中存储一个脏位和一些其他元数据。但是,这些问题通常会忽略诸如此类的事情,所以我也这样做。


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.

解决方案

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.

这篇关于直接映射缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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