This repository has been archived by the owner on Jun 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
do
464 lines (412 loc) · 13 KB
/
do
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
#!/bin/sh -e
# supercop/do
# D. J. Bernstein
# Public domain.
version=`cat version`
project=supercop
shorthostname=`hostname | sed 's/\..*//' | tr -cd '[a-z][A-Z][0-9]' | tr '[A-Z]' '[a-z]'`
top="`pwd`/bench/$shorthostname"
bin="$top/bin"
lib="$top/lib"
include="$top/include"
work="$top/work"
PATH="/usr/local/bin:$PATH"
PATH="/usr/sfw/bin:$PATH"
PATH="$bin:$PATH"
export PATH
LD_LIBRARY_PATH="/usr/local/lib/sparcv9:/usr/local/lib:$LD_LIBRARY_PATH"
LD_LIBRARY_PATH="/usr/sfw/lib/sparcv9:/usr/sfw/lib:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH
# and wacky MacOS X
DYLD_LIBRARY_PATH="/usr/local/lib/sparcv9:/usr/local/lib:$DYLD_LIBRARY_PATH"
DYLD_LIBRARY_PATH="/usr/sfw/lib/sparcv9:/usr/sfw/lib:$DYLD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH
# and work around bug in GNU sort
LANG=C
export LANG
rm -rf "$top"
mkdir -p "$top"
mkdir -p "$bin"
mkdir -p "$lib"
mkdir -p "$include"
cp include/* "$include"
exec >"$top/log"
exec 2>&1
exec 5>"$top/data"
exec </dev/null
echo "=== `date` === starting"
echo "=== `date` === building machineinfo"
rm -rf "$work"
mkdir -p "$work"
cp -pr machineinfo/* "$work"
( cd "$work" && sh do )
echo "=== `date` === building scripts"
cp -p scripts/* "$bin"
echo "=== `date` === building okcompilers"
rm -rf "$work"
mkdir -p "$work"
cp -pr okcompilers/* "$work"
( cd "$work" && sh do )
cp -p "$work"/bin/* "$bin"
echo "=== `date` === building cpuid"
rm -rf "$work"
mkdir -p "$work"
cp -pr cpuid/* "$work"
( cd "$work" && sh do )
cp -pr "$work"/include/* "$include"
echo "=== `date` === building inttypes"
rm -rf "$work"
mkdir -p "$work"
cp -pr inttypes/* "$work"
( cd "$work" && sh do )
cp -pr "$work"/include/* "$include"
echo "=== `date` === building killafter"
rm -rf "$work"
mkdir -p "$work"
cp -pr killafter/* "$work"
( cd "$work" && sh do )
cp -p "$work"/bin/* "$bin"
echo "=== `date` === building sinceepoch"
rm -rf "$work"
mkdir -p "$work"
cp -pr sinceepoch/* "$work"
( cd "$work" && sh do )
cp -p "$work"/bin/* "$bin"
echo "=== `date` === building cpucycles"
rm -rf "$work"
mkdir -p "$work"
cp -pr cpucycles/* "$work"
( cd "$work" && sh do )
cp -pr "$work"/lib/* "$lib"
cp -pr "$work"/include/* "$include"
okabi \
| while read abi
do
echo "=== `date` === building gmp for $abi"
mkdir -p "$lib/$abi"
mkdir -p "$include/$abi"
okc-$abi | head -1 \
| while read c copts
do
okcpp-$abi | head -1 \
| while read cpp cppopts
do
for gmpabi in 64 32 2.0w 2.0n 1.0 o32 n32 aix64 mode64 mode32 standard
do
[ -s "$lib/$abi/libgmp.a" ] && continue
echo "=== `date` === trying CC=$c CXX=$cpp CFLAGS=$copts CXXFLAGS=$cppopts ABI=$gmpabi"
rm -rf "$work"
mkdir -p "$work"
cp -pr gmp-6.1.1/* "$work"
( cd "$work" \
&& ./configure --enable-cxx \
ABI="$gmpabi" \
CC="$c" CXX="$cpp" CFLAGS="$copts" CXXFLAGS="$cppopts" LDFLAGS="$copts" \
&& make \
&& make check \
&& cp gmp.h gmpxx.h gmp-impl.h longlong.h \
config.h gmp-mparam.h fac_table.h fib_table.h mp_bases.h "$include/$abi" \
&& ( ranlib ".libs/libgmp.a" || : ) \
&& cp .libs/libgmp.a "$lib/$abi/libgmp.a" \
&& chmod 644 "$lib/$abi/libgmp.a" \
&& ( ranlib ".libs/libgmpxx.a" || : ) \
&& ( cp .libs/libgmpxx.a "$lib/$abi/libgmpxx.a" || : ) \
&& ( chmod 644 "$lib/$abi/libgmpxx.a" || : )
) && break
done
done
done
done
okabi \
| while read abi
do
echo "=== `date` === building cryptopp for $abi"
mkdir -p "$lib/$abi"
mkdir -p "$include/$abi/cryptopp"
okcpp-$abi | head -1 \
| while read cpp cppopts
do
[ -s "$lib/$abi/libcryptopp.a" ] && continue
echo "=== `date` === trying CXX=$cpp CXXFLAGS=$cppopts"
rm -rf "$work"
mkdir -p "$work"
cp -pr cryptopp-562/* "$work"
( cd "$work" \
&& make CXX="$cpp" CXXFLAGS="-DNDEBUG $cppopts" LDFLAGS="$cppopts" \
&& cp libcryptopp.a "$lib/$abi/libcryptopp.a" \
&& cp *.h "$include/$abi/cryptopp/"
) && break
done
done
okabi \
| while read abi
do
rm -rf "$work"
mkdir -p "$work"
echo 'void crypto_'"$project"'_base(void) { ; }' > "$work/${project}_base.c"
okc-$abi \
| while read compiler
do
( cd "$work" && $compiler -c ${project}_base.c ) && break
done
okar-$abi cr "$lib/$abi/lib${project}.a" "$work/${project}_base.o"
( ranlib "$lib/$abi/lib${project}.a" || exit 0 )
done
# loop over operations
cat OPERATIONS \
| while read o macros prototypes
do
[ -d "$o" ] || continue
# for each operation, loop over primitives
ls "$o" \
| sort \
| while read p
do
[ -d "$o/$p" ] || continue
expectedchecksumbig=''
[ -f "$o/$p/checksumbig" ] && expectedchecksumbig=`cat "$o/$p/checksumbig"`
expectedchecksumsmall=''
[ -f "$o/$p/checksumsmall" ] && expectedchecksumsmall=`cat "$o/$p/checksumsmall"`
op="${o}_${p}"
startdate=`date +%Y%m%d`
# for each operation primitive, loop over abis
okabi \
| while read abi
do
echo "=== `date` === $abi $o/$p"
libs=`"oklibs-$abi"`
libs="$lib/$abi/cpucycles.o $libs"
[ -f "$lib/$abi/libgmp.a" ] && libs="$lib/$abi/libgmp.a $libs"
[ -f "$lib/$abi/libcryptopp.a" ] && libs="$lib/$abi/libcryptopp.a $libs"
[ -f "$lib/$abi/lib${project}.a" ] && libs="$lib/$abi/lib${project}.a $libs"
rm -rf "$work"
mkdir -p "$work"
mkdir -p "$work/best"
mkdir -p "$work/bestc"
# for each operation primitive abi, loop over implementations
find "$o/$p" -follow -name "api.h" \
| sort \
| while read doth
do
implementationdir=`dirname $doth`
opi=`echo "$implementationdir" | tr ./- ___`
if [ -f "$implementationdir/architectures" ]
then
if grep '^'"$abi"'$' "$implementationdir/architectures" >/dev/null
then
:
else
echo "=== `date` === skipping $abi/implementation/$implementationdir"
continue
fi
fi
echo "=== `date` === $abi $implementationdir"
rm -rf "$work/compile"
mkdir -p "$work/compile"
cp -pr "$implementationdir"/* "$work/compile"
cfiles=`ls "$work/compile" | grep '\.c$' || :`
sfiles=`ls "$work/compile" | grep '\.[sS]$' || :`
ccfiles=`ls "$work/compile" | grep '\.cc$' || :`
cppfiles=`ls "$work/compile" | grep '\.cpp$' || :`
language=c
[ "x$cppfiles" = x ] || language=cpp
[ "x$ccfiles" = x ] || language=cpp
cp -p "$o/try.c" "$work/compile/try.$language"
cp -p "$o/measure.c" "$work/compile/measure.$language"
cp -p "try-anything.c" "$work/compile/try-anything.$language"
cp -p "try.h" "$work/compile/try.h"
cp -p "measure-anything.c" "$work/compile/measure-anything.$language"
(
cd "$work/compile"
(
echo "#ifndef ${o}_H"
echo "#define ${o}_H"
echo ""
echo "#include \"${op}.h\""
echo ""
echo "$macros" | tr : '\012' | while read macro
do
echo "#define ${o}${macro} ${op}${macro}"
done
echo "#define ${o}_PRIMITIVE \"${p}\""
echo "#define ${o}_IMPLEMENTATION ${op}_IMPLEMENTATION"
echo "#define ${o}_VERSION ${op}_VERSION"
echo ""
echo "#endif"
) > "$o.h"
(
echo "#ifndef ${op}_H"
echo "#define ${op}_H"
echo ""
sed 's/[ ]CRYPTO_/ '"${opi}"'_/g' < api.h
echo ' '
echo '#ifdef __cplusplus'
echo 'extern "C" {'
echo '#endif'
echo "$prototypes" | tr : '\012' | while read prototype
do
echo "extern int ${opi}${prototype};"
done
echo '#ifdef __cplusplus'
echo '}'
echo '#endif'
echo ""
echo "$macros" | tr : '\012' | while read macro
do
echo "#define ${op}${macro} ${opi}${macro}"
done
echo "#define ${op}_IMPLEMENTATION \"${implementationdir}\""
echo "#ifndef ${opi}_VERSION"
echo "#define ${opi}_VERSION \"-\""
echo "#endif"
echo "#define ${op}_VERSION ${opi}_VERSION"
echo ""
echo "#endif"
) > "$op.h"
ok${language}-$abi \
| while read compiler
do
echo "=== `date` === $abi $implementationdir $compiler"
compilerword=`echo "$compiler" | tr ' ' '_'`
ok=1
for f in $cfiles $sfiles $ccfiles $cppfiles
do
if [ "$ok" = 1 ]
then
$compiler -DSUPERCOP \
-I. -I"$include" -I"$include/$abi" \
-c "$f" >../errors 2>&1 || ok=0
( if [ `wc -l < ../errors` -lt 25 ]
then
cat ../errors
else
head ../errors
echo ...
tail ../errors
fi
) \
| while read err
do
echo "$version $shorthostname $abi $startdate $o $p fromcompiler $implementationdir $compilerword $f $err" >&5
done
fi
done
[ "$ok" = 1 ] || continue
okar-$abi cr "$op.a" *.o || continue
ranlib "$op.a"
killafter 300 \
$compiler -DSUPERCOP -DSMALL \
-I. -I"$include" -I"$include/$abi" \
-o try try.$language try-anything.$language \
"$op.a" $libs >../errors 2>&1 || ok=0
cat ../errors \
| while read err
do
echo "$version $shorthostname $abi $startdate $o $p fromcompiler $implementationdir $compilerword try.$language $err" >&5
done
[ "$ok" = 1 ] || continue
if sh -c 'killafter 3600 ./try || exit $?' >../outputs 2>../errors
then
checksumsmall=`awk '{print $1}' < ../outputs`
cycles=`awk '{print $2}' < ../outputs`
checksumcycles=`awk '{print $3}' < ../outputs`
cyclespersecond=`awk '{print $4}' < ../outputs`
impl=`awk '{print $5}' < ../outputs`
else
echo "$version $shorthostname $abi $startdate $o $p tryfails $implementationdir $compilerword error $?" >&5
cat ../outputs ../errors \
| while read err
do
echo "$version $shorthostname $abi $startdate $o $p tryfails $implementationdir $compilerword $err" >&5
done
continue
fi
[ x"$expectedchecksumsmall" != x ] \
&& [ x"$expectedchecksumsmall" != "x$checksumsmall" ] \
&& echo "$version $shorthostname $abi $startdate $o $p try $checksumsmall fails $cycles $checksumcycles $cyclespersecond $impl $compilerword" >&5 \
&& continue
killafter 300 \
$compiler -DSUPERCOP \
-I. -I"$include" -I"$include/$abi" \
-o try try.$language try-anything.$language \
"$op.a" $libs >../errors 2>&1 || ok=0
cat ../errors \
| while read err
do
echo "$version $shorthostname $abi $startdate $o $p fromcompiler $implementationdir $compilerword try.$language $err" >&5
done
[ "$ok" = 1 ] || continue
if sh -c 'killafter 3600 ./try || exit $?' >../outputs 2>../errors
then
checksumbig=`awk '{print $1}' < ../outputs`
cycles=`awk '{print $2}' < ../outputs`
checksumcycles=`awk '{print $3}' < ../outputs`
cyclespersecond=`awk '{print $4}' < ../outputs`
impl=`awk '{print $5}' < ../outputs`
else
echo "$version $shorthostname $abi $startdate $o $p tryfails $implementationdir $compilerword error $?" >&5
cat ../outputs ../errors \
| while read err
do
echo "$version $shorthostname $abi $startdate $o $p tryfails $implementationdir $compilerword $err" >&5
done
continue
fi
[ x"$expectedchecksumbig" != x ] \
&& [ x"$expectedchecksumbig" != "x$checksumbig" ] \
&& echo "$version $shorthostname $abi $startdate $o $p try $checksumbig fails $cycles $checksumcycles $cyclespersecond $impl $compilerword" >&5 \
&& continue
checksumok=ok
[ "x$expectedchecksumsmall" = "x" ] && checksumok=unknown
[ "x$expectedchecksumbig" = "x" ] && checksumok=unknown
echo "$version $shorthostname $abi $startdate $o $p try $checksumsmall/$checksumbig $checksumok $cycles $checksumcycles $cyclespersecond $impl $compilerword" >&5
[ -s ../bestc/median ] && [ `cat ../bestc/median` -le $cycles ] && continue
killafter 3600 \
$compiler -D'COMPILER="'"$compiler"'"' \
-DSUPERCOP -DLOOPS=3 \
-I. -I"$include" -I"$include/$abi" \
-o measure measure.$language measure-anything.$language \
"$op.a" $libs >../errors 2>&1 || ok=0
cat ../errors \
| while read err
do
echo "$version $shorthostname $abi $startdate $o $p fromcompiler $implementationdir $compilerword measure.$language $err" >&5
done
[ "$ok" = 1 ] || continue
for b in best bestc
do
[ $language = cpp ] && [ $b = bestc ] && continue
[ -s ../$b/median ] && [ `cat ../$b/median` -le $cycles ] && continue
echo "$cycles" > ../$b/median
rm -f ../$b/*.o ../$b/measure || continue
for f in *.o
do
cp -p "$f" "../$b/${opi}-$f"
done
cp -p "$op.h" "../$b/$op.h"
cp -p "$o.h" "../$b/$o.h"
cp -p measure ../$b/measure
done
done
)
done
echo "=== `date` === $abi $o/$p measuring"
"$work/best/measure" \
| while read measurement
do
echo "$version $shorthostname $abi $startdate $o $p $measurement" >&5
done
[ -f "$o/$p/used" ] \
&& okar-$abi cr "$lib/$abi/lib${project}.a" "$work/bestc"/*.o \
&& ( ranlib "$lib/$abi/lib${project}.a" || exit 0 ) \
&& cp -p "$work/bestc/$op.h" "$include/$abi/$op.h" \
&& [ -f "$o/$p/selected" ] \
&& cp -p "$work/bestc/$o.h" "$include/$abi/$o.h" \
|| :
done
done
done
echo "=== `date` === finishing"
sed 's/^/+ /' <"$top/log" >&5
gzip -9 "$top/data"
touch "$top/done-$version"