Winter ’19 CIS 314 Assignment 7 – 100/100 points – Due Friday, 3/15, 11:59 PM
Please submit individual source files for coding exercises (see naming conventions below) and a single solution document for non-coding exercises (.txt or .pdf only). Your code and answers need to be documented to the point that the graders can understand your thought process. Full credit will not be awarded if sufficient work is not shown.
1. [40] Consider the following C code:
struct ColorPoint {
long a;
long r;
long g;
long b;
};
struct ColorPoint points[16][16];
Also consider a 128B cache, comprised of a single cache block. Assume the following:
• sizeof(long) == 8.
• points begins at memory address 0.
• The cache is initially empty.
• The only memory accesses are to the entries of the array points. Variables i, j, and sum
are stored in registers (see code below).
A. (20) Consider the following C code, in the context of the assumptions above:
long sum = 0;
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
sum += points[i][j].a;
sum += points[i][j].r;
sum += points[i][j].g;
sum += points[i][j].b;
} }
What is the miss rate of the cache when running this code? Answer it terms of misses/(hits + misses).
B. (20) Consider the following C code, in the context of the assumptions above:
long sum = 0;
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
sum += points[j][i].a;
sum += points[j][i].r;
sum += points[j][i].g;
sum += points[j][i].b;
}
}
What is the miss rate of the cache when running this code? Answer it terms of misses/(hits + misses).
Hint: Memory is row major and cache blocks are contiguous regions of memory (see chapter 6.2-6.3).
Write and describe your answers in your solutions document.
2 [60] Assume that we’re going to simulate a 256B cache with 16B blocks and 16 sets (i.e., direct mapped) for a 32-bit architecture. Write a C program with the following functions, using only bitwise ops for the arithmetic (no division or modulo operators):
• (15) unsigned int getOffset(unsigned int address) – returns the byte offset of the address within its cache block.
• (15) unsigned int getSet(unsigned int address) – returns the cache set for the address.
• (15) unsigned int getTag(unsigned int address) – returns the cache tag for the address.
• (15) A main() function to test your functions.
Here are some test runs:
0x12345678: offset: 8 - tag: 123456 - set: 7
0x87654321: offset: 1 - tag: 876543 - set: 2
Name your source file 7-2.c.
Zip the source files and solution document (if applicable), name the .zip file