(5 pts) Exercise 7-1: Direct Mapped Cache Memory 20 7 21 3 22 27 23 32 24 101 25 78 26 59 27 24 28 56 29 87 30 36 31 98 Cache (N = 5) Address 0 1 Processor Data 30,25 36,78 31,26 98,59 28,23,28 56,32,56 M M H M M M M H M 2 3 4 1. 2. 3. 4. 5. 6. 7. 8. 9. Read 30 Read 31 Read 30 Read 26 Read 25 Read 28 Read 23 Read 25 Read 28 2 7 Total hits? Total misses? (5 pts) Exercise 7-2: Direct Mapped Cache N = 4) Cache ( Memory 20 7 21 3 22 27 23 32 24 101 25 78 26 59 27 24 28 56 29 87 30 36 31 98 Address Data 28 56 1 25 78 2 30,26 36,59 3 31,23 98,32 0 Processor Total hits? Total misses? 2-M M 3-M M 2-H H 2-M M 1-M M 0-M M 3-M M 1-H H 0-H H 3 6 1. 2. 3. 4. 5. 6. 7. 8. 9. Read 30 Read 31 Read 30 Read 26 Read 25 Read 28 Read 23 Read 25 Read 28 (5 pts) Exercise 7-6 • Look back at Exercises 1 and 2 and A.) identify two different kinds of reasons for why there might be a cache miss. B.) explain a technique for addressing each type of miss • Reason #1 for missing: 1. Evicted b/c of conflicts (add associativity) – How to address? • Reason #2 for missing: 2. Never accessed (increase block size, or pre-fetching) – How to address? (5 pts) Exercise 7-11 – Show final cache and total hits Block size = 2, N = 4 Memory 20 7 21 3 22 27 23 32 24 101 25 78 26 59 27 24 28 56 29 87 30 36 31 98 Cache Address 0 1 2 Processor Data 16,24,16,24 (16),(24),(16),(24) (17),(25),(17),(25) 26 (26) (27) 12 (12) (13) 14 (14) (15) 3 Total # hits? 0-M 3-M 0-H 2-M 0-M 0-M 3-H 0-M 1-M 1. 2. 3. 4. 5. 6. 7. 8. 9. Read 16 Read 14 Read 17 Read 13 Read 24 Read 17 Read 15 Read 25 Read 27 2 hits (5 pts) Exercise 7-12 Show the correct formula for calculating the cache index, given the cache parameters below Index = (Address/4) mod 10 1. N = 10, Block size = 4 • 2. N = 8, Block size = 1, Associativity = 4 Index = (Address/1) mod (8/4) 3. N = 16, Block size = 8, Associativity = 2 Index = (Address/8) mod (16/2) (5 pts) Exercise 7-13 – Fill in blanks, show final cache, hit/miss for each access, and total hits Block size = _____, N = ______, Assoc = _____ Memory 2 20 7 Address 21 3 22 27 23 32 24 101 25 78 26 59 27 24 28 56 29 87 30 36 31 98 8 Cache 4 Data 24 (24) (25) 20 (20) (21) 26 (26) (27) 0 1 Processor 0-M1. 0-H2. 1-M3. 0-H4. 0-M5. 1-H6. 0-H7. 1-H8. 1-H9. Read 24 Read 25 Read 26 Read 24 Read 21 Read 26 Read 24 Read 26 Read 27 (15 pts) Exercise 7-16 • • Assume you have an empty cache with a total of 16 blocks, with each block having 2 bytes. In this exercise, the cache is direct mapped. At right is a series of byte addresses. You should: 1. Write the appropriate FORMULA below (filled in for value of N, etc.) 2. For each address, compute the index and label each one hit or miss 3. Draw the cache and show the final contents of the cache As always, show your work. Address Hit / Miss Miss? Index Index 2 M 1 3 H 1 11 M 5 16 M 8 21 M 10 10 H 5 80 M 8 48 M 8 Formula: 39 M 3 Index = (Address/2) mod 16 11 H 5 3 H 1 80 M 8 • Index = Since the block size is 2, a load to address 2 will also bring in address 3, or a load to address 7 will also bring in address 6. Index First address in block (last number is actual contents, earlier numbers were evicted) 0 1 2 2 3 38 4 5 10 6 7 8 16,80,48,80 9 10 11 12 13 14 15 20 (15 pts) Exercise 7-17 Assume you have an empty cache with a total of 16 blocks, with each block having 2 bytes. In this exercise, the cache is twoway set associative. Assume LRU replacement. • At right is a series of byte addresses. You should: 1. Write the appropriate FORMULA below (filled in for value of N, etc.) 2. For each address, compute the index and label each one hit or miss 3. Draw the cache and show the final contents of the cache As always, show your work. • Formula: Index = (Address/2) mod (16/2) Index == (Address/2) mod 8 There is a total of 16 blocks. 2-way associativity divides these into 16/2 =8 sets. Address Hit Hit/miss / Miss? Index Index 2 M 1 3 H 1 11 M 5 16 M 0 21 M 2 10 H 5 80 M 0 48 M 0 39 M 3 11 H 5 3 H 1 80 H 0 Index First address in block (last number is actual contents, earlier numbers were evicted) 0 16, 48 80 1 2 2 20 3 38 4 5 6 7 10