1
/* @(#)cwhetstone.c 19.1 (ES0-DMD) 02/25/03 14:35:41 */
2
/*===========================================================================
3
Copyright (C) 1995 European Southern Observatory (ESO)
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License as
7
published by the Free Software Foundation; either version 2 of
8
the License, or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public
16
License along with this program; if not, write to the Free
17
Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
20
Corresponding concerning ESO-MIDAS should be addressed as follows:
21
Internet e-mail: midas@eso.org
22
Postal address: European Southern Observatory
23
Data Management Division
24
Karl-Schwarzschild-Strasse 2
25
D 85748 Garching bei Muenchen
27
===========================================================================*/
29
/* @(#)cwhetstone.c 6.1.1.1 (ESO-IPG) 7/16/93 20:39:05 */
31
* Whetstone benchmark in C. This program is a translation of the
32
* original Algol version in "A Synthetic Benchmark" by H.J. Curnow
33
* and B.A. Wichman in Computer Journal, Vol 19 #1, February 1976.
35
* Used to test compiler optimization and floating point performance.
37
* Compile by: cc -O -o whet whet.c -lm
40
#define ITERATIONS 1000 /* 100 Million Whetstone instructions */
47
double x1, x2, x3, x4, x, y, z, t, t1, t2;
49
int i, j, k, l, n1, n2, n3, n4, n6, n7, n8, n9, n10, n11;
56
/* initialize constants */
62
/* set values of module weights */
67
n4 = 345 * ITERATIONS;
68
n6 = 210 * ITERATIONS;
70
n8 = 899 * ITERATIONS;
71
n9 = 616 * ITERATIONS;
73
n11 = 93 * ITERATIONS;
75
/* MODULE 1: simple identifiers */
80
for(i = 1; i <= n1; i += 1) {
81
x1 = ( x1 + x2 + x3 - x4 ) * t;
82
x2 = ( x1 + x2 - x3 - x4 ) * t;
83
x3 = ( x1 - x2 + x3 + x4 ) * t;
84
x4 = (-x1 + x2 + x3 + x4 ) * t;
88
/* MODULE 2: array elements */
91
e1[1] = e1[2] = e1[3] = -1.0;
93
for (i = 1; i <= n2; i +=1) {
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;
100
/* MODULE 3: array as parameter */
102
for (i = 1; i <= n3; i += 1)
105
/* MODULE 4: conditional jumps */
108
for (i = 1; i <= n4; i += 1) {
125
/* MODULE 5: omitted */
127
/* MODULE 6: integer arithmetic */
133
for (i = 1; i <= n6; i += 1) {
134
j = j * (k - j) * (l -k);
135
k = l * k - (l - j) * k;
136
l = (l - k) * (k + j);
138
e1[l - 2] = j + k + l; /* C arrays are zero based */
139
e1[k - 2] = j * k * l;
142
/* MODULE 7: trig. functions */
146
for(i = 1; i <= n7; i +=1) {
147
x = t * atan(t2*sin(x)*cos(x)/(cos(x+y)+cos(x-y)-1.0));
148
y = t * atan(t2*sin(y)*cos(y)/(cos(x+y)+cos(x-y)-1.0));
151
/* MODULE 8: procedure calls */
155
for (i = 1; i <= n8; i +=1)
158
/* MODULE9: array references */
168
for(i = 1; i <= n9; i += 1)
171
/* MODULE10: integer arithmetic */
176
for(i = 1; i <= n10; i +=1) {
183
/* MODULE11: standard functions */
186
for(i = 1; i <= n11; i +=1)
187
x = sqrt( exp( log(x) / t1));
191
printf ("Whetstone MIPS = %f\n", ITERATIONS/((time1-time0)*10.0));
202
e[0] = ( e[0] + e[1] + e[2] - e[3] ) * t;
203
e[1] = ( e[0] + e[1] - e[2] + e[3] ) * t;
204
e[2] = ( e[0] - e[1] + e[2] + e[3] ) * t;
205
e[3] = ( -e[0] + e[1] + e[2] + e[3] ) / t2;