From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <199609040648.GAA22339@moondance.np.ac.sg> Date: Wed, 4 Sep 1996 06:55:33 +0800 (SST) From: Robert Allen Barker Subject: Re: interesting benchmarks In-Reply-To: Nigel, Optimizing the code for Alpha I get the following: pentium-166 21164-500 Alpha MFLOPS ----------- --------- ------------ initial version 22.3 12.15 66 RISC version 28.0 1.70 470 RISC with multiply 28.0 1.11 720 There are two primary reasons for the apparent 'slowness' of the Alpha chip. 1) Alpha pays a heavy penalty for converting from int to double because, although it can do the conversion quickly, the floating point register must be stored in memory and then retrieved into an integer register. 2) the code has not been tailored to a RISC environment taking advantage of the pipelining. I tried rewriting the floating point version removing the conversion, putting everything into registers, and unrolling the loop a bit to four calculations per loop instead of one. I also made four seperate results c0 .. c3 to prevent the pipes from stalling while waiting for previous results. (these changes are quite common to RISC and 'super computer' loops) The difference between Alpha and intel becomes clear with the Alpha achieving 470 of its theoretical 500 MFLOPS for this code. In the last test I replaced the calculation with '*' instead of '-' which allows the Alpha to dual issue the floating point operations because they are now a mix of '*' and '-'. Alas, none of these optimizations can help the poor old pentium. This benchmark is an excellent example of the difference between a RISC processor and an intel type machine. Perhaps the best way to compare two different architectures is to optimize the code for each individually. ------------------------------------------------------------------------- #include #define MAXI 100 #define MAXJ 1000 #define MAXK 500 #define MAXKF 100 /*------------------------------------------------------------------------*/ main() { benchf(); benchf2(); /*benchi();*/ } /*------------------------------------------------------------------------*/ benchi() { int i, j, k; int a, b, c; for (i=0;i-MAXJ;j--) { b = a*j; for (k=MAXK;k>-MAXK;k--) { c = b + k; } } } printf("%d %d %d\n",a ,b, c); } /*------------------------------------------------------------------------*/ benchf() { int i, j, k; double a, b, c; for (i=0;i-MAXJ;j--) { b = a*(double)j; for (k=MAXKF;k>-MAXKF;k--) { c = b + (double)k; } } } printf("%f %f %f\n",a ,b, c); } /*------------------------------------------------------------------------*/ benchf2() { int i, j,k; double a, b, c0,c1,c2,c3; double kf0,kf1,kf2,kf3,one,four; one=1.00;four=4.0; for (i=0;i-MAXJ;j--) { b = a*(double)j; kf0=MAXKF; kf1=kf0-one; kf2=kf1-one; kf3=kf2-one; for (k=MAXKF;k>-MAXKF;k-=4) { c0 = b + kf0; kf0=kf0-four; c1 = b + kf1; kf1=kf1-four; c2 = b + kf2; kf2=kf2-four; c3 = b + kf3; kf3=kf3-four; } } } printf("%f %f %f\n",a ,b, c0+c1+c2+c3); /* I must print all 4 cxs or else the optimizer will remove some of the inner loop*/ } /*------------------------------------------------------------------------*/ -- To unsubscribe: mail -s unsubscribe axp-list-request@redhat.com < /dev/null