| 1 |
/* |
| 2 |
PERMUTE_ARGS: -O |
| 3 |
TRANSFORM_OUTPUT: remove_lines("warning: sprintf\(\) is often misused") |
| 4 |
*/ |
| 5 |
|
| 6 |
/* |
| 7 |
WHETSTONE BENCHMARK PROGRAM |
| 8 |
|
| 9 |
This program uses a carefully chosen mix of instructions typical of |
| 10 |
scientific (floating point) calculations. |
| 11 |
|
| 12 |
See H.J. Curnow and B.A. Wichmann, |
| 13 |
"A Synthetic Benchmark", Computer J., V19 #1, Feb. 1976, pp. 43-49. |
| 14 |
|
| 15 |
Table of times for various computers in <info-ibmpc>whetst.answers |
| 16 |
compiled by Richard Gillmann (GILLMANN@ISIB) |
| 17 |
|
| 18 |
Whetstone Fortran Benchmark |
| 19 |
(I=10, optimization off, CPU seconds) |
| 20 |
|
| 21 |
DEC 1.1 sec DECsystem 2060 (TOPS-20 v4, F66) |
| 22 |
PR1ME 1.4 sec PR1ME 750 (PRIMOS v18.1, F66) |
| 23 |
PR1ME 1.5 sec PR1ME 750 (PRIMOS v18.1, F77) |
| 24 |
DEC 2.1 sec VAX 11/780 (Unix, F77) |
| 25 |
Apollo 6.2 sec 10 MHz MC68000 w/hardware float. point (AEGIS v4.0, F77) |
| 26 |
Apollo 13.1 sec 10 MHz MC68000 w/software float. point (AEGIS v4.0, F77) |
| 27 |
Intel 16.0 sec 8086/8087 (286WD Micro Development System,Intel FORTRAN) |
| 28 |
IBM 16.0 sec 4.77 MHz 8088 PC w/8087 (DOS 2, Microsoft F77/3.10) |
| 29 |
Z80 124.0 sec 4 MHz Z80 with Microsoft Fortran, CP/M |
| 30 |
IBM 268.9 sec 4.77 MHz 8088 PC ($NODEBUG) (DOS 1, Microsoft F77/1.0) |
| 31 |
Intel 390.0 sec 8086 alone (286WD Micro Development System,Intel FORTRAN) |
| 32 |
|
| 33 |
Table compiled by Richard Gillmann (Gillmann@ISIB). |
| 34 |
*/ |
| 35 |
|
| 36 |
import core.stdc.stdio; |
| 37 |
import core.stdc.time; |
| 38 |
import core.stdc.math; |
| 39 |
|
| 40 |
double t, t1, t2; |
| 41 |
double[5] e1; |
| 42 |
int j, k, l; |
| 43 |
|
| 44 |
int main() |
| 45 |
{ |
| 46 |
clock_t start, stop; |
| 47 |
double x1, x2, x3, x4, x, y, z; |
| 48 |
int i, isave, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12; |
| 49 |
|
| 50 |
start = clock(); |
| 51 |
|
| 52 |
/* I=10 CORRESPONDS TO ONE MILLION WHETSTONE INSTRUCTIONS */ |
| 53 |
|
| 54 |
i = 10; |
| 55 |
t1 = 0.50025000; |
| 56 |
t = 0.499975000; |
| 57 |
t2 = 2.0000; |
| 58 |
isave = i; |
| 59 |
n1 = 0; |
| 60 |
n2 = 12 * i; |
| 61 |
n3 = 14 * i; |
| 62 |
n4 = 348 * i; |
| 63 |
n5 = 0; |
| 64 |
n6 = 210 * i; |
| 65 |
n7 = 32 * i; |
| 66 |
n8 = 899 * i; |
| 67 |
n9 = 516 * i; |
| 68 |
n10 = 0; |
| 69 |
n11 = 93 * i; |
| 70 |
n12 = 0; |
| 71 |
x1 = 1.0; |
| 72 |
x2 = -1.0; |
| 73 |
x3 = -1.0; |
| 74 |
x4 = -1.0; |
| 75 |
for (i = 1; i <= n1; i++) |
| 76 |
{ |
| 77 |
x1 = (x1+x2+x3-x4)*t; |
| 78 |
x2 = (x1+x2-x3+x4)*t; |
| 79 |
x3 = (x1-x2+x3+x4)*t; |
| 80 |
x4 = (-x1+x2+x3+x4)*t; |
| 81 |
} |
| 82 |
auto s = pout(n1,n1,n1,x1,x2,x3,x4); |
| 83 |
assert(s[] == " 0 0 0 1.0000e+00 -1.0000e+00 -1.0000e+00 -1.0000e+00"); |
| 84 |
|
| 85 |
e1[1] = 1.0; |
| 86 |
e1[2] = -1.0; |
| 87 |
e1[3] = -1.0; |
| 88 |
e1[4] = -1.0; |
| 89 |
|
| 90 |
for (i = 1; i <= n2; i++) |
| 91 |
{ |
| 92 |
e1[1] = (e1[1]+e1[2]+e1[3]-e1[4])*t; |
| 93 |
e1[2] = (e1[1]+e1[2]-e1[3]+e1[4])*t; |
| 94 |
e1[3] = (e1[1]-e1[2]+e1[3]+e1[4])*t; |
| 95 |
e1[4] = (-e1[1]+e1[2]+e1[3]+e1[4])*t; |
| 96 |
} |
| 97 |
pout(n2,n3,n2,e1[1],e1[2],e1[3],e1[4]); |
| 98 |
assert(s == " 120 140 120 -6.8342e-02 -4.6264e-01 -7.2972e-01 -1.1240e+00"); |
| 99 |
|
| 100 |
for (i = 1; i <= n3; i++) |
| 101 |
{ |
| 102 |
pa(e1); |
| 103 |
} |
| 104 |
pout(n3,n2,n2,e1[1],e1[2],e1[3],e1[4]); |
| 105 |
assert(s == " 140 120 120 -5.5336e-02 -4.4744e-01 -7.1097e-01 -1.1031e+00"); |
| 106 |
|
| 107 |
j = 1; |
| 108 |
for (i = 1; i <= n4; i++) |
| 109 |
{ |
| 110 |
j = (j-1) ? 3 : 2; |
| 111 |
j = (j-2 < 0) ? 0 : 1; |
| 112 |
j = (j-1 < 0) ? 1 : 0; |
| 113 |
} |
| 114 |
pout(n4, j, j, x1, x2, x3, x4); |
| 115 |
assert(s == " 3480 0 0 1.0000e+00 -1.0000e+00 -1.0000e+00 -1.0000e+00"); |
| 116 |
|
| 117 |
j = 1; |
| 118 |
k = 2; |
| 119 |
l = 3; |
| 120 |
for (i = 1; i <= n6; i++) |
| 121 |
{ |
| 122 |
j = j*(k-j)*(l-k); |
| 123 |
k = l*k-(l-j)*k; |
| 124 |
l = (l-k)*(k+j); |
| 125 |
e1[l-1] = j+k+l; |
| 126 |
e1[k-1] = j*k*l; |
| 127 |
} |
| 128 |
pout(n6,j,k,e1[1],e1[2],e1[3],e1[4]); |
| 129 |
assert(s == " 2100 1 2 6.0000e+00 6.0000e+00 -7.1097e-01 -1.1031e+00"); |
| 130 |
|
| 131 |
x = 0.5; |
| 132 |
y = 0.5; |
| 133 |
for (i = 1; i <= n7; i++) |
| 134 |
{ |
| 135 |
x = t * atan(t2* sin(x)* cos(x) / |
| 136 |
( cos(x+y)+ cos(x-y)-1.0 )); |
| 137 |
y = t * atan(t2* sin(y)* cos(y) / |
| 138 |
( cos(x+y)+ cos(x-y)-1.0 )); |
| 139 |
} |
| 140 |
pout(n7, j, k, x, x, y, y); |
| 141 |
assert(s == " 320 1 2 4.9041e-01 4.9041e-01 4.9039e-01 4.9039e-01"); |
| 142 |
|
| 143 |
x = 1.0; |
| 144 |
y = 1.0; |
| 145 |
z = 1.0; |
| 146 |
|
| 147 |
for (i = 1; i <= n8; i++) |
| 148 |
{ |
| 149 |
z = p3(x, y); |
| 150 |
} |
| 151 |
pout(n8, j, k, x, y, z, z); |
| 152 |
assert(s == " 8990 1 2 1.0000e+00 1.0000e+00 9.9994e-01 9.9994e-01"); |
| 153 |
|
| 154 |
j = 1; |
| 155 |
k = 2; |
| 156 |
l = 3; |
| 157 |
e1[1] = 1.0; |
| 158 |
e1[2] = 2.0; |
| 159 |
e1[3] = 3.0; |
| 160 |
|
| 161 |
for (i = 1; i <= n9; i++) |
| 162 |
{ |
| 163 |
p0(); |
| 164 |
} |
| 165 |
pout(n9, j, k, e1[1], e1[2], e1[3], e1[4]); |
| 166 |
assert(s == " 5160 1 2 3.0000e+00 2.0000e+00 3.0000e+00 -1.1031e+00"); |
| 167 |
|
| 168 |
j = 2; |
| 169 |
k = 3; |
| 170 |
|
| 171 |
for (i = 1; i <= n10; i++) |
| 172 |
{ |
| 173 |
j = j + k; |
| 174 |
k = j + k; |
| 175 |
j = j - k; |
| 176 |
k = k - j - j; |
| 177 |
} |
| 178 |
pout(n10, j, k, x1, x2, x3, x4); |
| 179 |
assert(s == " 0 2 3 1.0000e+00 -1.0000e+00 -1.0000e+00 -1.0000e+00"); |
| 180 |
|
| 181 |
x = 0.75; |
| 182 |
|
| 183 |
for (i = 1; i <= n11; i++) |
| 184 |
{ |
| 185 |
x = sqrt( exp( log(x) / t1)); |
| 186 |
} |
| 187 |
|
| 188 |
pout(n11,j,k,x,x,x,x); |
| 189 |
assert(s == " 930 2 3 8.3467e-01 8.3467e-01 8.3467e-01 8.3467e-01"); |
| 190 |
|
| 191 |
stop = clock(); |
| 192 |
|
| 193 |
version (none) |
| 194 |
printf("Elapsed time = %d.%02d seconds\n", |
| 195 |
cast(int)(stop - start)/CLOCKS_PER_SEC, |
| 196 |
cast(int)(stop - start)%CLOCKS_PER_SEC); |
| 197 |
return 0; |
| 198 |
} |
| 199 |
|
| 200 |
void pa(double[] e) |
| 201 |
{ |
| 202 |
for (j = 0; j < 6; j++) |
| 203 |
{ |
| 204 |
e[1] = (e[1] + e[2] + e[3] - e[4]) * t; |
| 205 |
e[2] = (e[1] + e[2] - e[3] + e[4]) * t; |
| 206 |
e[3] = (e[1] - e[2] + e[3] + e[4]) * t; |
| 207 |
e[4] = (-e[1] + e[2] + e[3] + e[4]) / t2; |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
void p0() |
| 212 |
{ |
| 213 |
e1[j] = e1[k]; |
| 214 |
e1[k] = e1[l]; |
| 215 |
e1[l] = e1[j]; |
| 216 |
} |
| 217 |
|
| 218 |
double p3(double x, double y) |
| 219 |
{ |
| 220 |
x = t * (x + y); |
| 221 |
y = t * (x + y); |
| 222 |
return (x + y) / t2; |
| 223 |
} |
| 224 |
|
| 225 |
char[] pout(int n, int j, int k, double x1, double x2, double x3, double x4) |
| 226 |
{ |
| 227 |
__gshared char[80] result; |
| 228 |
const len = sprintf(result.ptr, " %7d %7d %7d %12.4e %12.4e %12.4e %12.4e", |
| 229 |
n, j, k, x1, x2, x3, x4); |
| 230 |
printf("%s\n", result.ptr); |
| 231 |
return result[0 .. len]; |
| 232 |
} |