There are 3 types of cache memories:
|
In this slide set, we study the associative cache
The program's view of the computer memory is: each byte is identified by an address
(I will show you a different view - "data transfer view" - of the memory later...)
|
The data transfer's view of the computer memory is as follows: a unit of tranfer is 4 bytes
Each transfer (read) operation will transfer 4 bytes from memory to the CPU
The block number of an associative cache memory is a number that identifies a unit of data transfer:
How to find a block number for a given memory address:
|
The associative cache memory has the following structure:
The Valid Flag is 1 bit
For a
32 bits
address bus,
the
block number will be
a
30 bit
binary number
(explained later)
(But I will use decimal numbers to
represent its value)
For a
32 bits
data bus,
the
value stored is
a
32 bit
binary number
(But I will use decimal numbers to
represent it)
Definition: slot of a cache memory = one row in a cache memory
Today, cache size ranges from 1 GBytes - 8 GBytes or 0.25 G - 2 G slots
I will now explain how each field in the associative cache is used.
The valid flag indicates whether the value stored in cache entry is valid or invalid:
Initially:
|
When a slot is filled with data from memory, that slot will become valid
The block number identifies the memory locations that are cached in a cache entry:
For an address bus of
32 bits,
the
block number is
a
30 bits
binary number
I will denote
block numbers as
a (unsigned)
decimal integer
(Why 30 bits will be explained later)
Recall how the block numbers are computed from memory addresses: Blk Num = Addr / 4
The block numbers are stored in the cache to identify the memory locations being cached
Quiz: Can you tell which memory addresses are being cached in this cache entry:
Hint: block number 0 spans address 0,1,2,3, block number 1 spans address 4,5,6,7, ...
Answer: data in memory addresses 16, 17, 18, 19 (= 4x4, 4x4+1, 4x4+2, 4x4+3)
Hint: block number 2 spans address 8,9,10,11, block number 3 spans address 12,13,14,15, ...
The value field contains the data from the 4 memory cells identified by the block number:
For a
32 bits
data bus,
the
value is a
32 bits
binary number
But
I will denote it as
a (unsigned) decimal integer
The following diagram shows an example content of the memory and an associative cache:
Note: the memory content is shown in 4 bytes units and identified using block numbers !!!
Example: the slot with block # 78 is valid and contains the correct value stored in memory:
From the (1) valid field and (2) the block number field, the cache memory can tell that the value is from memory locations 78x4, 78x4+1, 78x4+2, 78x4+3
Suppose the CPU want to read the 4 bytes at address 16:
The cache memory will check whether the value is in the cache first before reading the RAM !!
The associative cache memory detects that it contains the correct value in one of its entry:
The cache memory will return the data to the CPU and no memory operation is performed !!
Suppose the CPU wnat to read the 4 bytes at address 408:
The cache memory will check whether the value is in the cache first before reading the RAM !!
The block # 102 is not found in any cache slot:
The cache memory will now perform a memory read operation and fetch the missing data from RAM
The data from memory will be inserted into a (unused) slot of the cache and then sent to the CPU:
Note: if there is no unused slot, the slot that contains the "oldest" unused item is replaced