Cache Memory · Computer Organization and Architecture
68 questions · asked in 25 of 27 years (2000–2026)
MCQ 44 · MSQ 4 · NAT 201-mark 30 · 2-mark 38
2000Questions per year2026
Questions 56–60 of 68
A CPU has a 32 KB direct mapped cache with 128-byte block size. Suppose A is a twodimensional array of size 512x512 with elements that occupy 8-bytes each. Consider the following two C code segments, P1 and P2.
The value of ratio is:
P1:
for (i=0; i<512; i++) {
for (j=0; j<512; j++) {
x += A[i][j];
}
}
P2:
for (i=0; i<512; i++) {
for (j=0; j<512; j++) {
x += A[j][i];
}
} P1 and P2 are executed independently with the same initial state, namely, the array A is not in the cache and i, j, x are in registers. Let the number of cache misses experienced by P1 be M1 and that for P2 be M2 . The value of ratio is:
Answer: (B)
The array has elements of 8 bytes. A block has 128 bytes, so it holds elements. The cache has lines. C stores the array in row-major order, so one row is bytes (32 blocks).
P1 reads the array in memory order. One miss brings in 16 elements, and the next 15 reads hit. So .
P2 reads down a column. One column touches 512 different blocks, which is more than the 256 lines. Each step down moves 4096 bytes, so consecutive blocks differ by 32 in block number and only different lines are used. So a block is replaced long before the next column needs its other 15 elements. Every access misses: .
Answer: (B)
P1 reads the array in memory order. One miss brings in 16 elements, and the next 15 reads hit. So .
P2 reads down a column. One column touches 512 different blocks, which is more than the 256 lines. Each step down moves 4096 bytes, so consecutive blocks differ by 32 in block number and only different lines are used. So a block is replaced long before the next column needs its other 15 elements. Every access misses: .
Answer: (B)
A CPU has a 32 KB direct mapped cache with 128-byte block size. Suppose A is a twodimensional array of size 512x512 with elements that occupy 8-bytes each. Consider the following two C code segments, P1 and P2.
The value of M1 is:
P1:
for (i=0; i<512; i++) {
for (j=0; j<512; j++) {
x += A[i][j];
}
}
P2:
for (i=0; i<512; i++) {
for (j=0; j<512; j++) {
x += A[j][i];
}
} P1 and P2 are executed independently with the same initial state, namely, the array A is not in the cache and i, j, x are in registers. Let the number of cache misses experienced by P1 be M1 and that for P2 be M2 . The value of M1 is:
Answer: (C)
C stores a 2-D array in row-major order, and P1 reads it in that same order.
A block has 128 bytes and an element has 8 bytes, so one block holds elements. The first read of a block misses and brings in all 16 elements, so the next 15 reads hit. A block is never needed again after its 16 elements are read, so there are no other misses.
Number of elements .
Answer: (C)
A block has 128 bytes and an element has 8 bytes, so one block holds elements. The first read of a block misses and brings in all 16 elements, so the next 15 reads hit. A block is never needed again after its 16 elements are read, so there are no other misses.
Number of elements .
Answer: (C)
Consider two cache organizations: The first one is 32 KB 2-way set associative with 32-byte block size. The second one is of the same size but direct mapped. The size of an address is 32 bits in both cases. A 2-to-1 multiplexer has a latency of 0.6 ns while a kbit comparator has a latency of k/10 ns. The hit latency of the set associative organization is h1 while that of the direct mapped one is h2.
The value of h2 is:
The value of h2 is:
Answer: (D)
Direct mapped cache: number of blocks , and each block is its own set. So the index has 10 bits.
The block has 32 bytes, so the offset has 5 bits.
Tag bits .
On a hit, only one block can match, so the 17-bit tag comparator is the only delay. There is no way to choose between blocks, so no 2-to-1 multiplexer is needed.
Answer: (D)
The block has 32 bytes, so the offset has 5 bits.
Tag bits .
On a hit, only one block can match, so the 17-bit tag comparator is the only delay. There is no way to choose between blocks, so no 2-to-1 multiplexer is needed.
Answer: (D)
Consider two cache organizations: The first one is 32 KB 2-way set associative with 32-byte block size. The second one is of the same size but direct mapped. The size of an address is 32 bits in both cases. A 2-to-1 multiplexer has a latency of 0.6 ns while a kbit comparator has a latency of k/10 ns. The hit latency of the set associative organization is h1 while that of the direct mapped one is h2.
The value of h1 is:
The value of h1 is:
Answer: (A)
Number of sets , so the index has 9 bits.
The block has 32 bytes, so the offset has 5 bits.
Tag bits .
In a 2-way cache, the tags of both blocks in the set are compared at the same time, using two 18-bit comparators. This takes . Then a 2-to-1 multiplexer picks the data of the way that matched, which takes 0.6 ns.
Answer: (A)
The block has 32 bytes, so the offset has 5 bits.
Tag bits .
In a 2-way cache, the tags of both blocks in the set are compared at the same time, using two 18-bit comparators. This takes . Then a 2-to-1 multiplexer picks the data of the way that matched, which takes 0.6 ns.
Answer: (A)
A CPU generates 32-bit virtual addresses. The page size is 4 KB. The processor has a translation look-aside buffer (TLB) which can hold a total of 128 page table entries and is 4-way set associative. The minimum size of the TLB tag is
Answer: (C)
The page number has 32 12 = 20 bits.
Number of TLB sets = 128 / 4 = 32 so 5 index bits are needed.
Tag size = 20 5 = 15 bits
Answer: 15 bits
Number of TLB sets = 128 / 4 = 32 so 5 index bits are needed.
Tag size = 20 5 = 15 bits
Answer: 15 bits
Keep practising