page_title: Cache placement policies
section_title: Example
hierarchical_section_title: Cache placement policies / Direct-mapped cache / Example
caption_attribution_description: English: Direct-Mapped Cache
context_page_description: A CPU cache is a memory which holds the recently utilized data by the processor. A block of memory cannot necessarily be placed randomly in the cache and may be restricted to a single cache line or a set of cache lines by the cache placement policy. In other words, the cache placement policy determines where a particular memory block can be placed when it goes into the cache.
  There are three different policies available for placement of a memory block in the cache: direct-mapped, fully associative, and set-associative. Originally this space of cache organizations was described using the term "congruence mapping".
context_section_description: Consider a main memory of 16 kilobytes, which is organized as 4-byte blocks, and a direct-mapped cache of 256 bytes with a block size of 4 bytes.
  Since each cache block is of size 4 bytes, the total number of sets in the cache is 256/4, which equals 64 sets.
  The incoming address to the cache is divided into bits for Offset, Index and Tag.
  Offset corresponds to the bits used to determine the byte to be accessed from the cache line.
  In the example, the offset bits are 2 which are used to address the 4 bytes of the cache line.
  Index corresponds to bits used to determine the set of the Cache.
  In the example, the index bits are 6 which are used to address the 64 sets of the cache.
  Tag corresponds to the remaining bits.
  In the example, there are 14 – (6+2) = 6 tag bits, which are stored in tag field to match the address on cache request.
  Address 0x0000(tag - 00_0000, index – 00_0000, offset – 00) maps to block 0 of the memory and occupies the set 0 of the cache.
  Address 0x0004(tag - 00_0000, index – 00_0001, offset – 00) maps to block 1 of the memory and occupies the set 1 of the cache.
  Similarly, address 0x00FF(tag – 00_0000, index – 11_1111, offset – 11) maps to block 63 of the memory and occupies the set 63 of the cache.
  Address 0x0100(tag – 00_0001, index – 00_0000, offset – 00) maps to block 64 of the memory and occupies the set 0 of the cache.
caption: Direct-Mapped Cache
exif: {}