# Total bits required for a direct-mapped cache

I'm taking a course in computer architecture in which the main reference is the Computer Organization and Design by Patterson and Hennessy. I came across an example which I couldn't grasp its answer:

Example: how many total bits are required for a direct-mapped cache with 16 KiB of data and 4-word blocks, assuming a 32-bit address?

In the answer, it says "We know that 16 KiB is 4096 (2^12) words. With a block size of 4 words (2^2), there are 1024 (2^10) blocks".

But how do we know how many words would be 16 KiB?

And then it goes on and says the total bits are (number of blocks) * (data (32 * 4) + tag and validation bits). why don't we count index or offset bits in total bits?

And finally, it says the number of tag bits is (32 - 10 - 2 -2). we have 10 bits for the index part, 2 bits for offset, what're the second 2 bits we are subtracting from 32?

Honestly, I think I have missed something when studying the textbook, or there are some assumptions I'm missing.

BTW the answer according to the textbook is 147 Kibibits (18.4 KiB).

• It seems they imply 4-byte words, so 16 KiB is 4096 words and "second 2" probably is logb(4) Apr 10 '19 at 22:12
• Apr 20 '19 at 15:37

You have 16 kB = 16*1024 = 16384 bytes of data. Since word has 4 bytes, this makes 16384 bytes / 4 bytes per word = 4096 words . Block size is 4 words, that makes 4096 words/4 words per block = 1024 (2^10) blocks . This means 10 bits are used for the index. The size of the tag field is (assuming 32-bit address) 32-(n+m+2) where n is the number of bits used for the index, m is the number of bits used for the word within a block and 2 bits are used for the byte part of the address. So, in this example total number of bits = number of blocks * (number of bits per block + tag size + validation bit) = 2^10 * (4*32 + (32-10-2-2) + 1).