Download presentation
Presentation is loading. Please wait.
1
Cache Operation
2
Cache Parameters SIZE = total amount of cache data storage, in bytes
BLOCKSIZE = total number of bytes in a single block ASSOC = associativity, i.e., # of blocks in a set
3
Cache Parameters (cont.)
Equation for # of cache blocks in cache: Equation for # of sets in cache:
4
Address Fields 31 block offset index tag
31 block offset index tag Tag field is compared to the tag(s) of the indexed cache block(s). If there is a match, memory block is there (hit). If there isn’t a match, memory block is not there (miss). Used to lookup a “set”, which contains one or more memory blocks. The number of blocks in a set is the “associativity”. Once block is found, offset selects a particular byte or word of data in the block.
5
Address Fields (cont.) Widths of address fields (# bits)
# index bits = log2(# sets) # block offset bits = log2(block size) # tag bits = 32 - # index bits - # block offset bits Assuming 32-bit addresses 31 block offset index tag
6
31 block offset index tag Address (from processor) TAGS DATA Match? hit/miss byte or word select requested data (byte or word) (to processor)
7
Example --- Direct-mapped cache
Example: Processor accesses a 256 Byte direct-mapped cache, which has block size of 32 Bytes, with following sequence of addresses. Show contents of cache after each access, count # of hits, count # of replacements.
8
Example address sequence
Address (hex) Tag (hex) Index & Offset bits (binary) Index (decimal) Comment 0xFF0040E0 0xBEEF005C 0xFF0040E2 0xFF0040E8 0x 0x002183E0 0x 0x C 0x
9
# index bits = log2(# sets) = log2(8) = 3
# block offset bits = log2(block size) = log2(32 bytes) = 5 # tag bits = 32 bits – 3 bits – 5 bits = 24 SO: Top 6 nibbles (24 bits) of address form the tag and lower 2 nibbles (8 bits) of address form the index and block offset fields
10
Index & Offset bits (binary) Index (decimal) Comment
Address (hex) Tag (hex) Index & Offset bits (binary) Index (decimal) Comment 0xFF0040E0 0xFF0040 7 0xBEEF005C 0xBEEF00 2 0xFF0040E2 0xFF0040E8 0x 0x001010 3 0x002183E0 0x002183 0x 0x C 0x001225 0x
11
MISS TAGS DATA 31 block offset index tag 8 7 5 4 FF0040 7 24 3 FF0040
31 block offset index tag 8 7 5 4 1 2 3 6 FF0040 7 24 3 FF0040 Get block from memory (slow) Match? MISS
12
MISS TAGS DATA 31 block offset index tag 8 7 5 4 1 2 3 6 FF0040 BEEF00
31 block offset index tag 8 7 5 4 1 2 3 6 FF0040 BEEF00 2 24 3 BEEF00 Get block from memory (slow) Match? MISS
13
HIT TAGS DATA 31 block offset index tag 8 7 5 4 FF0040 FF0040 7 24 3
31 block offset index tag 8 7 5 4 1 2 3 6 FF0040 FF0040 7 24 3 BEEF00 Match? HIT
14
HIT TAGS DATA 31 block offset index tag 8 7 5 4 FF0040 FF0040 7 24 3
31 block offset index tag 8 7 5 4 1 2 3 6 FF0040 FF0040 7 24 3 BEEF00 Match? HIT
15
MISS TAGS DATA 31 block offset index tag 8 7 5 4 FF0040 001010 3 24 3
31 block offset index tag 8 7 5 4 1 2 3 6 FF0040 001010 3 24 3 BEEF00 Get block from memory (slow) 001010 Match? MISS
16
MISS & REPLACE TAGS DATA 31 block offset index tag 8 7 5 4 FF0040
31 block offset index tag 8 7 5 4 1 2 3 6 FF0040 002183 7 24 3 BEEF00 001010 Get block from memory (slow) 002183 Match? MISS & REPLACE
17
HIT TAGS DATA 31 block offset index tag 8 7 5 4 001010 3 24 3 BEEF00
31 block offset index tag 8 7 5 4 1 2 3 6 001010 3 24 3 BEEF00 001010 002183 Match? HIT
18
MISS & REPLACE TAGS DATA 31 block offset index tag 8 7 5 4 001225 2 24
31 block offset index tag 8 7 5 4 1 2 3 6 001225 2 24 3 Get block from memory (slow) 001225 BEEF00 001010 002183 Match? MISS & REPLACE
19
HIT TAGS DATA 31 block offset index tag 8 7 5 4 001225 2 24 3 001225
31 block offset index tag 8 7 5 4 1 2 3 6 001225 2 24 3 001225 001010 002183 Match? HIT
20
Index & Offset bits (binary) Index (decimal) Comment
Address (hex) Tag (hex) Index & Offset bits (binary) Index (decimal) Comment 0xFF0040E0 0xFF0040 7 Miss 0xBEEF005C 0xBEEF00 2 0xFF0040E2 Hit 0xFF0040E8 0x 0x001010 3 0x002183E0 0x002183 Miss/Repl 0x 0x C 0x001225 0x
21
Example --- N-way set-associative cache
Example: Processor accesses a 256 byte 2-way set-associative cache, which has block size of 32 bytes, with following sequence of addresses. Show contents of cache after each access, count # of hits, count # of replacements.
22
31 block offset index tag Address (from processor) TAGS DATA (32 bytes) (32 bytes) select a block Match? Match? select certain bytes hit OR
23
# index bits = log2(# sets) = log2(4) = 2
# block offset bits = log2(block size) = log2(32 bytes) = 5 # tag bits = total # address bits - # index bits - # block offset bits = 32 bits – 2 bits – 5 bits = 25
24
Index & Offset bits (binary) Index (decimal) Comment
Address (hex) Tag (hex) Index & Offset bits (binary) Index (decimal) Comment 0xFF0040E0 0x1FE0081 3 0xBEEF005C 0x17DDE00 2 0x 0x 0xFF0040E2 0x002183E0 0x 0x
25
MISS 31 7 6 5 4 tag index block offset 1FE0081 3 25 2 TAGS DATA
tag index block offset 1FE0081 3 25 2 TAGS 1 2 3 LRU DATA not shown for convenience 1FE0081 1 Match? Match? MISS
26
MISS 31 7 6 5 4 tag index block offset 17DDE00 2 25 2 TAGS 17DDE00
tag index block offset 17DDE00 2 25 2 TAGS 1 2 3 17DDE00 1 LRU DATA not shown for convenience 1FE0081 Match? Match? MISS
27
MISS 31 7 6 5 4 tag index block offset 0002020 3 25 2 TAGS 17DDE00
tag index block offset 3 25 2 TAGS 1 2 3 17DDE00 DATA not shown for convenience 1FE0081 1 1 LRU Match? Match? MISS
28
HIT 31 7 6 5 4 tag index block offset 1FE0081 3 25 2 TAGS 17DDE00 DATA
tag index block offset 1FE0081 3 25 2 TAGS 1 2 3 17DDE00 DATA not shown for convenience 1FE0081 1 1 LRU Match? Match? HIT
29
HIT 31 7 6 5 4 tag index block offset 0002020 3 25 2 TAGS 17DDE00 DATA
tag index block offset 3 25 2 TAGS 1 2 3 17DDE00 DATA not shown for convenience 1FE0081 1 1 LRU Match? Match? HIT
30
MISS & REPLACE LRU BLOCK
31 7 6 5 4 tag index block offset 3 25 2 TAGS 1 2 3 17DDE00 DATA not shown for convenience 1FE0081 1 1 LRU Match? Match? MISS & REPLACE LRU BLOCK
31
HIT 31 7 6 5 4 tag index block offset 0002020 3 25 2 TAGS 17DDE00 DATA
tag index block offset 3 25 2 TAGS 1 2 3 17DDE00 DATA not shown for convenience 1 1 LRU Match? Match? HIT
32
Index & Offset bits (binary) Index (decimal) Comment
Address (hex) Tag (hex) Index & Offset bits (binary) Index (decimal) Comment 0xFF0040E0 0x1FE0081 3 Miss 0xBEEF005C 0x17DDE00 2 0x 0x 0xFF0040E2 Hit 0x002183E0 0x Miss/Repl 0x
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.