Hackfix and re-enable strtoull and wcstoull, see bug #3798.
[sdcc.git] / sdcc-extra / historygraphs / whetstone-z80 / whetstone.c
blob6cc190d18ef4a2ed5322cc623ce248d61b96fc5e
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 clock(void);
64 /* map the FORTRAN math functions, etc. to the C versions */
65 #define DSIN sinf
66 #define DCOS cosf
67 #define DATAN atanf
68 #define DLOG logf
69 #define DEXP expf
70 #define DSQRT sqrtf
71 #define IF if
73 /* function prototypes */
74 void POUT(long N, long J, long K, double X1, double X2, double X3, double X4);
75 void PA(double E[]);
76 void P0(void);
77 void P3(double X, double Y, double *Z);
78 #define USAGE "usage: whetdc [-c] [loops]\n"
81 COMMON T,T1,T2,E1(4),J,K,L
83 double T,T1,T2,E1[5];
84 int J,K,L;
86 int
87 main(int argc, char *argv[])
89 /* used in the FORTRAN version */
90 long I;
91 long N1, N2, N3, N4, N6, N7, N8, N9, N10, N11;
92 double X1,X2,X3,X4,X,Y,Z;
93 long LOOP;
94 int II, JJ;
96 /* added for this version */
97 long startmsec, finimsec;
98 float KIPS;
99 int continuous;
101 continuous = 0;
103 init();
104 LCONT:
107 C Start benchmark timing at this point.
110 startmsec = clock();
114 C The actual benchmark starts here.
117 T = .499975;
118 T1 = 0.50025;
119 T2 = 2.0;
122 C With loopcount LOOP=10, one million Whetstone instructions
123 C will be executed in EACH MAJOR LOOP..A MAJOR LOOP IS EXECUTED
124 C 'II' TIMES TO INCREASE WALL-CLOCK TIMING ACCURACY.
126 LOOP = 1000;
128 LOOP = 10;
129 II = 1;
131 JJ = 1;
133 IILOOP:
134 N1 = 0;
135 N2 = 12 * LOOP;
136 N3 = 14 * LOOP;
137 N4 = 345 * LOOP;
138 N6 = 210 * LOOP;
139 N7 = 32 * LOOP;
140 N8 = 899 * LOOP;
141 N9 = 616 * LOOP;
142 N10 = 0;
143 N11 = 93 * LOOP;
146 C Module 1: Simple identifiers
149 X1 = 1.0;
150 X2 = -1.0;
151 X3 = -1.0;
152 X4 = -1.0;
154 for (I = 1; I <= N1; I++) {
155 X1 = (X1 + X2 + X3 - X4) * T;
156 X2 = (X1 + X2 - X3 + X4) * T;
157 X3 = (X1 - X2 + X3 + X4) * T;
158 X4 = (-X1+ X2 + X3 + X4) * T;
160 #ifdef PRINTOUT
161 IF (JJ==II)POUT(N1,N1,N1,X1,X2,X3,X4);
162 #endif
166 C Module 2: Array elements
169 E1[1] = 1.0;
170 E1[2] = -1.0;
171 E1[3] = -1.0;
172 E1[4] = -1.0;
174 for (I = 1; I <= N2; I++) {
175 E1[1] = ( E1[1] + E1[2] + E1[3] - E1[4]) * T;
176 E1[2] = ( E1[1] + E1[2] - E1[3] + E1[4]) * T;
177 E1[3] = ( E1[1] - E1[2] + E1[3] + E1[4]) * T;
178 E1[4] = (-E1[1] + E1[2] + E1[3] + E1[4]) * T;
181 #ifdef PRINTOUT
182 IF (JJ==II)POUT(N2,N3,N2,E1[1],E1[2],E1[3],E1[4]);
183 #endif
187 C Module 3: Array as parameter
190 for (I = 1; I <= N3; I++)
191 PA(E1);
193 #ifdef PRINTOUT
194 IF (JJ==II)POUT(N3,N2,N2,E1[1],E1[2],E1[3],E1[4]);
195 #endif
199 C Module 4: Conditional jumps
202 J = 1;
203 for (I = 1; I <= N4; I++) {
204 if (J == 1)
205 J = 2;
206 else
207 J = 3;
209 if (J > 2)
210 J = 0;
211 else
212 J = 1;
214 if (J < 1)
215 J = 1;
216 else
217 J = 0;
220 #ifdef PRINTOUT
221 IF (JJ==II)POUT(N4,J,J,X1,X2,X3,X4);
222 #endif
226 C Module 5: Omitted
227 C Module 6: Integer arithmetic
231 J = 1;
232 K = 2;
233 L = 3;
235 for (I = 1; I <= N6; I++) {
236 J = J * (K-J) * (L-K);
237 K = L * K - (L-J) * K;
238 L = (L-K) * (K+J);
239 E1[L-1] = J + K + L;
240 E1[K-1] = J * K * L;
243 #ifdef PRINTOUT
244 IF (JJ==II)POUT(N6,J,K,E1[1],E1[2],E1[3],E1[4]);
245 #endif
249 C Module 7: Trigonometric functions
252 X = 0.5;
253 Y = 0.5;
255 for (I = 1; I <= N7; I++) {
256 X = T * DATAN(T2*DSIN(X)*DCOS(X)/(DCOS(X+Y)+DCOS(X-Y)-1.0));
257 Y = T * DATAN(T2*DSIN(Y)*DCOS(Y)/(DCOS(X+Y)+DCOS(X-Y)-1.0));
260 #ifdef PRINTOUT
261 IF (JJ==II)POUT(N7,J,K,X,X,Y,Y);
262 #endif
266 C Module 8: Procedure calls
269 X = 1.0;
270 Y = 1.0;
271 Z = 1.0;
273 for (I = 1; I <= N8; I++)
274 P3(X,Y,&Z);
276 #ifdef PRINTOUT
277 IF (JJ==II)POUT(N8,J,K,X,Y,Z,Z);
278 #endif
282 C Module 9: Array references
285 J = 1;
286 K = 2;
287 L = 3;
288 E1[1] = 1.0;
289 E1[2] = 2.0;
290 E1[3] = 3.0;
292 for (I = 1; I <= N9; I++)
293 P0();
295 #ifdef PRINTOUT
296 IF (JJ==II)POUT(N9,J,K,E1[1],E1[2],E1[3],E1[4]);
297 #endif
301 C Module 10: Integer arithmetic
304 J = 2;
305 K = 3;
307 for (I = 1; I <= N10; I++) {
308 J = J + K;
309 K = J + K;
310 J = K - J;
311 K = K - J - J;
314 #ifdef PRINTOUT
315 IF (JJ==II)POUT(N10,J,K,X1,X2,X3,X4);
316 #endif
320 C Module 11: Standard functions
323 X = 0.75;
325 for (I = 1; I <= N11; I++)
326 X = DSQRT(DEXP(DLOG(X)/T1));
328 #ifdef PRINTOUT
329 IF (JJ==II)POUT(N11,J,K,X,X,X,X);
330 #endif
334 C THIS IS THE END OF THE MAJOR LOOP.
337 if (++JJ <= II)
338 goto IILOOP;
342 C Stop benchmark timing at this point.
345 finimsec = clock();
348 C----------------------------------------------------------------
349 C Performance in Whetstone KIP's per second is given by
351 C (100*LOOP*II)/TIME
353 C where TIME is in seconds.
354 C--------------------------------------------------------------------
356 printf("\n");
357 if (finimsec-startmsec <= 0) {
358 printf("Insufficient duration- Increase the LOOP count\n");
359 return(1);
362 printf("Loops: %ld, Iterations: %d, Duration: %ld msec.\n",
363 LOOP, II, finimsec-startmsec);
365 KIPS = (100.0*LOOP*II)/((float)(finimsec-startmsec)/1000.0f);
366 if (KIPS >= 1000.0)
367 printf("C Converted Double Precision Whetstones: %.1f MIPS\n", KIPS/1000.0);
368 else
369 printf("C Converted Double Precision Whetstones: %.1f KIPS\n", KIPS);
370 printf ("\x04");
371 if (continuous)
372 goto LCONT;
374 return(0);
377 void
378 PA(double E[])
380 J = 0;
382 L10:
383 E[1] = ( E[1] + E[2] + E[3] - E[4]) * T;
384 E[2] = ( E[1] + E[2] - E[3] + E[4]) * T;
385 E[3] = ( E[1] - E[2] + E[3] + E[4]) * T;
386 E[4] = (-E[1] + E[2] + E[3] + E[4]) / T2;
387 J += 1;
389 if (J < 6)
390 goto L10;
393 void
394 P0(void)
396 E1[J] = E1[K];
397 E1[K] = E1[L];
398 E1[L] = E1[J];
401 void
402 P3(double X, double Y, double *Z)
404 double X1, Y1;
406 X1 = X;
407 Y1 = Y;
408 X1 = T * (X1 + Y1);
409 Y1 = T * (X1 + Y1);
410 *Z = (X1 + Y1) / T2;
413 #ifdef PRINTOUT
414 void
415 POUT(long N, long J, long K, double X1, double X2, double X3, double X4)
417 printf("%7ld %7ld %7ld %12.4e %12.4e %12.4e %12.4e\n",
418 N, J, K, X1, X2, X3, X4);
420 #endif