#include int main(int argc, char *argv[]) { /* the size of the cache in bytes */ int logsize = atoi(argv[1]); int size = 1 << logsize; /* the number of elements in table */ int m = size << 1; int associativity = atoi(argv[2]); /* how many iterations to make */ int n = 1 << 25; int *table = malloc(size * 8); int *tab0 = table; int *tab1 = table + (size >> 2); int *tab2 = table + 2 * (size >> 2); int *tab3 = table + 3 * (size >> 2); int *tab4 = table + 4 * (size >> 2); int *tab5 = table + 5 * (size >> 2); int *tab6 = table + 6 * (size >> 2); int *tab7 = table + 7 * (size >> 2); int sum = 0; int i, j; for(j = 0; j < m; j++) { table[j] = 0; } switch(associativity) { case 1: for(i = 0; i < n; i++) { sum += *tab0; sum += *tab0; sum += *tab0; sum += *tab0; sum += *tab0; sum += *tab0; sum += *tab0; sum += *tab0; } break; case 2: for(i = 0; i < n; i++) { sum += *tab0; sum += *tab0; sum += *tab0; sum += *tab0; sum += *tab1; sum += *tab1; sum += *tab1; sum += *tab1; } break; case 4: for(i = 0; i < n; i++) { sum += *tab0; sum += *tab0; sum += *tab1; sum += *tab1; sum += *tab2; sum += *tab2; sum += *tab3; sum += *tab3; } break; case 8: for(i = 0; i < n; i++) { sum += *tab0; sum += *tab1; sum += *tab2; sum += *tab3; sum += *tab4; sum += *tab5; sum += *tab6; sum += *tab7; } break; } return sum; }