Cache mapping
• Number of blocks in main memory=
• Main memory size/ block size
• = 2 20 Bytes/ 2 4 Bytes
• Main memory = 220 Bytes
• number of bits in physical address= 20 bits.
• Block size= 16 Bytes
• = 2 4 Bytes
• number of bits in block offset = 4 bits.
• Cache memory contains 32 blocks = 2 5 blocks
• Number of bits in cache index = 5 bits
• Number of bits in tag : the remaining
• = 20 – (5+4)
• =11 bits
• ODB63 = 0000 1101 1011 0110 0011
• The first least significant bits are for the offset
• The next 5 bits are for cache index.
• 10110 is 22 in decimal
• ODBC will map (22 Mod 32) = 22 cache block
that is the block number 23 (blocks start from
0)
• In the figure below, the physical address in
only divided into offset and tag.
• A block in the main memory can map any
address in the cache memory.
• It is the fully associative mapping.
• When the cache is searched, all entries (block
in cache) are searched in parallel to retrieve
the data.
• Main memory size= 2 14 words
• number of bits in physical address = 14 bits
• Block size= 8 words
• = 23 words
•  number of bits in offset = 3 bits
• Number of lines in cache memory = 16 blocks
• 2-way set associative mapping means each set
contains 2 blocks
•  16/2 = 8 sets = 2 3 sets
• That is 3 bits for the set index
• The tag bits are the remaining tag=
• 14 – (3+3) = 8 bits
• Direct mapping case:
• Block size = 32 Bytes = 2 5 Bytes
• 5 bits offset
• Cache Memory size =64 Kbytes = 26* 210 Bytes
• Number of lines = CM size/ Block size
•  216 Bytes / 32 Bytes = 211 Bytes
•  11 bits for index
Tag 8 bits Index 11 bits Offset 5 bits
• Tag bits = the remaining
• = 24- (11+5)
• = 8 bits
• Fully associative case:
• Block size = 32 Bytes = 2 5 Bytes
• 5 bits offset
• In full associative, all the rest of bits is for the
tag since a block in Main Memory can be
mapped to any cache block
Tag 19 bits Offset 5 bits
• 4-way set associative :
• Block size = 32 Bytes = 2 5 Bytes
• 5 bits offset
• Cache Memory size =64 Kbytes = 26* 210 Bytes
• Number of lines = CM size/ Block size
•  216 Bytes / 32 Bytes = 211 lines
• Each set contains 4 blocks = 22 blocks
• So the number of sets is :
• 211/22=29
•  9 bits for set
• Tag bits = the remaining
• = 24- (9+5)
• = 10 bits
Tag 10 bits Index 9 bits Offset 5 bits
• Step 1 : read 30
• 30 Mod 5 = 0
• So we go to address zero and map the
memory block  miss
• Step 2 : read 31
• 31 Mod 5 = 1
• So we go to address one and map the memory
block again miss
• Step 3 : read 30
• It already exists at this position  hit
• Step 4 : read 26
• 26 Mod 5 = 1 (address location busy, we will
replace and we no longer have 31 in cache)
• So we go to address one and replace the
memory block  miss
• Step 5 : read 25
• 25 Mod 5 = 0 (address location busy, we will
replace and we no longer have 30 in cache)
• So we go to address zero and replace the
memory block  miss
• Step 6 : read 28
• 28 Mod 5 = 3
• So we go to address three and map the memory
block  miss
• Step 7 : read 23
• 23 Mod 5 = 3 (address location busy, we will
replace and we no longer have 28 in cache)
• So we go to address three and replace the
memory block  miss
• Step 7 : read 25
• Already in cache memory  hit
• Step 8: read 28
• 28 Mod 5 = 3 (address location busy, we will
replace and we no longer have 23 in cache)
• So we go to address three and replace the
block 23 by 28  miss

Cache mapping exercises

  • 1.
  • 3.
    • Number ofblocks in main memory= • Main memory size/ block size • = 2 20 Bytes/ 2 4 Bytes
  • 4.
    • Main memory= 220 Bytes • number of bits in physical address= 20 bits. • Block size= 16 Bytes • = 2 4 Bytes • number of bits in block offset = 4 bits.
  • 5.
    • Cache memorycontains 32 blocks = 2 5 blocks • Number of bits in cache index = 5 bits • Number of bits in tag : the remaining • = 20 – (5+4) • =11 bits
  • 6.
    • ODB63 =0000 1101 1011 0110 0011 • The first least significant bits are for the offset • The next 5 bits are for cache index. • 10110 is 22 in decimal • ODBC will map (22 Mod 32) = 22 cache block that is the block number 23 (blocks start from 0)
  • 8.
    • In thefigure below, the physical address in only divided into offset and tag. • A block in the main memory can map any address in the cache memory. • It is the fully associative mapping. • When the cache is searched, all entries (block in cache) are searched in parallel to retrieve the data.
  • 10.
    • Main memorysize= 2 14 words • number of bits in physical address = 14 bits • Block size= 8 words • = 23 words •  number of bits in offset = 3 bits
  • 11.
    • Number oflines in cache memory = 16 blocks • 2-way set associative mapping means each set contains 2 blocks •  16/2 = 8 sets = 2 3 sets • That is 3 bits for the set index • The tag bits are the remaining tag= • 14 – (3+3) = 8 bits
  • 13.
    • Direct mappingcase: • Block size = 32 Bytes = 2 5 Bytes • 5 bits offset • Cache Memory size =64 Kbytes = 26* 210 Bytes • Number of lines = CM size/ Block size •  216 Bytes / 32 Bytes = 211 Bytes •  11 bits for index Tag 8 bits Index 11 bits Offset 5 bits
  • 14.
    • Tag bits= the remaining • = 24- (11+5) • = 8 bits
  • 15.
    • Fully associativecase: • Block size = 32 Bytes = 2 5 Bytes • 5 bits offset • In full associative, all the rest of bits is for the tag since a block in Main Memory can be mapped to any cache block Tag 19 bits Offset 5 bits
  • 16.
    • 4-way setassociative : • Block size = 32 Bytes = 2 5 Bytes • 5 bits offset • Cache Memory size =64 Kbytes = 26* 210 Bytes • Number of lines = CM size/ Block size •  216 Bytes / 32 Bytes = 211 lines • Each set contains 4 blocks = 22 blocks
  • 17.
    • So thenumber of sets is : • 211/22=29 •  9 bits for set • Tag bits = the remaining • = 24- (9+5) • = 10 bits Tag 10 bits Index 9 bits Offset 5 bits
  • 19.
    • Step 1: read 30 • 30 Mod 5 = 0 • So we go to address zero and map the memory block  miss • Step 2 : read 31 • 31 Mod 5 = 1 • So we go to address one and map the memory block again miss
  • 20.
    • Step 3: read 30 • It already exists at this position  hit • Step 4 : read 26 • 26 Mod 5 = 1 (address location busy, we will replace and we no longer have 31 in cache) • So we go to address one and replace the memory block  miss
  • 21.
    • Step 5: read 25 • 25 Mod 5 = 0 (address location busy, we will replace and we no longer have 30 in cache) • So we go to address zero and replace the memory block  miss • Step 6 : read 28 • 28 Mod 5 = 3 • So we go to address three and map the memory block  miss
  • 22.
    • Step 7: read 23 • 23 Mod 5 = 3 (address location busy, we will replace and we no longer have 28 in cache) • So we go to address three and replace the memory block  miss • Step 7 : read 25 • Already in cache memory  hit
  • 23.
    • Step 8:read 28 • 28 Mod 5 = 3 (address location busy, we will replace and we no longer have 23 in cache) • So we go to address three and replace the block 23 by 28  miss