/* Test setup for polynomial evaluation. Do not change this. */ #include #include #include //#include #include "poly.h" #include "cpe.h" #include "clock.h" #include double CPU_Mhz; /* Degree for fixed evaluation */ #define FIXDEGREE 10 /* Largest degree polynomial tested */ #define MAXDEGREE 2000 static int coeff[MAXDEGREE+1]; #define MAX_ITER_COUNT 100 #define REF_CPU_MHZ 2292.6 // �����ҵĴ�������Ƶ /* Define performance standards */ static struct { double cref; /* Cycles taken by reference solution */ double cbest; /* Cycles taken by our best implementation */ } cstandard[3] = {{4.00, 1.75}, /* CPE */ {50, 43}, /* C(10) */ {57,31} /* ��ϵ������ʽ���� */ }; int coeff_const[4]; /* Should I print extra information? */ int verbose = 0; /* Standard value for polynomial evaluation */ static int xval; /* How many degrees should I compute reference value for? */ #define DCNT 20 /* Correct value of polynomial evaluation for range of different degrees */ /* pval[i] contains evaluation for degree MAXDEGREE-i */ static int pval[DCNT]; /* fixval contains evaluation for degree FIXDEGREE */ static int fixval; static int fixval_const; static void init_const_poly(void); static void init(void); extern int const_poly_eval(int *not_use, int not_use2, int x); void run_fun_const(int degree); static double compute_score(double cmeas, double cref, double cbest); unsigned long rand1_h,rand1_l,rand_div; void rand_step(unsigned long divv); void GenerateRandomNumber(unsigned long divv); extern void make_CPU_busy(void); double run_poly_perf_test(void); /* Reference implementation */ static int ref_poly_eval(int *a, int degree, int x) { int result = 0; int i; int xpwr = 1; /* Successive powers of x */ for (i = 0; i <= degree; i++) { result += a[i]*xpwr; xpwr *= x; } return result; } /* Initialize polynomial to constant values and compute reference values */ static void init_const_poly(void) { int i; for (i=0;i<4;i++) { GenerateRandomNumber(90); coeff_const[i] = rand_div+10; } printf("����Ҫ�޸�poly.c��const_poly_eval������ʵ������ij�������ʽ���㣡\n"); printf("\tresult=%d+%d*x+%d*x^2+%d*x^3\n",coeff_const[0],coeff_const[1],coeff_const[2],coeff_const[3]); fixval_const = ref_poly_eval(coeff_const, 3, xval); // printf("x=%d, fixval_const=%d\n",xval,fixval_const); } void test_const_poly(void) { int i; double fix_time=0; int my_cal = const_poly_eval(coeff_const, 3, xval); if (fixval_const != my_cal) { printf("��ϵ������ʽ����const_poly_evalʵ�ִ���x=%d����Ԥ�ڽ����%d�����Ǽ���õ�����%d\n",xval,fixval_const,my_cal); exit(0); } fix_time = 0; for (i=0;i 1.1*(sbest-1)+1) return 120; return 100*((smeas-1.0)/(sbest-1.0) + 0.1); } /* ����һ��0~divv-1֮����������ͬʱ������������� */ void GenerateRandomNumber(unsigned long divv) { unsigned long long x = rand1_h; x *= 0x6AC690C5; x += rand1_l; rand1_h = (unsigned long)x; rand1_l = (unsigned long)(x>>32); if (divv==0) return; rand_div = rand1_h % divv; } int main(int argc, char *argv[]) { int i; double cpe = cstandard[0].cref; double cfix = cstandard[1].cref; verbose = 0; srand((unsigned int)time(NULL)); // CPU_Factor(); // GetCpuClock(); printf("\t2015����ʽ�Ż�ʵ�飬��ӭ�㣡\n"); printf("============================\n"); if (argc == 1) { printf("ʹ�÷�����%s ѧ�ź�6λ [ѧ�ź�6λ] [ѧ�ź�6λ] ...\n",argv[0]); printf("����Ҫ������ʾ��дpoly.c����ʵ��һ����ϵ������ʽ�ļ��㣬�����ܿ�Ŷ....\n"); printf("���⣬����Ҫ��дpoly.c����ʵ������׵Ķ���ʽ�����10�׵Ķ���ʽ���㣬Ҫ�죡\n"); return 0; } /*����ѧ�ţ���ʼ��һ�������������*/ rand1_h = (unsigned long)atoi(argv[1]); rand1_l=0x29A; GenerateRandomNumber(0); for (i=2;i