home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / BENCHMARKS / whet.c < prev    next >
C/C++ Source or Header  |  2009-11-06  |  4KB  |  229 lines

  1. /*     transcription errors fixed by drf 4 may 1987 also Nov. 1988
  2.      revised version - 280ct81
  3.      author - H.J. Curnow, CCTA, 01-211 8633
  4.      This version can be run on machines with limited range
  5.      of values for the loop control limit and counter.
  6.      Data values are ii and jj. The limitations on
  7.      the values of ii are the same as for i in the old
  8.      version (see IS internal memo 5101/13).
  9.      The weight of the program is now (ii+jj)/10
  10.      million Whetstones (+overhead)
  11. **
  12.      "If a change in time is T seconds for a change in the product
  13.      ii*jj of 10 then the speed is 1000/T thousands of Whetstone
  14.      instructions per second (kWi/s)."
  15. **
  16.      For more information on this program see "A Synthetic Benchmark"
  17.      by H.J. Curnow and B.A. Wichman in The Computer Journal vol. 19
  18.      no. 1 (Feb. 1976.)
  19. **
  20.      This program has been transcribed and slightly modified
  21.      by Daniel Feenberg.  The modifications do not affect the
  22.      timings but allow precision conversion with only an
  23.      implicit statement.  The output format is also slightly
  24.      different. An open statement is also present.
  25.  
  26. */
  27. # include <stdio.h>
  28. # include <math.h>
  29. #include <setsys.h>
  30. #include <time.h>
  31.  
  32.  
  33. float t,t1,t2,e1[4];
  34. int  j,k,l;
  35. int ii;
  36. int jj;
  37.  
  38. int loop,kount;
  39. unsigned long start_t, end_t;
  40. double secs;
  41.  
  42. main()        /* whetstone Benchmark */
  43. {
  44.     float x1,x2,x3,x4,x,y,z,ww;
  45.     int   n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,nn;
  46.     register int i;
  47.  
  48.     ii = 10;
  49.     jj = 10;
  50.     printf("Starting Whetstone benchmark\n");
  51.  
  52.     nn = ii * jj;
  53.     ww = nn * 10.0;
  54.     t = .499975;
  55.     t1 = .50025;
  56.     t2 = 2.0;
  57.  
  58.     n1=0;
  59.     n2=12*ii;
  60.     n3=14*ii;
  61.     n4=345*ii;
  62.     n5=0;
  63.     n6=210*ii;
  64.     n7=32*ii;
  65.     n8=899*ii;
  66.     n9=616*ii;
  67.     n10=0;
  68.     n11=93*ii;
  69.     n12=0;
  70.     loop = 0;
  71.     kount = 0;
  72.     start_t = clock(); 
  73.     do
  74.         {
  75.         x1=1.0;
  76.         x2=(-1.);
  77.         x3=(-1.);
  78.         x4=(-1.);
  79.         if(n1 > 0)
  80.             for (i = 1; i <= n1; i++)
  81.             {
  82.             x1 = (x1+x2+x3-x4)*t;
  83.             x2 = (x1+x2-x3+x4)*t;
  84.             x3 = (x1-x2+x3+x4)*t;
  85.             x4 = (-x1+x2+x3+x4)*t;
  86.             }
  87.         e1[0]= 1.0;
  88.         e1[1]=(-1.0);
  89.         e1[2]=(-1.0);
  90.         e1[3]=(-1.0);
  91.         if(n2 > 0)
  92.             for (i = 1; i <= n2; i++)
  93.             {
  94.             e1[0]=(e1[0]+e1[1]+e1[2]-e1[3])*t;
  95.             e1[1]=(e1[0]+e1[1]-e1[2]+e1[3])*t;
  96.             e1[2]=(e1[0]-e1[1]+e1[2]+e1[3])*t;
  97.             e1[3]=(-e1[0]+e1[1]+e1[2]+e1[3])*t;
  98.             }
  99.         if(n3 > 0) 
  100.             for (i = 1; i <= n3; i++)
  101.             {
  102.             pa(e1);
  103.             }
  104.         j=1;
  105.         if(n4 > 0)
  106.             for (i = 1; i <= n4; i++)
  107.             {
  108.             if(j-1 == 0)
  109.                 j=2;
  110.             else
  111.                 j=3;
  112.             if(j-2 > 0)
  113.                 j=0;
  114.             else
  115.                 j=1;
  116.             if(j-1 < 0)
  117.                 j=1;
  118.             else
  119.                 j=0;
  120.             }
  121.         j=1;
  122.         k=2;
  123.         l=3;
  124.         if(n6 > 0)
  125.             for (i = 1; i <= n6; i++)
  126.             {
  127.             j=j*(k-j)*(l-k);
  128.             k=l*k-(l-j)*k;
  129.             l=(l-k)*(k+j);
  130.             e1[l-1]=j+k+l;
  131.             e1[k-1]=j*k*l;
  132.             }
  133.         x=.5;
  134.         y=.5;
  135.         if(n7 > 0)
  136.             for (i = 1; i <= n7; i++)
  137.             {
  138.             x=t*atan(t2*sin(x)*cos(x)/(cos(x+y)+cos(x-y)-1.));
  139.             y=t*atan(t2*sin(y)*cos(y)/(cos(x+y)+cos(x-y)-1.));
  140.             }
  141.         x=1.;
  142.         y=1.;
  143.         z=1.;
  144.         if(n8 > 0)
  145.             for (i = 1; i <= n8; i++)
  146.             {
  147.             p3(x,y,z);
  148.             }
  149.         j=1;
  150.         k=2;
  151.         l=3;
  152.         e1[0]=1.;
  153.         e1[1]=2.;
  154.         e1[2]=3.;
  155.         if(n9 > 0)
  156.             for (i = 1; i <= n9; i++)
  157.             {
  158.             p0();
  159.             }
  160.         j=2;
  161.         k=3;
  162.         if(n10 > 0)
  163.             for (i = 1; i <= n10; i++)
  164.             {
  165.             j=j+k;
  166.             k=j+k;
  167.             j=j-k;
  168.             k=k-j-j;
  169.             }
  170.         x=.75;
  171.         if(n11 > 0)
  172.             for (i = 1; i <=n11; i++)
  173.             {
  174.             x=sqrt(exp(log(x)/t1));
  175.             }
  176.     kount += 1;
  177.     loop = loop+ii;
  178.     }while(kount < jj);
  179.     end_t = clock(); 
  180.     printf("start = %d end = %d ticks = %d\n",start_t,end_t,CLK_TCK);
  181.     secs = (double)(end_t - start_t) / (double)CLK_TCK;
  182.     printf("Seconds = %5.2f\n",secs);
  183.     printf("KWI/S = %12.3f\n",((ww * 1000.0) / secs));
  184.     pout();
  185. }
  186.  
  187. pa(e)
  188. float    e[4];
  189. {
  190.     for (j = 0; j < 6; j++)
  191.     {
  192.         e[0]=(e[0]+e[1]+e[2]-e[3])*t;
  193.         e[0]=(e[0]+e[1]-e[2]+e[3])*t;
  194.         e[0]=(e[0]-e[1]+e[2]+e[3])*t;
  195.         e[0]=(-e[0]+e[1]+e[2]+e[3])*t;
  196.     }
  197. }
  198.  
  199. p0()
  200. {
  201.  
  202.     e1[j]=e1[k];
  203.     e1[k]=e1[l];
  204.     e1[l]=e1[j];
  205. }
  206.  
  207. p3(x,y,z)
  208. float    x,y,z;
  209. {
  210.     float x1,y1;
  211.  
  212.     x1=x;
  213.     y1=y;
  214.     x1=t*(x1+y1);
  215.     y1=t*(x1+y1);
  216.     z=(x1+y1)/t2;
  217. }
  218.  
  219. pout(n,j,k,x1,x2,x3,x4)
  220. int    n,j,k;
  221. float    x1,x2,x3,x4;
  222. {
  223.     printf("/*%2d,%2d,%2d,\t%10.4f,\t%10.4f,\t%10.4f,\t%10.4f*/\n",
  224.         n,j,k,x1,x2,x3,x4);
  225.     printf("{ %2d,%2d,%2d,\t0x%08x,\t0x%08x,\t0x%08x,\t0x%08x},\n",
  226.         n,j,k,
  227.         *((int *)&x1),*((int *)&x2),*((int *)&x3),*((int *)&x4));
  228. }
  229.