Trade-off: giving up flexibility for reduced cost

The problem with the associative cache memory:

 
 

We need to use a lot of compare circuits to make a associative cache

Trade-off: giving up flexibility for reduced cost

The associative cache can store (4 bytes) data from any memory location in any slot: (= flexible)

 
 

We will trade this flexibility for remove the need for millions of compare circuits !

What is the inflexibility in caching ?

Inflexible caching: the data from memory can only be stored in one specific slot in the cache

 
 

With an 8-slots cache:   data from address 0 must be stored in slot 0, data from address 4 must be stored in slot 1 (4/4=1), data from address 8 must be stored in slot 2 (8/4=2), etc

What is the inflexibility in caching ?

Inflexible caching: data from memory can only be stored in one specific slot in the cache

 
 

With an 8-slots cache:   data from address 32 (32/4=8=8+0) must be stored in slot 0, data from address 36 must be stored in slot 1, data from address 40 must be stored in slot 2 (40/4=10=8+2), etc

The direct mapped cache

The slot k in direct mapped cache can only store the memory addresses that are mapped to k:

 
 

The mapping is k = ((Mem Addr)/4) % CacheSize

The direct mapped cache

Example: memory locations that are mapped to slot 2 in an 8-slot direct mapped cache: (part 1)

 
 

The mapping is 2 = ((Mem Addr)/4) % 8   ---   = addresses 8,9,10,11 ((addr/4)%8=2)

The direct mapped cache

Example: memory locations that are mapped to slot 2 in an 8-slot direct mapped cache: (part 2 + end)

 
 

The mapping is 2 = ((Mem Addr)/4) % 8   ---   and address 40,41,42,43 ((addr/4)%8=2), etc,etc

How to identify which memory locations are cached in a slot in a direct mapped cache

We map memory addresses to block numbers in a direct mapped cache as follows:

 
 

Block number = (mem addr/4) / CacheSize

How to identify which memory locations are cached in a slot in a direct mapped cache

Example: when memory data from address 8,9,10,11 is stored in slot 2: we store blk num = 0

 
 

The block number stored in the slot = ({8,9,10,11}/4) / 8 = 2/8 = 0

How to identify which memory locations are cached in a slot in a direct mapped cache

Example: when memory data from address 40,41,42,43 is stored in slot 2: we store blk num = 1

 
 

The block number stored in the slot = ({40,41,42,43}/4) / 8 = 10/8 = 1

How to identify which memory locations are cached in a slot in a direct mapped cache

Practice example 1:

Find the memory locations that is currently cached in the entry 2

How to identify which memory locations are cached in a slot in a direct mapped cache

Answer 1:

The data is at "position 2" in block 0 in memory.

How to identify which memory locations are cached in a slot in a direct mapped cache

Practice example 2:

Find the memory locations that is currently cached in the entry 6

How to identify which memory locations are cached in a slot in a direct mapped cache

Answer 2:

The data is at "position (offset) 6" in block 2 in memory.

How to identify which memory locations are cached in a slot in a direct mapped cache

Practice example 3:

Find the memory locations that is currently cached in the entry 3

How to identify which memory locations are cached in a slot in a direct mapped cache

Answer 3:

This slot currently is not used !!