struct / union in initializer, RFE #901.
[sdcc.git] / sdcc-extra / historygraphs / whetstone-mcs51 / whetstone.c
blobd3ff63d3f2515fdcf209b1bf7151768497563a17
1 /*
2 * C Converted Whetstone Double Precision Benchmark
3 * Version 1.2 22 March 1998
5 * (c) Copyright 1998 Painter Engineering, Inc.
6 * All Rights Reserved.
8 * Permission is granted to use, duplicate, and
9 * publish this text and program as long as it
10 * includes this entire comment block and limited
11 * rights reference.
13 * Converted by Rich Painter, Painter Engineering, Inc. based on the
14 * www.netlib.org benchmark/whetstoned version obtained 16 March 1998.
16 * A novel approach was used here to keep the look and feel of the
17 * FORTRAN version. Altering the FORTRAN-based array indices,
18 * starting at element 1, to start at element 0 for C, would require
19 * numerous changes, including decrementing the variable indices by 1.
20 * Instead, the array E1[] was declared 1 element larger in C. This
21 * allows the FORTRAN index range to function without any literal or
22 * variable indices changes. The array element E1[0] is simply never
23 * used and does not alter the benchmark results.
25 * The major FORTRAN comment blocks were retained to minimize
26 * differences between versions. Modules N5 and N12, like in the
27 * FORTRAN version, have been eliminated here.
29 * An optional command-line argument has been provided [-c] to
30 * offer continuous repetition of the entire benchmark.
31 * An optional argument for setting an alternate LOOP count is also
32 * provided. Define PRINTOUT to cause the POUT() function to print
33 * outputs at various stages. Final timing measurements should be
34 * made with the PRINTOUT undefined.
36 * Questions and comments may be directed to the author at
37 * r.painter@ieee.org
40 C**********************************************************************
41 C Benchmark #2 -- Double Precision Whetstone (A001)
43 C o This is a REAL*8 version of
44 C the Whetstone benchmark program.
46 C o DO-loop semantics are ANSI-66 compatible.
48 C o Final measurements are to be made with all
49 C WRITE statements and FORMAT sttements removed.
51 C**********************************************************************
54 /* standard C library headers required */
55 #include <stdlib.h>
56 #include <stdio.h>
57 #include <string.h>
58 #include <math.h>
60 /* the following is optional depending on the timing function used */
61 void init(void);
62 unsigned long int clock(void);
63 void clockinc(void) __interrupt(1);
65 /* map the FORTRAN math functions, etc. to the C versions */
66 #define DSIN sinf
67 #define DCOS cosf
68 #define DATAN atanf
69 #define DLOG logf
70 #define DEXP expf
71 #define DSQRT sqrtf
72 #define IF if
74 /* function prototypes */
75 void POUT(long N, long J, long K, double X1, double X2, double X3, double X4);
76 void PA(double E[]);
77 void P0(void);
78 void P3(double X, double Y, double *Z);
79 #define USAGE "usage: whetdc [-c] [loops]\n"
82 COMMON T,T1,T2,E1(4),J,K,L
84 double T,T1,T2,E1[5];
85 int J,K,L;
87 int
88 main(int argc, char *argv[])
90 /* used in the FORTRAN version */
91 long I;
92 long N1, N2, N3, N4, N6, N7, N8, N9, N10, N11;
93 double X1,X2,X3,X4,X,Y,Z;
94 long LOOP;
95 int II, JJ;
97 /* added for this version */
98 long startmsec, finimsec;
99 float KIPS;
100 int continuous;
102 continuous = 0;
104 init();
105 LCONT:
108 C Start benchmark timing at this point.
111 startmsec = clock();
115 C The actual benchmark starts here.
118 T = .499975;
119 T1 = 0.50025;
120 T2 = 2.0;
123 C With loopcount LOOP=10, one million Whetstone instructions
124 C will be executed in EACH MAJOR LOOP..A MAJOR LOOP IS EXECUTED
125 C 'II' TIMES TO INCREASE WALL-CLOCK TIMING ACCURACY.
127 LOOP = 1000;
129 LOOP = 10;
130 II = 1;
132 JJ = 1;
134 IILOOP:
135 N1 = 0;
136 N2 = 12 * LOOP;
137 N3 = 14 * LOOP;
138 N4 = 345 * LOOP;
139 N6 = 210 * LOOP;
140 N7 = 32 * LOOP;
141 N8 = 899 * LOOP;
142 N9 = 616 * LOOP;
143 N10 = 0;
144 N11 = 93 * LOOP;
147 C Module 1: Simple identifiers
150 X1 = 1.0;
151 X2 = -1.0;
152 X3 = -1.0;
153 X4 = -1.0;
155 for (I = 1; I <= N1; I++) {
156 X1 = (X1 + X2 + X3 - X4) * T;
157 X2 = (X1 + X2 - X3 + X4) * T;
158 X3 = (X1 - X2 + X3 + X4) * T;
159 X4 = (-X1+ X2 + X3 + X4) * T;
161 #ifdef PRINTOUT
162 IF (JJ==II)POUT(N1,N1,N1,X1,X2,X3,X4);
163 #endif
167 C Module 2: Array elements
170 E1[1] = 1.0;
171 E1[2] = -1.0;
172 E1[3] = -1.0;
173 E1[4] = -1.0;
175 for (I = 1; I <= N2; I++) {
176 E1[1] = ( E1[1] + E1[2] + E1[3] - E1[4]) * T;
177 E1[2] = ( E1[1] + E1[2] - E1[3] + E1[4]) * T;
178 E1[3] = ( E1[1] - E1[2] + E1[3] + E1[4]) * T;
179 E1[4] = (-E1[1] + E1[2] + E1[3] + E1[4]) * T;
182 #ifdef PRINTOUT
183 IF (JJ==II)POUT(N2,N3,N2,E1[1],E1[2],E1[3],E1[4]);
184 #endif
188 C Module 3: Array as parameter
191 for (I = 1; I <= N3; I++)
192 PA(E1);
194 #ifdef PRINTOUT
195 IF (JJ==II)POUT(N3,N2,N2,E1[1],E1[2],E1[3],E1[4]);
196 #endif
200 C Module 4: Conditional jumps
203 J = 1;
204 for (I = 1; I <= N4; I++) {
205 if (J == 1)
206 J = 2;
207 else
208 J = 3;
210 if (J > 2)
211 J = 0;
212 else
213 J = 1;
215 if (J < 1)
216 J = 1;
217 else
218 J = 0;
221 #ifdef PRINTOUT
222 IF (JJ==II)POUT(N4,J,J,X1,X2,X3,X4);
223 #endif
227 C Module 5: Omitted
228 C Module 6: Integer arithmetic
232 J = 1;
233 K = 2;
234 L = 3;
236 for (I = 1; I <= N6; I++) {
237 J = J * (K-J) * (L-K);
238 K = L * K - (L-J) * K;
239 L = (L-K) * (K+J);
240 E1[L-1] = J + K + L;
241 E1[K-1] = J * K * L;
244 #ifdef PRINTOUT
245 IF (JJ==II)POUT(N6,J,K,E1[1],E1[2],E1[3],E1[4]);
246 #endif
250 C Module 7: Trigonometric functions
253 X = 0.5;
254 Y = 0.5;
256 for (I = 1; I <= N7; I++) {
257 X = T * DATAN(T2*DSIN(X)*DCOS(X)/(DCOS(X+Y)+DCOS(X-Y)-1.0));
258 Y = T * DATAN(T2*DSIN(Y)*DCOS(Y)/(DCOS(X+Y)+DCOS(X-Y)-1.0));
261 #ifdef PRINTOUT
262 IF (JJ==II)POUT(N7,J,K,X,X,Y,Y);
263 #endif
267 C Module 8: Procedure calls
270 X = 1.0;
271 Y = 1.0;
272 Z = 1.0;
274 for (I = 1; I <= N8; I++)
275 P3(X,Y,&Z);
277 #ifdef PRINTOUT
278 IF (JJ==II)POUT(N8,J,K,X,Y,Z,Z);
279 #endif
283 C Module 9: Array references
286 J = 1;
287 K = 2;
288 L = 3;
289 E1[1] = 1.0;
290 E1[2] = 2.0;
291 E1[3] = 3.0;
293 for (I = 1; I <= N9; I++)
294 P0();
296 #ifdef PRINTOUT
297 IF (JJ==II)POUT(N9,J,K,E1[1],E1[2],E1[3],E1[4]);
298 #endif
302 C Module 10: Integer arithmetic
305 J = 2;
306 K = 3;
308 for (I = 1; I <= N10; I++) {
309 J = J + K;
310 K = J + K;
311 J = K - J;
312 K = K - J - J;
315 #ifdef PRINTOUT
316 IF (JJ==II)POUT(N10,J,K,X1,X2,X3,X4);
317 #endif
321 C Module 11: Standard functions
324 X = 0.75;
326 for (I = 1; I <= N11; I++)
327 X = DSQRT(DEXP(DLOG(X)/T1));
329 #ifdef PRINTOUT
330 IF (JJ==II)POUT(N11,J,K,X,X,X,X);
331 #endif
335 C THIS IS THE END OF THE MAJOR LOOP.
338 if (++JJ <= II)
339 goto IILOOP;
343 C Stop benchmark timing at this point.
346 finimsec = clock();
349 C----------------------------------------------------------------
350 C Performance in Whetstone KIP's per second is given by
352 C (100*LOOP*II)/TIME
354 C where TIME is in seconds.
355 C--------------------------------------------------------------------
357 printf("\n");
358 if (finimsec-startmsec <= 0) {
359 printf("Insufficient duration- Increase the LOOP count\n");
360 return(1);
363 printf("Loops: %ld, Iterations: %d, Duration: %ld msec.\n",
364 LOOP, II, finimsec-startmsec);
366 KIPS = (100.0*LOOP*II)/((float)(finimsec-startmsec)/1000.0f);
367 if (KIPS >= 1000.0)
368 printf("C Converted Double Precision Whetstones: %.1f MIPS\n", KIPS/1000.0);
369 else
370 printf("C Converted Double Precision Whetstones: %.1f KIPS\n", KIPS);
372 if (continuous)
373 goto LCONT;
375 return(0);
378 void
379 PA(double E[])
381 J = 0;
383 L10:
384 E[1] = ( E[1] + E[2] + E[3] - E[4]) * T;
385 E[2] = ( E[1] + E[2] - E[3] + E[4]) * T;
386 E[3] = ( E[1] - E[2] + E[3] + E[4]) * T;
387 E[4] = (-E[1] + E[2] + E[3] + E[4]) / T2;
388 J += 1;
390 if (J < 6)
391 goto L10;
394 void
395 P0(void)
397 E1[J] = E1[K];
398 E1[K] = E1[L];
399 E1[L] = E1[J];
402 void
403 P3(double X, double Y, double *Z)
405 double X1, Y1;
407 X1 = X;
408 Y1 = Y;
409 X1 = T * (X1 + Y1);
410 Y1 = T * (X1 + Y1);
411 *Z = (X1 + Y1) / T2;
414 #ifdef PRINTOUT
415 void
416 POUT(long N, long J, long K, double X1, double X2, double X3, double X4)
418 printf("%7ld %7ld %7ld %12.4e %12.4e %12.4e %12.4e\n",
419 N, J, K, X1, X2, X3, X4);
421 #endif