�Caches II
CS61C
UC Berkeley�Teaching Professor �Dan Garcia
cs61c.org
Great Ideas
in�Computer Architecture
(a.k.a. Machine Structures)
Garcia
Caches II (1)
Garcia
Direct Mapped Caches
Caches II (2)
Garcia
Direct-Mapped Cache (1/4)
Caches II (3)
Garcia
Direct-Mapped Cache (2/4)
Memory
Memory �Address
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
4 Byte Direct
Mapped Cache
Cache
Index
0
1
2
3
What if we wanted a block�to be bigger than one byte?
Block size = 1 byte
Caches II (4)
Garcia
Direct-Mapped Cache (3/4)
Memory
Memory �Address
0
2
4
6
8
A
C
E
10
12
14
16
18
1A
1C
1E
8-Byte Direct
Mapped Cache
Cache
Index
0
1
2
3
Block size = 2 bytes
0
1
2
3
4
5
6
7
8
9
etc.
Caches II (5)
Garcia
Direct-Mapped Cache (4/4)
Memory
Memory �Address
0
2
4
6
8
A
C
E
10
12
14
16
18
1A
1C
1E
8-Byte Direct
Mapped Cache with Tag
Cache
Index
0
1
2
3
Block size = 2 bytes
0
1
2
3
4
5
6
7
8
9
etc.
0
1
2
3
Cache#
1
0
3
2
8
2
1E
14
Caches II (6)
Garcia
Issues with Direct-Mapped
ttttttttttttttttt iiiiiiiiii oooo
tag index byte�to check to offset�if have select within�correct block block block
Caches II (7)
Garcia
Direct-Mapped Cache Terminology
Caches II (8)
Garcia
AREA (cache size, B)�= HEIGHT (# of blocks) � * WIDTH (size of one block, B/block)
WIDTH �(size of one block, B/block)
HEIGHT�(# of blocks)
2(H+W) = 2H * 2W
Tag Index Offset
TIO Cache Mnemonic (Thanks Uncle Dan!)
AREA�(cache size, B)
🗹
Caches II (9)
Garcia
Direct Mapped Example
Caches II (10)
Garcia
Direct-Mapped Cache Example (1/3)
= 21 bytes
Caches II (11)
Garcia
Direct-Mapped Cache Example (2/3)
= bytes/cache� bytes/block
= 23 bytes/cache� 21 bytes/block
= 22 blocks/cache
Caches II (12)
Garcia
Direct-Mapped Cache Example (3/3)
Caches II (13)
Garcia
Memory Access without Cache
Caches II (14)
Garcia
Memory Access with Cache
2a. If finds a match (Hit): cache reads 99, sends to processor
2b. No match (Miss): cache sends address 1022 to Memory
Caches II (15)
Garcia
Solving Cache problems
WIDTH �(size of one block, B/block)
HEIGHT�(# of blocks)
Tag Index Offset
CACHE
WIDTH �(size of one block, B/block)
Tag = 0
Tag = 1
Tag = 2
Tag = max
00…00 00…00 00…00
00…00 00…00 00…01
00…00 00…00 11…11
00…00 00…01 00…00
00…00 11…11 11…11
00…01 00…00 00…00
11…11 11…11 11…11
Tag Index Offset
MEMORY
🗹
Caches II (16)
Garcia
Cache Terminology
Caches II (17)
Garcia
Caching Terminology
Caches II (18)
Garcia
Cache Temperatures
Caches II (19)
Garcia
Cache Terms
Caches II (20)
Garcia
One More Detail: Valid Bit
0 🡪 cache miss, even if by chance, address = tag
1 🡪 cache hit, if processor address = tag
Caches II (21)
Garcia
Example: 16 KB Direct-Mapped Cache, 16B blocks
...
Valid
Tag
0xc-f
0x8-b
0x4-7
0x0-3
0
1
2
3
4
5
6
7
1022
1023
...
Index
0
0
0
0
0
0
0
0
0
0
Looks like a real cache, will investigate it some more!
Caches II (22)
Garcia
Caches II (23)
Garcia
“And in Conclusion…”
🗹
Caches II (24)
Garcia