~ubuntu-branches/debian/jessie/eso-midas/jessie

« back to all changes in this revision

Viewing changes to util/bench/cwhetstone/cwhetstone.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* @(#)cwhetstone.c     19.1 (ES0-DMD) 02/25/03 14:35:41 */
 
2
/*===========================================================================
 
3
  Copyright (C) 1995 European Southern Observatory (ESO)
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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, 
 
18
  MA 02139, USA.
 
19
 
 
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 
 
26
                        GERMANY
 
27
===========================================================================*/
 
28
 
 
29
/* @(#)cwhetstone.c     6.1.1.1 (ESO-IPG) 7/16/93 20:39:05 */
 
30
/*
 
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.
 
34
 *
 
35
 *      Used to test compiler optimization and floating point performance.
 
36
 *
 
37
 *      Compile by:             cc -O -o whet whet.c -lm
 
38
 */
 
39
 
 
40
#define ITERATIONS      1000 /* 100 Million Whetstone instructions */
 
41
 
 
42
/*
 
43
#include "fastmath.h"
 
44
 */
 
45
#include <math.h>
 
46
 
 
47
double          x1, x2, x3, x4, x, y, z, t, t1, t2;
 
48
double          e1[4];
 
49
int             i, j, k, l, n1, n2, n3, n4, n6, n7, n8, n9, n10, n11;
 
50
long            time0, time1;
 
51
 
 
52
main()
 
53
{
 
54
        time(&time0);
 
55
 
 
56
        /* initialize constants */
 
57
 
 
58
        t   =   0.499975;
 
59
        t1  =   0.50025;
 
60
        t2  =   2.0;
 
61
 
 
62
        /* set values of module weights */
 
63
 
 
64
        n1  =   0 * ITERATIONS;
 
65
        n2  =  12 * ITERATIONS;
 
66
        n3  =  14 * ITERATIONS;
 
67
        n4  = 345 * ITERATIONS;
 
68
        n6  = 210 * ITERATIONS;
 
69
        n7  =  32 * ITERATIONS;
 
70
        n8  = 899 * ITERATIONS;
 
71
        n9  = 616 * ITERATIONS;
 
72
        n10 =   0 * ITERATIONS;
 
73
        n11 =  93 * ITERATIONS;
 
74
 
 
75
/* MODULE 1:  simple identifiers */
 
76
 
 
77
        x1 =  1.0;
 
78
        x2 = x3 = x4 = -1.0;
 
79
 
 
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;
 
85
        }
 
86
 
 
87
 
 
88
/* MODULE 2:  array elements */
 
89
 
 
90
        e1[0] =  1.0;
 
91
        e1[1] = e1[2] = e1[3] = -1.0;
 
92
 
 
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;
 
98
        }
 
99
 
 
100
/* MODULE 3:  array as parameter */
 
101
 
 
102
        for (i = 1; i <= n3; i += 1)
 
103
                pa(e1);
 
104
 
 
105
/* MODULE 4:  conditional jumps */
 
106
 
 
107
        j = 1;
 
108
        for (i = 1; i <= n4; i += 1) {
 
109
                if (j == 1)
 
110
                        j = 2;
 
111
                else
 
112
                        j = 3;
 
113
 
 
114
                if (j > 2)
 
115
                        j = 0;
 
116
                else
 
117
                        j = 1;
 
118
 
 
119
                if (j < 1 )
 
120
                        j = 1;
 
121
                else
 
122
                        j = 0;
 
123
        }
 
124
 
 
125
/* MODULE 5:  omitted */
 
126
 
 
127
/* MODULE 6:  integer arithmetic */
 
128
 
 
129
        j = 1;
 
130
        k = 2;
 
131
        l = 3;
 
132
 
 
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);
 
137
 
 
138
                e1[l - 2] = j + k + l;          /* C arrays are zero based */
 
139
                e1[k - 2] = j * k * l;
 
140
        }
 
141
 
 
142
/* MODULE 7:  trig. functions */
 
143
 
 
144
        x = y = 0.5;
 
145
 
 
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));
 
149
        }
 
150
 
 
151
/* MODULE 8:  procedure calls */
 
152
 
 
153
        x = y = z = 1.0;
 
154
 
 
155
        for (i = 1; i <= n8; i +=1)
 
156
                p3(x, y, &z);
 
157
 
 
158
/* MODULE9:  array references */
 
159
 
 
160
        j = 1;
 
161
        k = 2;
 
162
        l = 3;
 
163
 
 
164
        e1[0] = 1.0;
 
165
        e1[1] = 2.0;
 
166
        e1[2] = 3.0;
 
167
 
 
168
        for(i = 1; i <= n9; i += 1)
 
169
                p0();
 
170
 
 
171
/* MODULE10:  integer arithmetic */
 
172
 
 
173
        j = 2;
 
174
        k = 3;
 
175
 
 
176
        for(i = 1; i <= n10; i +=1) {
 
177
                j = j + k;
 
178
                k = j + k;
 
179
                j = k - j;
 
180
                k = k - j - j;
 
181
        }
 
182
 
 
183
/* MODULE11:  standard functions */
 
184
 
 
185
        x = 0.75;
 
186
        for(i = 1; i <= n11; i +=1)
 
187
                x = sqrt( exp( log(x) / t1));
 
188
 
 
189
        time(&time1);
 
190
 
 
191
        printf ("Whetstone MIPS = %f\n", ITERATIONS/((time1-time0)*10.0));
 
192
        exit(0);
 
193
}
 
194
 
 
195
pa(e)
 
196
double e[4];
 
197
{
 
198
        register int j;
 
199
 
 
200
        j = 0;
 
201
     lab:
 
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;
 
206
        j += 1;
 
207
        if (j < 6)
 
208
                goto lab;
 
209
}
 
210
 
 
211
 
 
212
p3(x, y, z)
 
213
double x, y, *z;
 
214
{
 
215
        x  = t * (x + y);
 
216
        y  = t * (x + y);
 
217
        *z = (x + y) /t2;
 
218
}
 
219
 
 
220
 
 
221
p0()
 
222
{
 
223
        e1[j] = e1[k];
 
224
        e1[k] = e1[l];
 
225
        e1[l] = e1[j];
 
226
}