# Direct and Associate Cache - Offset, Index, and Tag

I have two questions:

An 8-kB (8192 bytes) direct-mapped cache has 16-byte lines.
The system has 64-bit addresses numbered from 0 on the right to 63 on the left.
Which bits are associated with the offset, index, and tag?

A 16-kB (16384 bytes) 4-way set associative cache has 8-byte lines.
The system has 64-bit addresses numbered from 0 on the right to 63 on the left.
Which bits are associated with the offset, index, and tag?


For offset, it's: tag bits = address bit length - exponent of index - exponent of offset, correct?

Then the Index for a direct mapped cache is the number of blocks in the cache, and the Tag bits are everything else, right?

How would I calculate these? Because I'm a little confused on an associated cache vs a direct-map cache.

An 8-kB (8192 bytes) direct-mapped cache has 16-byte lines.
The system has 64-bit addresses numbered from 0 on the right to 63 on the left.
Which bits are associated with the offset, index, and tag?


Since a cache line is 16-byte long, it can be represented with $$\log_2 16 = 4 \text{b}$$, which is the number of bits required for the offset field. The number of lines in the cache are $$\frac{8\text{kB}}{16\text{B}} = 512$$. The index maps these entire lines; therefore, $$\log_2 512 = 9\text{b}$$ are required. The tag field gets the rest, that is, $$64-9-4=51\text{b}$$.

A 16-kB (16384 bytes) 4-way set associative cache has 8-byte lines.
The system has 64-bit addresses numbered from 0 on the right to 63 on the left.
Which bits are associated with the offset, index, and tag?


As before, $$\log_2 8 = 3\text{b}$$ for the offset field. Since the cache is 4-way associative, the number of sets are $$\frac{16\text{kB}}{4\cdot 8\text{B}}=512$$, which, again, requires $$9\text{b}$$ for the index field. Finally, the tag is $$52$$ bits long.

• @greybeard, why one set? you can select 2^9 sets. – Gilsho Feb 6 at 10:53