Professional Documents
Culture Documents
Lec-7 Memory-2 CompArch
Lec-7 Memory-2 CompArch
Memory-2
CSE-2823
Computer Architecture
Dr. Md. Waliur Rahman Miah
Associate Professor, CSE, DUET
1
Today’s Topic
Memory
Part-2
Ref:
Hennessy-Patterson 5e-Ch-5; 4e-Ch-7
Stallings 8e-Ch-4-5-6
Dr. Md. Waliur Rahman Miah Dept of CSE, DUET 2
Caches
• By simple example
– assume block size = one word of data
X4 X4
X1 X1
Xn – 2 Xn – 2
Reference to Xn
causes miss so
Xn – 1 Xn – 1 it is fetched from
memory
X2 X2
Xn
X3 X3
• Issues:
– how do we know if a data item is in the cache?
– if it is, how do we find it?
– if not, what do we do?
• Solution depends on cache addressing scheme…
Dr. Md. Waliur Rahman Miah Dept of CSE, DUET
General Organization of a Cache
Cache is an array 1 valid bit t tag bits B = 2b bytes
of sets per line per line per cache block
Each set contains
valid tag 0 1 • • • B–1
one or more lines E lines
set 0: •••
per set
Each line holds a valid tag 0 1 • • • B–1
block of data
valid tag 0 1 • • • B–1
S = 2s sets set 1: •••
valid tag 0 1 • • • B–1
•••
valid tag 0 1 • • • B–1
set S-1: •••
valid tag 0 1 • • • B–1
Cache size:
Dr. Md. Waliur Rahman Miah
C = B x E x S data bytes
Dept of CSE, DUET
Addressing Caches
Address A:
t bits s bits b bits
m-1 0
v tag 0 1 • • • B–1
set 0: •••
v tag 0 1 • • • B–1 <tag> <set index> <block offset>
v tag 0 1 • • • B–1
set 1: •••
v tag 0 1 • • • B–1
•••
The word at address A is in the cache if
v tag 0 1 • • • B–1
set S-1: ••• the tag bits in one of the <valid> lines in
v tag 0 1 • • • B–1 set <set index> match <tag>
v tag 0 1 • • • B–1
set 1: •••
v tag 0 1 • • • B–1
•••
1. Locate the set based on
v tag 0 1 • • • B–1
set S-1: ••• <set index>
v tag 0 1 • • • B–1 2. Locate the line in the set based on
<tag>
3. Check that the line is valid
4. Locate the data in the line based on
Dr. Md. Waliur Rahman Miah Dept<block
of CSE, offset>
DUET
Direct-Mapped Cache
Simplest kind of cache, easy to build
(only 1 tag compare required per access)
Characterized by exactly one line per set.
set 0: valid tag cache block E=1 lines per set
0 1 2 3 4 5 6 7
101 N 101 N
110 Y 10 Mem(10110) 110 Y 10 Mem(10110)
111 N 111 N
(4) Address referred 10010 (miss):
v tag data
0
1 ?1
0 ?
M[8-9]
M[0-1]
1 0 M[6-7]
Dr. Md. Waliur Rahman Miah Dept of CSE, DUET
Direct Mapped Cache