forked from FFTW/fftw3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench-main.c
255 lines (229 loc) · 6.75 KB
/
bench-main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*
* Copyright (c) 2001 Matteo Frigo
* Copyright (c) 2001 Massachusetts Institute of Technology
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/* $Id: bench-main.c,v 1.9 2003-03-15 20:29:43 stevenj Exp $ */
#include "config.h"
#include "getopt.h"
#include "bench.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int verbose;
int paranoid;
static struct option long_options[] =
{
{"accuracy", required_argument, 0, 'a'},
{"accuracy-rounds", required_argument, 0, 405},
{"can-do", required_argument, 0, 'd'},
{"help", no_argument, 0, 'h'},
{"info", required_argument, 0, 'i'},
{"info-all", no_argument, 0, 'I'},
{"paranoid", no_argument, 0, 'p'},
{"print-precision", no_argument, 0, 402},
{"print-time-min", no_argument, 0, 400},
{"random-seed", required_argument, 0, 404},
{"report-avg-mflops", no_argument, 0, 302},
{"report-avg-time", no_argument, 0, 312},
{"report-benchmark", no_argument, 0, 320},
{"report-max-mflops", no_argument, 0, 301},
{"report-mflops", no_argument, 0, 300},
{"report-min-time", no_argument, 0, 311},
{"report-time", no_argument, 0, 310},
{"speed", required_argument, 0, 's'},
{"time-min", required_argument, 0, 't'},
{"time-repeat", required_argument, 0, 'r'},
{"verbose", optional_argument, 0, 'v'},
{"verify", required_argument, 0, 'y'},
{"verify-rounds", required_argument, 0, 401},
{"verify-tolerance", required_argument, 0, 403},
{0, no_argument, 0, 0}
};
static int bench_main1(int argc, char *argv[])
{
double tmin = 0.0;
double tol;
int repeat = 0;
int rounds = 10;
int arounds = 1; /* this is too low for precise results */
int c;
int index;
char *short_options = make_short_options(long_options);
report = report_time; /* default */
verbose = paranoid = 0;
tol = SINGLE_PRECISION ? 1.0e-3 : 1.0e-10;
bench_srand(1);
while ((c = getopt_long (argc, argv, short_options,
long_options, &index)) != -1) {
switch (c) {
case 't' :
tmin = strtod(optarg, 0);
break;
case 'r':
repeat = atoi(optarg);
break;
case 's':
timer_init(tmin, repeat);
speed(optarg);
break;
case 'd':
report_can_do(optarg);
break;
case 'v':
if (optarg)
verbose = atoi(optarg);
else
++verbose;
break;
case 'p':
++paranoid;
break;
case 'y':
verify(optarg, rounds, tol);
break;
case 'a':
accuracy(optarg, arounds);
break;
case 'i':
report_info(optarg);
break;
case 'I':
report_info_all();
break;
case 'h':
usage(argv[0], long_options);
break;
case 300: /* --report-mflops */
report = report_mflops;
break;
case 301: /* --report-max-mflops */
report = report_max_mflops;
break;
case 302: /* --report-avg-mflops */
report = report_avg_mflops;
break;
case 310: /* --report-time */
report = report_time;
break;
case 311: /* --report-min-time */
report = report_min_time;
break;
case 312: /* --report-avg-time */
report = report_avg_time;
break;
case 320: /* --report-benchmark */
report = report_benchmark;
break;
case 400: /* --print-time-min */
timer_init(tmin, repeat);
ovtpvt("%g\n", time_min);
break;
case 401: /* --verify-rounds */
rounds = atoi(optarg);
break;
case 402: /* --print-precision */
if (SINGLE_PRECISION)
ovtpvt("single\n");
else if (LDOUBLE_PRECISION)
ovtpvt("long-double\n");
else if (DOUBLE_PRECISION)
ovtpvt("double\n");
else
ovtpvt("unknown %d\n", sizeof(bench_real));
break;
case 403: /* --verify-tolerance */
tol = strtod(optarg, 0);
break;
case 404: /* --random-seed */
bench_srand(atoi(optarg));
break;
case 405: /* --accuracy-rounds */
arounds = atoi(optarg);
break;
case '?':
/* `getopt_long' already printed an error message. */
break;
default:
abort ();
}
}
/* Print any remaining command line arguments (not options). */
if (optind < argc) {
fprintf(stderr, "unrecognized non-option arguments: ");
while (optind < argc)
fprintf(stderr, "%s ", argv[optind++]);
fprintf(stderr, "\n");
}
bench_free(short_options);
return 0;
}
int bench_main(int argc, char *argv[])
{
#if defined(__GNUC__) && defined(__i386__)
/*
* horrible hack to align the stack so that double precision
* numbers are 8-bytes aligned on x86 processors. If not,
* the benchmark is totally useless.
*
* We assume a gcc version >= 2.95 so that
* -mpreferred-stack-boundary works. Otherwise, all bets are
* off. However, -mpreferred-stack-boundary does not create a
* stack alignment, but it only preserves it. Unfortunately,
* many versions of libc on linux call main() with the wrong
* initial stack alignment, with the result that the code is now
* pessimally aligned instead of having a 50% chance of being
* correct.
*
* Here, we check the alignment of a double variable and restore
* the proper alignment if it is wrong.
*/
{
double x;
if (((long)&x) & 0x7) {
/* wrong alignment. */
/*
* You would imagine that __builtin_alloca(4) would
* solve the problem. However, the overzealous gcc
* aligns it to __builtin_alloca(8) so that we
* accomplish nothing. So here is what we do:
*/
/*
* Use alloca to allocate some memory on the stack.
* This alerts gcc that something funny is going
* on, so that it does not omit the frame pointer
* etc.
*/
(void)__builtin_alloca(16);
/*
* Now allocate 4 stack bytes using inline asm.
*/
__asm__ __volatile__ ("addl $-4, %esp");
}
}
#endif
#ifdef __ICC /* Intel's compiler for ia32 */
{
/*
* Simply calling alloca seems to do the right thing.
* The size of the allocated block seems to be irrelevant.
*/
_alloca(8);
}
#endif
return bench_main1(argc, argv);
}