// ECE3055a lab4.c Effect of data-cache-miss ratio and penalty // To compile into "lab4", "gcc lab4.c -o lab4" // To print a Table of Values, type lab4 x at the command prompt // To put output into a file for Excel, "./lab4 x > myfile.csv" #include #include #include main(int argc, char * argv[ ]) { unsigned long i, j ; // array indices float mpc[21][4] ; // Multi-cycle datapath cycles, 21 values of DCMR, 4 of CMP float plc[21][4] ; // Pipelined datapath cycles float mpr[21][4] ; // Ratio, mpc/plc (speed-up ratio) float spn ; // sum of pi*ni - normal multicycle average C/I float bmrp = 0.5 ; // branch prediction sucess (0.5) times penalty (1) float imr = 0.02 ; // Instruction miss ratio float p[4], n[4], dcmr[21], cmp[4] ; p[0] = 0.1 ; // Branch probability (frequency) p[1] = 0.2 ; // Load probability p[2] = 0.1 ; // Store probability p[3] = 0.6 ; // Other probability n[0] = 3 ; // Normal cycles for Branch (no cache misses) n[1] = 5 ; // Normal cycles for Load n[2] = 4 ; // Normal cycles for Store n[3] = 4 ; // Normal cycles for Other spn = 0 ; for(i = 0 ; i <= 3 ; i++) spn += EQUATION MISSING ; // normal cycles dcmr[0] = 0 ; // data-cache-miss ratio values for(i = 1 ; i <= 20 ; i++) dcmr[i] = dcmr[i-1] + 0.01 ; cmp[0] = 5 ; // data-cache-miss ratio values cmp[1] = 12 ; cmp[2] = 20 ; cmp[3] = 50 ; if(argc > 1 ) { // if no command line argument, print table printf(" DCMR - Cache Miss Penalty (Cycles) -\n") ; printf(" CMP=") ; for( j = 0 ; j <= 3 ; j++ ) printf("\t%6.1f", cmp[j] ) ; printf("\n") ; // print two header lines for output for(i = 0 ; i <= 20 ; i++) { // loop over dcmr (miss ratio) values printf("%6.3f", dcmr[i] ) ; // print dcmr value and tab (column 1) for( j = 0 ; j <= 3 ; j++ ) { // loop over cmp (penalty) values mpc[i][j] = ; // Equation missing plc[i][j] = ; // Equation missing mpr[i][j] = mpc[i][j] / plc[i][j] ; printf("\t%6.3f", mpr[i][j] ) ; // print mpr value and tab } printf("\n") ; // print "new line" character to end line } } else { // if there is no command line augument, ask for values float x, y ; // float variables printf("\nTo print a Table of Values, type 'lab4 x' at the command prompt\n\n"); printf(" Type Value of Data-Cache-Miss Ratio (0-1)\n ") ; scanf("%f", &x ) ; printf(" Type Value of Cache-Miss Penalty (cycles)\n") ; scanf("%f", &y ) ; i = j = 1 ; mpc[i][j] = ; // Equation missing plc[i][j] = ; // Equation missing mpr[i][j] = mpc[i][j] / plc[i][j] ; printf("\n *** The Speed-Up Ratio is %6.3f\n\n", mpr[i][j] ) ; // print mpr value } } // end of main()