How to calculate set associative cache size? - caching

A 32-bit processor has a two-way associative cache set that uses the 32 address bits as follows: 31-14 tags, 13-5 index, 4-0 offsets.
Calculate :
The size of the cache line in number of words
The total cache size in bits
I do not understand how to solve it, in my slides there is almost nothing on the set associative caches.
Solutions :
2^3 = 8 words (remaining 3 offset bits removed 2 bits for byte address)
2 * 2^9 * (1 + 18 + 8 * 2^5)
For 1 Shouldn't it be 2^(number of offset bits) so 2^5?
And for 2 what is the formula used?

The size of a word and the smallest entity addressable are not given. But, if we assume that addresses are byte oriented and that a word hold 4 bytes, there are 2^5 bytes/line and 2^3 words
2 * 2^9 * (1 + 18 + 8 * 2^5)
2 (number of ways/sets) * 2^9 (number of sets based on index)
* (1 (valid bit) + 18 (tag size) + 8 (bits/byte) * 2^5 (line size in bytes))

Related

Direct mapped cache example

i am really confused on the topic Direct Mapped Cache i've been looking around for an example with a good explanation and it's making me more confused then ever.
For example: I have
2048 byte memory
64 byte big cache
8 byte cache lines
with direct mapped cache how do i determine the 'LINE' 'TAG' and "Byte offset'?
i believe that the total number of addressing bits is 11 bits because 2048 = 2^11
2048/64 = 2^5 = 32 blocks (0 to 31) (5bits needed) (tag)
64/8 = 8 = 2^3 = 3 bits for the index
8 byte cache lines = 2^3 which means i need 3 bits for the byte offset
so the addres would be like this: 5 for the tag, 3 for the index and 3 for the byte offset
Do i have this figured out correctly?
Do i figured out correctly? YES
Explanation
1) Main memmory size is 2048 bytes = 211. So you need 11 bits to address a byte (If your word size is 1 byte) [word = smallest individual unit that will be accessed with the address]
2) You can calculating tag bits in direct mapping by doing (main memmory size / cash size). But i will explain a little more about tag bits.
Here the size of a cashe line( which is always same as size of a main memmory block) is 8 bytes. which is 23 bytes. So you need 3 bits to represent a byte within a cashe line. Now you have 8 bits (11 - 3) are remaining in the address.
Now the total number of lines present in the cache is (cashe size / line size) = 26 / 23 = 23
So, you have 3 bits to represent the line in which the your required byte is present.
The number of remaining bits now are 5 (8 - 3).
These 5 bits can be used to represent a tag. :)
3) 3 bit for index. If you were trying to label the number of bits needed to represent a line as index. Yes you are right.
4) 3 bits will be used to access a byte withing a cache line. (8 = 23)
So,
11 bits total address length = 5 tag bits + 3 bits to represent a line + 3 bits to represent a byte(word) withing a line
Hope there is no confusion now.

Calculating the total data+overhead of a set associative cache

This is a question from a Computer Architecture exam and I don't understand how to get to the correct answer.
Here is the question:
This question deals with main and cache memory only.
Address size: 32 bits
Block size: 128 items
Item size: 8 bits
Cache Layout: 6 way set associative
Cache Size: 192 KB (data only)
Write policy: Write Back
What is the total number of cache bits?
In order to get the number of tag bits, I find that 7 bits of the address are used for byte offset (0-127) and 8 bits are used for the block number (0-250) (250 = 192000/128/6), therefore 17 bits of the address are left for the tag.
To find the total number of bits in the cache, I would take (valid bit + tag size + bits per block) * number of blocks per set * number of sets = (1 + 17 + 1024) * 250 * 6 = 1,536,000. This is not the correct answer though.
The correct answer is 1,602,048 total bits in the cache and part of the answer is that there are 17 tag bits. After trying to reverse engineer the answer, I found that 1,602,048 = 1043 * 256 * 6 but I don't know if that is relevant to the solution because I don't know why those numbers would be used.
I'd like if someone could explain what I did wrong in my calculation to get a different answer.

MIPS N-way associative cache

This is a question about memory organization which I have had very difficulty to understand,
Assume we have an N-way set associative cache with the capacity 4096bytes. The
set field size of the address is 7 bits and the tag field 21 bits. If we assume that
the cache is used together with a 32-bit processor, what is then the block size (in
bytes), how many valid bits does the cache contain, and what is the associativity of
the cache?
Here are some equation that is good to know in order to solve question of these type.
Parameter to know
C = cache capacity
b = block size
B = number of blocks
N = degree of associativity
S = number of set
tag_bits
set_bits (also called index)
byte_offset
v = valid bits
Equations to know
B = C/b
S = B/N
b = 2^(byte_offset)
S = 2^(set_bits)
Memory Address
|___tag________|____set___|___byte offset_|
Now to the question
known:
C = 4096 bytes
set_bits = 7
tag_bits = 21
32 bits address field
Asked:
b?
N?
v?
Simply subtract the tag_bits and set_bits from the 32 bit field this gives you the byte_offset.
byte_offset = 32-21-7 = 4 bits
b = 2^4 = 16 bytes
S = 2^7 = 128 set
B = C/b = 4096/16 = 256
N = B/S = 256/128 = 2
v = B = 256 valid bits
So, we have the following information about the processor and the cache -
Cache Size = 4096 B
Address bits = 32
Index bits = 7
Tag bits = 21
From the above information you can quickly calculate the number of bits required for the offset field -
Offset bits = Address bits - Tag bits - Index bits
Offset bits = 32 - 21 - 7 = 4
Offset bits = 4
Using the offset bits, you can find the block size, 2**offset bits
Block Size = 16 bytes
Next thing is the associativity of the cache
We know that the index bits = 7.
This means we have 128 blocks. Each block is 16 bytes wide.
Therefore, the number of ways in the cache would be -
Number of ways = Cache Size / (number of blocks * block Size)
Number of ways = 2
Hence the associativity is 2.
Regarding the number of valid bits. Each block requires a valid bit. Hence the number of valid bits would be -
Valid bits = 128*2
Valid bits = 256

FAT filesystem: calculate the size and search a byte

I have this question in an Operating System test:
Given a disk of 1GB with 16KB blocks:
(1) Calculate the size of the File Allocation Table:
My Answer: since there are 2^16 blocks in the disk, we have a table with 2^16 entry, and every entry needs to store 16 bit (since there are 2^16 different blocks, we need 16 bit to identify each of them). So the size is 2^16 times 16 bit = 2^16 x 2^4 = 2^20 bit = 2^17 byte = 128Kb.
(2) Given the following table, indicate in which block are stored the following byte:
-byte 131080 of FileA starting at block 4.
-byte 62230 of FileB starting at block 3.
Entry Content
0 10
1 2
2 0
3 6
4 1
5 8
6 7
7 11
8 12
So FileA is (4) -> (1) -> (2) but the problem is: since every block is 16Kb = 2^4 x 2^10 byte = 2^14 byte = 16384 byte, block 4 contains from 1 to 16384, block 1 contains from 16385 to 32768, and block 2 from 32769 to 49152, where am I supposed to find the byte 131080???
Where is this wrong??

Identify set in 12MB 16-way L3 cache with 64B cache lines

The number of sets will be (12 * 2^20) / (16 * 2^6 ) = 3 * 2^12. Since the number of sets is not a power of two , how do the physical addresses map to the sets ?

Resources