static void analyze() { double xval[MAXCNT]; double yval[MAXCNT]; double slope, intercept; double dtime; int n; int i; /* Create entries */ for (i = 0; intel[i].name; i++) { xval[i] = intel[i].year - intel[0].year; yval[i] = log10(intel[i].trans); } n = i-1; printf("Got %d values\n", n); for (i = 0; i < n; i++) printf("x = %f, y = %f\n", xval[i], yval[i]); slope = ls_slope(xval, yval, n); intercept = ls_intercept(xval, yval, n); printf("annual growth rate = %.4f\n", pow(10, slope)); printf("intercept at year %d = %.2f\n", (int) intel[0].year, pow(10,intercept)); dtime = 0.3010/slope; printf("Doubling time = %.2f years (%.1f months)\n", dtime, dtime*12); for (i = 0; i < n; i++) { printf("Year = %d, predicted %d, got %d\n", (int) intel[i].year, (int) pow(10, intercept+xval[i]*slope), (int) intel[i].trans); } exit(0); }
/* Find absolute performance */ void find_abs_performance(double *intercept, double *slope, int clear_cache, int verbose, int cpubench) { int min_param = 1; int pcount = 10; int i; /* Try to get precise measurements at max_params points */ double *xval = calloc(pcount, sizeof(double)); double *yval = calloc(pcount, sizeof(double)); for (i = 0; i < pcount; i++) { xval[i] = i+min_param; if (cpubench) yval[i] = fcyc_full(cpufunct, i+min_param, clear_cache, 3, 0.00000, 1000, 0); else yval[i] = fcyc_full(funct, i+min_param, clear_cache, 3, 0.00000, 1000, 0); } /* Now perform least squares fit */ *intercept = ls_intercept(xval, yval, pcount); *slope = ls_slope(xval, yval, pcount); if (verbose) { double avg_err = ls_error(xval, yval, pcount, LS_AVG); double max_err = ls_error(xval, yval, pcount, LS_MAX); printf("Slope = %0.1f, Intercept = %.1f, max err = %f, avg err = %f\n", *slope, *intercept, max_err, avg_err); } }
/* Find cpe for function f, which allows cnt up to maxcnt, using specified number of sample points. If data_file, then print data so that can plot points with Excel smethod determines method for generating samples */ double find_cpe_full(elem_fun_t f, int maxcnt, int samples, FILE *data_file, sample_t smethod, double bias, int verbose) { int i; int cnt; double cpe; double overhead = 0.0; double *cnt_val = calloc(samples, sizeof(double)); double *cycle_val = calloc(samples, sizeof(double)); /* Do the samples */ srandom(SEED); for (i = 0; i < samples; i++) { cnt = get_cnt(i, samples, maxcnt, smethod, bias); cnt_val[i] = cnt; cycle_val[i] = measure_function(f, cnt); } /* Fit data */ cpe = ls_slope(cnt_val, cycle_val, samples); if (data_file) overhead = ls_intercept(cnt_val, cycle_val, samples); if (data_file && verbose) { /* Print x values */ fprintf(data_file, "Cnt\t0"); for (i = 0; i < samples; i++) fprintf(data_file, "\t%.0f", cnt_val[i]); fprintf(data_file, "\n"); /* Print y values */ fprintf(data_file, "Cycs.\t"); for (i = 0; i < samples; i++) fprintf(data_file, "\t%.2f", cycle_val[i]); fprintf(data_file, "\n"); #if 0 /* Print (y-b)/x values */ fprintf(data_file, "CPE"); for (i = 0; i < samples; i++) fprintf(data_file, "\t%.2f", (cycle_val[i]-overhead)/cnt_val[i]); fprintf(data_file, "\n"); #endif /* Print ax*b values */ fprintf(data_file, "Interp.\t%.2f", overhead); for (i = 0; i < samples; i++) fprintf(data_file, "\t%.2f", cpe*cnt_val[i]+overhead); fprintf(data_file, "\n"); } if (data_file && verbose) { /* Print results */ fprintf(data_file, "cpe\t%.2f\tovhd\t%.2f\tavgerr\t\%.3f\tmaxerr\t\%.3f\n", cpe, overhead, ls_error(cnt_val, cycle_val, samples, LS_AVG), ls_error(cnt_val, cycle_val, samples, LS_MAX)); } free(cnt_val); free(cycle_val); return cpe; }