Review: the Associative Cache

The associative cache can store data from any memory location in any cache slot:

Review: the Associative Cache

BUT: it uses millions of compare circuits:

Review: the Direct Mapped Cache

The direct mapped cache uses 1 compare circuit (and 3 sets of multiplexors):

Review: the Direct Mapped Cache

BUT:   data from a memory location must be stored in a specific cache slot:

The Set Associative cache

The set-associative cache consists of N direct mapped caches:

Data from memory can be stored in either direct mapped cache (but not in both caches)

The Set Associative cache

Data from a memory location can be stored in different slots in a set associative cache:

So we have achieve a higher level of flexibility !!

How to use a set associative cache

Consider the following content of a set associative cache:

Which memory addresses are cached in the highlighted cache slot ?

How to use a set associative cache

Answer:

The data is at offset 2 in block 2 in memory !

How to use a set associative cache

Consider the following content of a set associative cache:

Which memory addresses are cached in the highlighted cache slot ?

How to use a set associative cache

Answer:

The data is at offset 2 in block 0 in memory !

Constructing a Set Associative cache - overview

Recall: that each direct mapped caches will output a cache hit and data signals:

We need to combine the multiple outputs into a single result !!

Constructing a Set Associative cache - overview

We use the parallel search technique in the set-associative cache combine the results:

Constructing a Set Associative cache - circuit

The following is the (simplified) circuit for a set associative cache:

Constructing a Set Associative cache - circuit

The input and outputs of the set associative cache are as follows:

Constructing a Set Associative cache - circuit

We start with the input and output signals (I will only use 2 direct mapped caches)

Constructing a Set Associative cache - circuit

The first direct mapped cache will output its cache hit and data signals:

Constructing a Set Associative cache - circuit

The second direct mapped cache will also output its cache hit and data signals:

Constructing a Set Associative cache - circuit

We have 2 "chances" to get a cache hit:

Constructing a Set Associative cache - circuit

If (any) one of the direct mapped cache reports cache hit, we have a cache hit:

Constructing a Set Associative cache - circuit

To obtain the data output, we first filter the cache 1's data by its cache hit signal:

Constructing a Set Associative cache - circuit

When cache hit=0, the output are all equal to 0 and when cache hit=1, output=data:

Constructing a Set Associative cache - circuit

We also filter the cache 2's data by its cache hit signal:

Constructing a Set Associative cache - circuit

We use OR-gates to collect all the filtered outputs to form the data outputs: