1
$\begingroup$

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).

$\endgroup$
2
  • $\begingroup$ It seems they imply 4-byte words, so 16 KiB is 4096 words and "second 2" probably is logb(4) $\endgroup$
    – Bulat
    Commented Apr 10, 2019 at 22:12
  • $\begingroup$ See cs.stackexchange.com/a/43876 $\endgroup$
    – Ran G.
    Commented Apr 20, 2019 at 15:37

1 Answer 1

1
$\begingroup$

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).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.