请问Set associative Cache

huangry 2004-10-23 10:54:13
手头没有英文的书,Set associative Cache是指什么?

能不能再稍微解释一下

谢谢,唉
...全文
664 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
mathe 2004-10-24
  • 打赏
  • 举报
回复
fully associative mapping 应该是指这种方案,
比如现在有1024个cache line,现在来了一个内存地址,那么就会有1024个计算单元同时来比较这1024个cache line的地址和这个内存地址是否匹配。
direct mapped cache应该是这样,使用一个Hash函数,把每个地址可以换算成0到1023中的一个整数;映射到那个位置,就使用哪条cache line.
而set associative mapping应该是指:比如我们可以将1024个cache line分成4路,也就是4*256组。
对于每个地址,都可以将它换算成0到255中的一个整数。然后4个计算单元同时比较4路中对应位置的cache line是否和这个内存地址匹配。
zzwu 2004-10-24
  • 打赏
  • 举报
回复
由于牵涉到计算机硬件方面的许多东西,到和硬件有关的版(或论坛)去发一个贴,可能得到更多的帮助。
zzwu 2004-10-24
  • 打赏
  • 举报
回复
但要理解还不容易,要了解 fully associative cache 和 direct mapped cache 又是什么?
zzwu 2004-10-24
  • 打赏
  • 举报
回复
找到一个完整的解释了:

Set Associative Cache

Introduction
A set-associative scheme is a hybrid between a fully associative cache, and direct mapped cache. It's considered a reasonable compromise between the complex hardware needed for fully associative caches (which requires parallel searches of all slots), and the simplistic direct-mapped scheme, which may cause collisions of addresses to the same slot (similar to collisions in a hash table).
Let's assume, as we did for fully associate caches that we have:

128 slots
32 bytes per slot
Furthermore, let's assume that we can group slots together into sets. In particular, we will assume that we have 8 slots per set.

Parking Lot Analogy
Suppose we have 1000 parking spots. This time, instead of using a 3 digit number for each parking spot, we use 2 digits. Thus, the parking spots are numbered 00 up to 99.
However, instead of one parking spot per number, we have 10 for each number. Thus, there are ten parking spots numbered 00, ten numbered 01, ..., and ten numbered 99.

Your parking spot is based on the first 2 digits of your student ID number.

In this case, you use the first 2 digits of your student ID, and have up to 10 different parking spots you can park at. This gives you some flexibility about where to park.

In effect, the various parking permits on a large commuter campus work just like that. There are many lots, each with their own letter or number. You are given a permit for a particular lot, but you can park anywhere within this lot. The advantage is that you only have to search for a spot in one large lot, as opposed to searching for a parking spot in all of campus.

Set Associative Scheme
Like the direct mapped scheme, we still treat the slots like an array. The slots are still numbered 0000000 up to 1111111 (there are 128 slots).
However, we group the slots into sets, and the key is to keep track of the sets, instead of the slots.

How many sets do we have? 128 slots divided by 8 slots per sets, gives us 16 sets.

We need to specify the set number, instead of the slot number, and that takes lg 16 = 4 bits.

Here's how the bits of the address break down. It's very similar to direct mapped, except we use 4 bits for the set, instead of the slot.



Bits A4-0 is still the offset. The set number are the next 4 bits, Bits A8-5. The remaining bits, A31-9 is the tag.

Finding the Slot
Finding a slot is more complex than in direct-mapped caches. Suppose you have address B31-0.
Use bits B8-5 to find the set.
This should specify 8 slots (since we said there were 8 slots per set. The slots should have following slot indexes:
B8-5000
B8-5001
B8-5010
B8-5011
B8-5100
B8-5101
B8-5110
B8-5111
In effect, the set number specifies the upper 4 bits of the index, and the bottom 3 bits are all possible 3 bit bitstring values.
Search in all 8 slots to see if the tag A31-9 matches the tag in the slot.
If it matches one of the slots, get the byte at offset B4-0.
If not, decide which slot should be used (possibly evicting a slot), fetch the 32 bytes from memory, slot, updating valid bit, dirty bit, and tag as neededx
This is called 8-way set associative cache, since each set contains 8 slots. You can have N-way set-associative caches, where each set contains N slots (where N is a power of 2).
Compromises
This scheme is a compromise. You only have to use the complex comparison hardware (to find the correct slot) on a small set of slots, instead of over all the slots. Presumably, such comparison hardware is more than linear in the number of slots, so the fewer the slots you need to search through, the less overall hardware is needed.
Yet, you gain the flexibility of allowing up to N cache lines per slot for an N-way set associative scheme.

Summary
A set-associative cache scheme is a combination of fully associative and direct mapped schemes. You group slots into sets. You find the appropriate set for a given address (which is like the direct mapped scheme), and within the set you find the appropriate slot (which is like the fully associative scheme).
This scheme has fewer collisions because you have more slots to pick from, even when cache lines map to the same set.
mathe 2004-10-24
  • 打赏
  • 举报
回复
课本里面的东西太陈旧了
mathe 2004-10-24
  • 打赏
  • 举报
回复
计算机体系结构方面的东西,set这里是名词,可以翻译成集合?
set associative是cache的一种实现方式吧,比如说 2-way set associative cache.
你可以通过google搜索一下看看。
huangry 2004-10-24
  • 打赏
  • 举报
回复
是指什么? -_-''

我好像从来没听说过
zzwu 2004-10-24
  • 打赏
  • 举报
回复
set: 设置
associative: 关联的
Cache:高速缓冲存储器

整个意思:设置相关联高速缓存




huangry 2004-10-24
  • 打赏
  • 举报
回复
这东西 怎么感觉好像以前系统结构课里面从来没讲到 -_-''

33,008

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧