source: rtems/testsuites/benchmarks/whetstone/whetstone.c

Last change on this file was ee63681a, checked in by Sebastian Huber <sebastian.huber@…>, on 09/22/23 at 12:14:14

tests: Add header for RTEMS test printer

The <rtems/test-info.h> header file is required for every RTEMS test
program. Move the RTEMS test printer support to a dedicated header file
<rtems/test-printer.h>. This removes an unnecessary dependency to the
RTEMS printer support in <rtems/test-info.h>.

Tests using the RTEMS Testing Framework no longer depend on the
<rtems/printer.h>.

  • Property mode set to 100644
File size: 8.2 KB
Line 
1/*
2 * C Converted Whetstone Double Precision Benchmark
3 *              Version 1.2     22 March 1998
4 *
5 *      (c) Copyright 1998 Painter Engineering, Inc.
6 *              All Rights Reserved.
7 *
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.
12 *
13 * Converted by Rich Painter, Painter Engineering, Inc. based on the
14 * www.netlib.org benchmark/whetstoned version obtained 16 March 1998.
15 *
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.
24 *
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.
28 *
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.
35 *
36 * Questions and comments may be directed to the author at
37 *                      r.painter@ieee.org
38 */
39/*
40C**********************************************************************
41C     Benchmark #2 -- Double  Precision Whetstone (A001)
42C
43C     o This is a REAL*8 version of
44C       the Whetstone benchmark program.
45C
46C     o DO-loop semantics are ANSI-66 compatible.
47C
48C     o Final measurements are to be made with all
49C       WRITE statements and FORMAT sttements removed.
50C
51C**********************************************************************   
52*/
53
54/* standard C library headers required */
55#include <stdlib.h>
56#include <stdio.h>
57#include <string.h>
58#include <math.h>
59#ifdef __rtems__
60#include <rtems/test-printer.h>
61#define fprintf(f, ...) rtems_printf(&rtems_test_printer, __VA_ARGS__)
62#endif /* __rtems__ */
63
64/* the following is optional depending on the timing function used */
65#include <sys/time.h>
66
67/* map the FORTRAN math functions, etc. to the C versions */
68#define DSIN    sin
69#define DCOS    cos
70#define DATAN   atan
71#define DLOG    log
72#define DEXP    exp
73#define DSQRT   sqrt
74#define IF              if
75
76/* function prototypes */
77void POUT(long N, long J, long K, double X1, double X2, double X3, double X4);
78void PA(double E[]);
79void P0(void);
80void P3(double X, double Y, double *Z);
81#define USAGE   "usage: whetdc [-c] [loops]\n"
82
83/*
84        COMMON T,T1,T2,E1(4),J,K,L
85*/
86double T,T1,T2,E1[5];
87int J,K,L;
88
89static double
90Time(void)
91{
92        struct timeval tv;
93
94        gettimeofday(&tv, NULL);
95        return (double)tv.tv_sec + (double)tv.tv_usec * 1e-6;
96}
97
98int
99main(int argc, char *argv[])
100{
101        /* used in the FORTRAN version */
102        long I;
103        long N1, N2, N3, N4, N6, N7, N8, N9, N10, N11;
104        double X1,X2,X3,X4,X,Y,Z;
105        long LOOP;
106        int II, JJ;
107
108        /* added for this version */
109        long loopstart;
110        double startsec, finisec;
111        double KIPS;
112        int continuous;
113
114        loopstart = 1000;               /* see the note about LOOP below */
115        continuous = 0;
116
117        II = 1;         /* start at the first arg (temp use of II here) */
118        while (II < argc) {
119                if (strncmp(argv[II], "-c", 2) == 0 || argv[II][0] == 'c') {
120                        continuous = 1;
121                } else if (atol(argv[II]) > 0) {
122                        loopstart = atol(argv[II]);
123                } else {
124                        fprintf(stderr, USAGE);
125                        return(1);
126                }
127                II++;
128        }
129
130LCONT:
131/*
132C
133C       Start benchmark timing at this point.
134C
135*/
136        startsec = Time();
137
138/*
139C
140C       The actual benchmark starts here.
141C
142*/
143        T  = .499975;
144        T1 = 0.50025;
145        T2 = 2.0;
146/*
147C
148C       With loopcount LOOP=10, one million Whetstone instructions
149C       will be executed in EACH MAJOR LOOP..A MAJOR LOOP IS EXECUTED
150C       'II' TIMES TO INCREASE WALL-CLOCK TIMING ACCURACY.
151C
152        LOOP = 1000;
153*/
154        LOOP = loopstart;
155        II   = 1;
156
157        JJ = 1;
158
159IILOOP:
160        N1  = 0;
161        N2  = 12 * LOOP;
162        N3  = 14 * LOOP;
163        N4  = 345 * LOOP;
164        N6  = 210 * LOOP;
165        N7  = 32 * LOOP;
166        N8  = 899 * LOOP;
167        N9  = 616 * LOOP;
168        N10 = 0;
169        N11 = 93 * LOOP;
170/*
171C
172C       Module 1: Simple identifiers
173C
174*/
175        X1  =  1.0;
176        X2  = -1.0;
177        X3  = -1.0;
178        X4  = -1.0;
179
180        for (I = 1; I <= N1; I++) {
181            X1 = (X1 + X2 + X3 - X4) * T;
182            X2 = (X1 + X2 - X3 + X4) * T;
183            X3 = (X1 - X2 + X3 + X4) * T;
184            X4 = (-X1+ X2 + X3 + X4) * T;
185        }
186#ifdef PRINTOUT
187        IF (JJ==II)POUT(N1,N1,N1,X1,X2,X3,X4);
188#endif
189
190/*
191C
192C       Module 2: Array elements
193C
194*/
195        E1[1] =  1.0;
196        E1[2] = -1.0;
197        E1[3] = -1.0;
198        E1[4] = -1.0;
199
200        for (I = 1; I <= N2; I++) {
201            E1[1] = ( E1[1] + E1[2] + E1[3] - E1[4]) * T;
202            E1[2] = ( E1[1] + E1[2] - E1[3] + E1[4]) * T;
203            E1[3] = ( E1[1] - E1[2] + E1[3] + E1[4]) * T;
204            E1[4] = (-E1[1] + E1[2] + E1[3] + E1[4]) * T;
205        }
206
207#ifdef PRINTOUT
208        IF (JJ==II)POUT(N2,N3,N2,E1[1],E1[2],E1[3],E1[4]);
209#endif
210
211/*
212C
213C       Module 3: Array as parameter
214C
215*/
216        for (I = 1; I <= N3; I++)
217                PA(E1);
218
219#ifdef PRINTOUT
220        IF (JJ==II)POUT(N3,N2,N2,E1[1],E1[2],E1[3],E1[4]);
221#endif
222
223/*
224C
225C       Module 4: Conditional jumps
226C
227*/
228        J = 1;
229        for (I = 1; I <= N4; I++) {
230                if (J == 1)
231                        J = 2;
232                else
233                        J = 3;
234
235                if (J > 2)
236                        J = 0;
237                else
238                        J = 1;
239
240                if (J < 1)
241                        J = 1;
242                else
243                        J = 0;
244        }
245
246#ifdef PRINTOUT
247        IF (JJ==II)POUT(N4,J,J,X1,X2,X3,X4);
248#endif
249
250/*
251C
252C       Module 5: Omitted
253C       Module 6: Integer arithmetic
254C
255*/
256
257        J = 1;
258        K = 2;
259        L = 3;
260
261        for (I = 1; I <= N6; I++) {
262            J = J * (K-J) * (L-K);
263            K = L * K - (L-J) * K;
264            L = (L-K) * (K+J);
265            E1[L-1] = J + K + L;
266            E1[K-1] = J * K * L;
267        }
268
269#ifdef PRINTOUT
270        IF (JJ==II)POUT(N6,J,K,E1[1],E1[2],E1[3],E1[4]);
271#endif
272
273/*
274C
275C       Module 7: Trigonometric functions
276C
277*/
278        X = 0.5;
279        Y = 0.5;
280
281        for (I = 1; I <= N7; I++) {
282                X = T * DATAN(T2*DSIN(X)*DCOS(X)/(DCOS(X+Y)+DCOS(X-Y)-1.0));
283                Y = T * DATAN(T2*DSIN(Y)*DCOS(Y)/(DCOS(X+Y)+DCOS(X-Y)-1.0));
284        }
285
286#ifdef PRINTOUT
287        IF (JJ==II)POUT(N7,J,K,X,X,Y,Y);
288#endif
289
290/*
291C
292C       Module 8: Procedure calls
293C
294*/
295        X = 1.0;
296        Y = 1.0;
297        Z = 1.0;
298
299        for (I = 1; I <= N8; I++)
300                P3(X,Y,&Z);
301
302#ifdef PRINTOUT
303        IF (JJ==II)POUT(N8,J,K,X,Y,Z,Z);
304#endif
305
306/*
307C
308C       Module 9: Array references
309C
310*/
311        J = 1;
312        K = 2;
313        L = 3;
314        E1[1] = 1.0;
315        E1[2] = 2.0;
316        E1[3] = 3.0;
317
318        for (I = 1; I <= N9; I++)
319                P0();
320
321#ifdef PRINTOUT
322        IF (JJ==II)POUT(N9,J,K,E1[1],E1[2],E1[3],E1[4]);
323#endif
324
325/*
326C
327C       Module 10: Integer arithmetic
328C
329*/
330        J = 2;
331        K = 3;
332
333        for (I = 1; I <= N10; I++) {
334            J = J + K;
335            K = J + K;
336            J = K - J;
337            K = K - J - J;
338        }
339
340#ifdef PRINTOUT
341        IF (JJ==II)POUT(N10,J,K,X1,X2,X3,X4);
342#endif
343
344/*
345C
346C       Module 11: Standard functions
347C
348*/
349        X = 0.75;
350
351        for (I = 1; I <= N11; I++)
352                X = DSQRT(DEXP(DLOG(X)/T1));
353
354#ifdef PRINTOUT
355        IF (JJ==II)POUT(N11,J,K,X,X,X,X);
356#endif
357
358/*
359C
360C      THIS IS THE END OF THE MAJOR LOOP.
361C
362*/
363        if (++JJ <= II)
364                goto IILOOP;
365
366/*
367C
368C      Stop benchmark timing at this point.
369C
370*/
371        finisec = Time();
372
373/*
374C----------------------------------------------------------------
375C      Performance in Whetstone KIP's per second is given by
376C
377C       (100*LOOP*II)/TIME
378C
379C      where TIME is in seconds.
380C--------------------------------------------------------------------
381*/
382        printf("\n");
383        if (finisec-startsec <= 0) {
384                printf("Insufficient duration- Increase the LOOP count\n");
385                return(1);
386        }
387
388        printf("Loops: %ld, Iterations: %d, Duration: %f sec.\n",
389                        LOOP, II, finisec-startsec);
390
391        KIPS = (100.0*LOOP*II)/(finisec-startsec);
392        if (KIPS >= 1000.0)
393                printf("C Converted Double Precision Whetstones: %.1f MIPS\n", KIPS/1000.0);
394        else
395                printf("C Converted Double Precision Whetstones: %.1f KIPS\n", KIPS);
396
397        if (continuous)
398                goto LCONT;
399
400        return(0);
401}
402
403void
404PA(double E[])
405{
406        J = 0;
407
408L10:
409        E[1] = ( E[1] + E[2] + E[3] - E[4]) * T;
410        E[2] = ( E[1] + E[2] - E[3] + E[4]) * T;
411        E[3] = ( E[1] - E[2] + E[3] + E[4]) * T;
412        E[4] = (-E[1] + E[2] + E[3] + E[4]) / T2;
413        J += 1;
414
415        if (J < 6)
416                goto L10;
417}
418
419void
420P0(void)
421{
422        E1[J] = E1[K];
423        E1[K] = E1[L];
424        E1[L] = E1[J];
425}
426
427void
428P3(double X, double Y, double *Z)
429{
430        double X1, Y1;
431
432        X1 = X;
433        Y1 = Y;
434        X1 = T * (X1 + Y1);
435        Y1 = T * (X1 + Y1);
436        *Z  = (X1 + Y1) / T2;
437}
438
439#ifdef PRINTOUT
440void
441POUT(long N, long J, long K, double X1, double X2, double X3, double X4)
442{
443        printf("%7ld %7ld %7ld %12.4e %12.4e %12.4e %12.4e\n",
444                                                N, J, K, X1, X2, X3, X4);
445}
446#endif
Note: See TracBrowser for help on using the repository browser.