当直接映射的缓存中存在偏移量时,如何将内存地址映射到块? [英] How do I map a memory address to a block when there is an offset in a direct-mapped cache?

查看:97
本文介绍了当直接映射的缓存中存在偏移量时,如何将内存地址映射到块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,第一个高速缓存具有16个单字块.作为示例,我将使用0x03内存引用.索引有4位(0011).显然,这些位等于 3mod16 (0011 = 0x03 = 3).但是,使用此mod方程确定具有偏移量位的缓存中的块位置时,我感到困惑.

To start off, the first cache has 16 one-word blocks. As an example I will use 0x03 memory reference. The index has 4 bits (0011). It is clear that the bits equal 3mod16 (0011 = 0x03 = 3). However I am getting confused using this mod equation to determine block location in a cache with offset bits.

第二个缓存的总大小为八个两个字的块.这意味着有1个偏移位.由于现在有8个块,因此只有3个索引位.例如,我将使用相同的内存引用0x03.但是现在我在使用以前使用的mod方程映射到块时遇到了麻烦.我尝试使用 3mod8 ,它是3,但是在这种情况下,由于存在偏移位,因此索引位是001.001不等于3,所以我做错了什么?有偏移位时,mod不起作用吗?我的印象是mod方程将始终等于索引位.

The second cache has a total size of eight two-word blocks. This means that there is 1 offset bit. Since there are now 8 blocks, there are only 3 index bits. As an example, I will take the same memory reference of 0x03. However now I am having trouble mapping to the block using the mod equation I used before. I try 3mod8 which is 3, however in this case, since there is an offset bit, the index bits are 001. 001 is not equal to 3 so what did I do wrong? Does mod not work when there are offset bits? I was under the impression that the mod equation would always equal the index bits.

推荐答案

全部在地址中.出于以下原因,您获得了地址,然后从末尾屏蔽了位数.

Its all in the address. You get the address, then mask off number of bits from the end, for following reasons.

  1. 高速缓存行中的单词数.如果您有2个字的缓存行(花一点时间,用4个字-2个bts等)
  2. 然后您有多少个缓存行条目. (如果是1024个缓存行,则需要10位.这10位是您的索引,其余位用于您的代码)

现在,您还需要考虑"WAY".如果它是直接映射的缓存,则适用上面的方法.如果它是2路设置的关联缓存,则您没有1024行,而您有512个块,每个块中有2行.这意味着您仅需要9位就可以确定块的索引.如果采用4种方式,您将获得256个块,其中有4行,这意味着您只需要8位的索引即可.

Now, you also need to consider 'WAY' as well. If its a direct mapped cache, above applies. If its a 2 way set associative cache, you dont have 1024 lines, what you have a 512 blocks with each having 2 lines in them. Which means you only need 9 bits to determine the index of the block. If its 4 way, you've got 256 blocks with 4 lines in them, meaning you only need 8 bits for your index.

在一组关联的高速缓存中,有索引可以选择一个块,一旦选择了一个块,在发生高速缓存未命中的情况下,用户可以使用LRU之类的策略来填充条目.通过比较所选区块中的标签来确定点击数.

In a set associative cache, index are there to choose a block, once a block is chosen, use can use a policy like LRU to fill an entry in case of a cache miss. Hits are determined by comparing the tag in the selected block.

最底线,块的位置不是由地址决定的,只有一个块是由地址选择的,然后通过其标记比较来找到数据.

Bottom line, block location is not determined by the address, only a block is selected by the address and thereafter its Tag comparison to find the data.

这篇关于当直接映射的缓存中存在偏移量时,如何将内存地址映射到块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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