Cache Parameters

There are many parameters that can vary in the design of a cache memory system, but many of them can be derived from other ones. For example, looking at the first two tables below, if you know the number of bytes per word and the number of words per block, you can calculate the number of bits per word, the number of bytes per block, and the number of bits per block.

On symbols: I’ve always thought that obscure symbols were an evil ruse on the part of mathematicians to make simple concepts difficult to understand. So I’ve tried to use mnemonic symbols as best I can here. Everything is uppercase except b (for bits) and B (for bytes), a common convention. I used a lowercase L in PBl because there were no more variants on the latin letter 'B' for distinguishing among bits, bytes, and blocks, and I didn’t want to go the evil mathematician route by introducing a letter from some other alphabet.

Also, I used the term “primary memory” as the basis for the symbols that refer to what is commonly called “main memory” to avoid confusion with the prefix letter M used for Mega.

Primary Memory Capacity

Capacity can be measured in bits, bytes, words, or blocks.
BitsPbtotal capacity, in bits
BytesPBtotal capacity, in bytes
WordsPWtotal capacity, in words
BlocksPBltotal capacity, in bocks
Capacity Ratios
Pb ÷ PBbits per byte: always 8
PB ÷ PWbytes per word
PW ÷ PBlwords per block

Number of Primary Memory Address bits is A.

A = log2(PB) for byte addressable memory

A = log2(PW) for word addressable memory

Cache Capacity

BitsCbcache capacity, in bits
BytesCBcache capacity, in bytes
WordsCWcache capacity, in words
LinesCLnumber of cache lines
SetsCSnumber of cache sets
Ratios
Cb ÷ CBSame as Pb ÷ PB (8)
CB ÷ CWSame as PB ÷ PW
CW ÷ CLSame as PW ÷ PBl
CL ÷ CSSet Size (n)
Set Size = Lines per Set (n)
n == 1Direct Mapped
n == CLFully Associative
1 < n < CLn-way Set Associative

Bit fields in a Primary Memory address, from left-to-right

[ tag | index | block or line offset | byte offset ]

Total number of bits is A, the number of Primary Memory Address bits.

A == tag + index + block or line offset + byte offset

Cache parameters are always powers of two, so log2(whatever) is always an integer. No need to use ceil(log2(whatever)).