Cache - Memory - Concept
Cache - Memory - Concept
Cache Memory
Temporal
– Recently executed instruction is likely to be executed again
very soon
– Whenever an item is first needed, it is first brought to the
cache, where it will hopefully remain until it is needed
again. Also influences choice on which item to discard when
cache is full
Spatial
– Instructions in close proximity to a recently executed
instruction are also likely to be executed soon
– Instead of fetching just one item into the cache, fetch
several adjacent data items as well (block/cache line)
25/03/2020 Cache Memory 5
Cache Memory
Cache Memory is intended to give:
– Memory speed approaching that of the fastest
memories available.
– Large memory size at the price of less expensive
types of semiconductor memories.
Cache
Main
2n-1 Memory
Word Length
Block 4095
25/03/2020 Cache Memory 14
Direct Mapping
Block j of main memory maps onto block (j modulo
128) of the cache.
Example:
– Block 2103 of main memory maps to block (2103 mod 128)
= block 55
Each main memory block has only one place in
cache
Cache Block 0
– Memory Blocks 0, 128, 256...
Cache Block 1
– Memory Blocks 1, 129, 257...
Contention may occur even when cache is not full
Replacement algorithm is trivial
Simplest
– Very inflexible
Block 4095
25/03/2020 Cache Memory 18
Direct Mapping Cache Organization
5 13 3
Block 4095
25/03/2020 Cache Memory 23
Associative Mapping
Block 4095
25/03/2020 Cache Memory 27
25/03/2020 Cache Memory 28
Set-Associative Mapping
11 10 4
7A04h A(0,1)
Set-Associative 15
7A05h A(1,1)
7A06h A(2,1)
Associative 16
7A07h A(3,1)
… … 16-Bit
16
7A24h A(0,9) Address
7A25h A(1,9)
7A26h A(2,9)
7A27h A(3,9)
Array Address
A(0,0) 7A00h
A(0,1) 7A04h
SUM := 0 A(0,2) 7A08h
for j:= 0 to 9 do A(0,3) 7A0Ch
SUM := SUM + A(0,j) A(0,4) 7A10h
end
A(0,5) 7A14h
AVE := SUM / 10
A(0,6) 7A18h
for i:= 9 downto 0 do
A(0,i) := A(0,i) / AVE A(0,7) 7A1Ch
end A(0,8) 7A20h
A(0,9) 7A24h
1
2
3
4 A(0,1) A(0,3) A(0,5) A(0,7) A(0,9) A(0,7) A(0,5) A(0,3) A(0,1)
5
6
7
4
Set 1 5
6
7
tavg = hC + (1–h)M
Processing Units
LI Instruction LI Data
Cache Cache
k m
m k