Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

1Learning Outcomes

In an earlier section, we explained why hardware costs make fully associative caches rather uncommon in modern processors. We now introduce the other end of the spectrum policy: a direct mapped cache. With this new cache, we consider again the cache design policies and walk through an example.

2Placement Policy

3Identification

Consider our visualization for a 16B, direct-mapped cache with 4B blocks in Figure 1.

"TODO"

Figure 1:A cold snapshot of a 16B direct-mapped cache with 4B blocks and a dirty bit for write-back.

On the surface, the direct mapped cache looks very similar to that of our fully associative cache. We discuss how the direct mapped placement policy shortens the tag width and impacts the identification procedure to determine a cache hit.

3.1Tag, Index, and Offset

The mapping of pretty much all direct-mapped caches is simple:

(Block address) modulo (nunber of blocks in cache)\text{(Block address) modulo (nunber of blocks in cache)}

Like before direct-mapped caches copy in data from memory at the granularity of blocks. The block address is the address of a cache block and, by definition, is the address of the (lowest significant byte of) block in memory. The lowest bits of the address therefore describe byte addresses within a block and are still defined as the offset.

Now, we can connect the direct-mapped cache in Figure 1 to the 12-bit memory address in Figure 2.

"TODO"

Figure 2:For a direct-mapped cache, the memory address is split into three fields: the tag, the index, and the offset. For the blocks in Figure 1, a 12-bit memory address is split into an 8-bit tag, a 2-bit index, and a 2-bit offset.

4Replacement Policy

5Write Policy

6Walkthrough

The following animation traces through four memory accesses to a 12-bit address space on our 16B direct mapped with 4B blocks. Assume a write-back policy. Assume the cache starts out cold, like in Figure 1.

Figure 3:Warming up a direct mapped cache.

Contrast this direct mapped cache walkthrough with the one for fully associative caches: