SlideShare une entreprise Scribd logo
1  sur  10
Cache Memory

   Exercises
Questions I
• Given:
  – memory is little-endian and byte addressable;
    memory size;
  – number of cache blocks, size of cache block
  – An instruction lw $t0, x or lbu $t0, x;
• Determine
  – HIT or MISS?
  – What value is in $t0?; and
  – Show the cache after word is brought in if needed
Assume memory is little-endian and byte
Address    Contents (Hex)
                                 addressable; cache block = 1 word;
(binary)
                                 Cache holds 4 blocks of data ( 4 words)
000000     aa   bb   cc     dd
000100     00   11   00     33

001000     ff   ee   01     23
                                                        V   Tag   data(hex)
001100     45   67   89     0a
                                                        0   10    11 11 00 01   00
010000     bc   de   f0     1a
                                                        1   00    00 01 01 33   01
010100     2a   3a   4a     5a
                                                        0   11    11 11 11 11   10
011000     6a   7a   8a     9a
                                                        1   00    45 67 89 0a   11
011100     1b   2b   3b     4b
100000     b2   b3   b4     b5
100100     c1   c2   c3     c4
101000     d1   d2   d3     d4
101100     e1   e2   e3     e4
110000     f1   f2   f3     f4
                                        lbu $t0, x      # x = 001101
110100     a1   a2   a3     a4
111000     2c   3c   4c     5c          Question 1: cache HIT or
111100     2d   3d   4d     5d          MISS? What is in $t0?
                                        Draw the cache after
                                        data is brought in
Assume memory is little-endian and byte
Address       Contents (Hex)
                                    addressable; cache block = 1 word;
    (binary
    )                               Cache holds 4 blocks of data ( 4 words)
000000        aa   bb   cc     dd
000100        00   11   00     33

001000        ff   ee   01     23                          V   Tag   data(hex)
                                                           0   10    11 11 00 01   00
001100        45   67   89     0a
                                                           0   00    00 01 01 11   01
010000        bc   de   f0     1a
                                                           0   00    Ffee 01 23    10
010100        2a   3a   4a     5a
                                                           0   00    00 00 00 00   11
011000        6a   7a   8a     9a
011100        1b   2b   3b     4b
100000        b2   b3   b4     b5
100100        c1   c2   c3     c4
101000        d1   d2   d3     d4
101100        e1   e2   e3     e4
110000        f1   f2   f3     f4
                                           lbu $t0, x      # x = 001010
110100        a1   a2   a3     a4          Question 2: cache HIT or
111000        2c   3c   4c     5c          MISS? What is in $t0?
111100        2d   3d   4d     5d
                                           Draw the cache after
                                           data is brought in
Assume memory is little-endian and byte
Address    Contents (Hex)
                                 addressable; cache block = 1 word;
(binary)
                                 Cache holds 4 blocks of data ( 4 words)
000000     aa   bb   cc     dd
000100     00   11   00     33

001000     ff   ee   01     23
                                                        V   Tag   data(hex)
001100     45   67   89     0a
                                                        0   10    11 11 00 01   00
010000     bc   de   f0     1a
                                                        1   00    00 11 00 33   01
010100     2a   3a   4a     5a
                                                        0   11    11 11 11 11   10
011000     6a   7a   8a     9a
                                                        1   00    00 00 00 00   11
011100     1b   2b   3b     4b
100000     b2   b3   b4     b5
100100     c1   c2   c3     c4
101000     d1   d2   d3     d4
101100     e1   e2   e3     e4
110000     f1   f2   f3     f4
                                        lbu $t0, x      # x = 000111
110100     a1   a2   a3     a4
111000     2c   3c   4c     5c          Question 3: cache HIT or
111100     2d   3d   4d     5d          MISS? What is in $t0?
                                        Draw the cache after
                                        data is brought in
Assume memory is little-endian and byte
Address    Contents (Hex)
                                 addressable; cache block = 1 word;
(binary)
                                 Cache holds 4 blocks of data ( 4 words)
000000     11   11   00     01
000100     00   11   00     33

001000     ff   ee   01     23
                                                        V   Tag   data(hex)
001100     45   67   89     0a
                                                        0   01    11 11 00 01   00
010000     bc   de   f0     1a
                                                        1   00    00 01 01 11   01
010100     2a   3a   4a     5a
                                                        0   11    11 11 11 11   10
011000     6a   7a   8a     9a
                                                        1   00    00 00 00 00   11
011100     1b   2b   3b     4b
100000     b2   b3   b4     b5
100100     c1   c2   c3     c4
101000     d1   d2   d3     d4
101100     e1   e2   e3     e4
110000     f1   f2   f3     f4             lbu $t0, x       # x = 010010
110100     a1   a2   a3     a4
111000     2c   3c   4c     5c
                                           Question 4: cache HIT or
111100     2d   3d   4d     5d
                                           MISS? What is in $t0?
                                           Draw the cache after
                                           data is brought in
Assume memory is little-endian and byte
Address    Contents (Hex)
                                 addressable; cache block = 1 word;
(binary)
                                 Cache holds 4 blocks of data ( 4 words)
000000     aa   bb   cc     dd
000100     00   11   00     33

001000     ff   ee   01     23
                                                        V   Tag   data(hex)
001100     45   67   89     0a
                                                        0   10    11 11 00 01   00
010000     bc   de   f0     1a
                                                        0   00    00 01 01 11   01
010100     2a   3a   4a     5a
                                                        0   11    11 11 11 11   10
011000     6a   7a   8a     9a
                                                        0   00    00 00 00 00   11
011100     1b   2b   3b     4b
100000     b2   b3   b4     b5
100100     c1   c2   c3     c4
101000     d1   d2   d3     d4
101100     e1   e2   e3     e4
110000     f1   f2   f3     f4
                                        lbu $t0, x      # x = 011011
110100     a1   a2   a3     a4
111000     2c   3c   4c     5c          Question 5: cache HIT or
111100     2d   3d   4d     5d          MISS? What is in $t0?
                                        Draw the cache after
                                        data is brought in
Cache Question II-1
• Suppose: 256 bytes of memory, cache
  holds 4 blocks, each block is 1 word.
  What is the cache size?
• Answer:
aaaaaaaa  t t t t i i o o
     cache: valid tag data
Cache size:     1      4   32
(4+1+32)*4 bits
Cache Question II-2
• Suppose: 256 bytes of memory, cache
  holds 8 blocks , each block is 1 word.
  What is the cache size?
• Answer:
aaaaaaaa  t t t i i i o o
     cache: valid tag data
Cache size:     1      3   32
(3+1+32)*8 bits
Question II-3
• What is the cache size (total number of bits) for
  a cache that holds 64KB of data (block == 1
  word; 2**32 bytes of memory)
• Answer:
• 64KB == 16K words;
   – 16K = (2**4) *(2**10) = 2**14
   – So 14 bits are needed for the cache index
• Tag size = 32 – 14 -2 = 16 bits
• Cache size = (1 + (32-14-2) + 32) * (2**14)
                = 784 K bits
                = 98 KB

Contenu connexe

En vedette

STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to SlideshareSTOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to SlideshareEmpowered Presentations
 
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...SlideShare
 
How To Get More From SlideShare - Super-Simple Tips For Content Marketing
How To Get More From SlideShare - Super-Simple Tips For Content MarketingHow To Get More From SlideShare - Super-Simple Tips For Content Marketing
How To Get More From SlideShare - Super-Simple Tips For Content MarketingContent Marketing Institute
 
Masters of SlideShare
Masters of SlideShareMasters of SlideShare
Masters of SlideShareKapost
 
10 Ways to Win at SlideShare SEO & Presentation Optimization
10 Ways to Win at SlideShare SEO & Presentation Optimization10 Ways to Win at SlideShare SEO & Presentation Optimization
10 Ways to Win at SlideShare SEO & Presentation OptimizationOneupweb
 
2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShareSlideShare
 
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksHow to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksSlideShare
 
What to Upload to SlideShare
What to Upload to SlideShareWhat to Upload to SlideShare
What to Upload to SlideShareSlideShare
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShareSlideShare
 

En vedette (9)

STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to SlideshareSTOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
 
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...
 
How To Get More From SlideShare - Super-Simple Tips For Content Marketing
How To Get More From SlideShare - Super-Simple Tips For Content MarketingHow To Get More From SlideShare - Super-Simple Tips For Content Marketing
How To Get More From SlideShare - Super-Simple Tips For Content Marketing
 
Masters of SlideShare
Masters of SlideShareMasters of SlideShare
Masters of SlideShare
 
10 Ways to Win at SlideShare SEO & Presentation Optimization
10 Ways to Win at SlideShare SEO & Presentation Optimization10 Ways to Win at SlideShare SEO & Presentation Optimization
10 Ways to Win at SlideShare SEO & Presentation Optimization
 
2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare
 
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksHow to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & Tricks
 
What to Upload to SlideShare
What to Upload to SlideShareWhat to Upload to SlideShare
What to Upload to SlideShare
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShare
 

Plus de Abhijit Gaikwad (11)

Java concurrency
Java concurrencyJava concurrency
Java concurrency
 
20 ch22 collections
20 ch22 collections20 ch22 collections
20 ch22 collections
 
17 sessions
17 sessions17 sessions
17 sessions
 
16 cookies
16 cookies16 cookies
16 cookies
 
15 decorator pattern
15 decorator pattern15 decorator pattern
15 decorator pattern
 
12 memory hierarchy
12 memory hierarchy12 memory hierarchy
12 memory hierarchy
 
10 strategy pattern
10 strategy pattern10 strategy pattern
10 strategy pattern
 
9 abstract interface
9 abstract interface9 abstract interface
9 abstract interface
 
8 polymorphism
8 polymorphism8 polymorphism
8 polymorphism
 
7 inheritance
7 inheritance7 inheritance
7 inheritance
 
4 recursion details
4 recursion details4 recursion details
4 recursion details
 

12 cache questions

  • 1. Cache Memory Exercises
  • 2. Questions I • Given: – memory is little-endian and byte addressable; memory size; – number of cache blocks, size of cache block – An instruction lw $t0, x or lbu $t0, x; • Determine – HIT or MISS? – What value is in $t0?; and – Show the cache after word is brought in if needed
  • 3. Assume memory is little-endian and byte Address Contents (Hex) addressable; cache block = 1 word; (binary) Cache holds 4 blocks of data ( 4 words) 000000 aa bb cc dd 000100 00 11 00 33 001000 ff ee 01 23 V Tag data(hex) 001100 45 67 89 0a 0 10 11 11 00 01 00 010000 bc de f0 1a 1 00 00 01 01 33 01 010100 2a 3a 4a 5a 0 11 11 11 11 11 10 011000 6a 7a 8a 9a 1 00 45 67 89 0a 11 011100 1b 2b 3b 4b 100000 b2 b3 b4 b5 100100 c1 c2 c3 c4 101000 d1 d2 d3 d4 101100 e1 e2 e3 e4 110000 f1 f2 f3 f4 lbu $t0, x # x = 001101 110100 a1 a2 a3 a4 111000 2c 3c 4c 5c Question 1: cache HIT or 111100 2d 3d 4d 5d MISS? What is in $t0? Draw the cache after data is brought in
  • 4. Assume memory is little-endian and byte Address Contents (Hex) addressable; cache block = 1 word; (binary ) Cache holds 4 blocks of data ( 4 words) 000000 aa bb cc dd 000100 00 11 00 33 001000 ff ee 01 23 V Tag data(hex) 0 10 11 11 00 01 00 001100 45 67 89 0a 0 00 00 01 01 11 01 010000 bc de f0 1a 0 00 Ffee 01 23 10 010100 2a 3a 4a 5a 0 00 00 00 00 00 11 011000 6a 7a 8a 9a 011100 1b 2b 3b 4b 100000 b2 b3 b4 b5 100100 c1 c2 c3 c4 101000 d1 d2 d3 d4 101100 e1 e2 e3 e4 110000 f1 f2 f3 f4 lbu $t0, x # x = 001010 110100 a1 a2 a3 a4 Question 2: cache HIT or 111000 2c 3c 4c 5c MISS? What is in $t0? 111100 2d 3d 4d 5d Draw the cache after data is brought in
  • 5. Assume memory is little-endian and byte Address Contents (Hex) addressable; cache block = 1 word; (binary) Cache holds 4 blocks of data ( 4 words) 000000 aa bb cc dd 000100 00 11 00 33 001000 ff ee 01 23 V Tag data(hex) 001100 45 67 89 0a 0 10 11 11 00 01 00 010000 bc de f0 1a 1 00 00 11 00 33 01 010100 2a 3a 4a 5a 0 11 11 11 11 11 10 011000 6a 7a 8a 9a 1 00 00 00 00 00 11 011100 1b 2b 3b 4b 100000 b2 b3 b4 b5 100100 c1 c2 c3 c4 101000 d1 d2 d3 d4 101100 e1 e2 e3 e4 110000 f1 f2 f3 f4 lbu $t0, x # x = 000111 110100 a1 a2 a3 a4 111000 2c 3c 4c 5c Question 3: cache HIT or 111100 2d 3d 4d 5d MISS? What is in $t0? Draw the cache after data is brought in
  • 6. Assume memory is little-endian and byte Address Contents (Hex) addressable; cache block = 1 word; (binary) Cache holds 4 blocks of data ( 4 words) 000000 11 11 00 01 000100 00 11 00 33 001000 ff ee 01 23 V Tag data(hex) 001100 45 67 89 0a 0 01 11 11 00 01 00 010000 bc de f0 1a 1 00 00 01 01 11 01 010100 2a 3a 4a 5a 0 11 11 11 11 11 10 011000 6a 7a 8a 9a 1 00 00 00 00 00 11 011100 1b 2b 3b 4b 100000 b2 b3 b4 b5 100100 c1 c2 c3 c4 101000 d1 d2 d3 d4 101100 e1 e2 e3 e4 110000 f1 f2 f3 f4 lbu $t0, x # x = 010010 110100 a1 a2 a3 a4 111000 2c 3c 4c 5c Question 4: cache HIT or 111100 2d 3d 4d 5d MISS? What is in $t0? Draw the cache after data is brought in
  • 7. Assume memory is little-endian and byte Address Contents (Hex) addressable; cache block = 1 word; (binary) Cache holds 4 blocks of data ( 4 words) 000000 aa bb cc dd 000100 00 11 00 33 001000 ff ee 01 23 V Tag data(hex) 001100 45 67 89 0a 0 10 11 11 00 01 00 010000 bc de f0 1a 0 00 00 01 01 11 01 010100 2a 3a 4a 5a 0 11 11 11 11 11 10 011000 6a 7a 8a 9a 0 00 00 00 00 00 11 011100 1b 2b 3b 4b 100000 b2 b3 b4 b5 100100 c1 c2 c3 c4 101000 d1 d2 d3 d4 101100 e1 e2 e3 e4 110000 f1 f2 f3 f4 lbu $t0, x # x = 011011 110100 a1 a2 a3 a4 111000 2c 3c 4c 5c Question 5: cache HIT or 111100 2d 3d 4d 5d MISS? What is in $t0? Draw the cache after data is brought in
  • 8. Cache Question II-1 • Suppose: 256 bytes of memory, cache holds 4 blocks, each block is 1 word. What is the cache size? • Answer: aaaaaaaa  t t t t i i o o cache: valid tag data Cache size: 1 4 32 (4+1+32)*4 bits
  • 9. Cache Question II-2 • Suppose: 256 bytes of memory, cache holds 8 blocks , each block is 1 word. What is the cache size? • Answer: aaaaaaaa  t t t i i i o o cache: valid tag data Cache size: 1 3 32 (3+1+32)*8 bits
  • 10. Question II-3 • What is the cache size (total number of bits) for a cache that holds 64KB of data (block == 1 word; 2**32 bytes of memory) • Answer: • 64KB == 16K words; – 16K = (2**4) *(2**10) = 2**14 – So 14 bits are needed for the cache index • Tag size = 32 – 14 -2 = 16 bits • Cache size = (1 + (32-14-2) + 32) * (2**14) = 784 K bits = 98 KB