do 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. #!/bin/sh
  2. # nacl/do
  3. # D. J. Bernstein
  4. # Public domain.
  5. version=`cat version`
  6. project=nacl
  7. shorthostname=`hostname | sed 's/\..*//' | tr -cd '[a-z][A-Z][0-9]'`
  8. top="`pwd`/build/$shorthostname"
  9. bin="$top/bin"
  10. lib="$top/lib"
  11. include="$top/include"
  12. work="$top/work"
  13. PATH="/usr/local/bin:$PATH"
  14. PATH="/usr/sfw/bin:$PATH"
  15. PATH="$bin:$PATH"
  16. export PATH
  17. LD_LIBRARY_PATH="/usr/local/lib/sparcv9:/usr/local/lib:$LD_LIBRARY_PATH"
  18. LD_LIBRARY_PATH="/usr/sfw/lib/sparcv9:/usr/sfw/lib:$LD_LIBRARY_PATH"
  19. export LD_LIBRARY_PATH
  20. # and wacky MacOS X
  21. DYLD_LIBRARY_PATH="/usr/local/lib/sparcv9:/usr/local/lib:$DYLD_LIBRARY_PATH"
  22. DYLD_LIBRARY_PATH="/usr/sfw/lib/sparcv9:/usr/sfw/lib:$DYLD_LIBRARY_PATH"
  23. export DYLD_LIBRARY_PATH
  24. # and work around bug in GNU sort
  25. LANG=C
  26. export LANG
  27. rm -rf "$top"
  28. mkdir -p "$top"
  29. mkdir -p "$bin"
  30. mkdir -p "$lib"
  31. mkdir -p "$include"
  32. exec 2>&1
  33. exec 5>"$top/data"
  34. exec </dev/null
  35. echo "=== `date` === starting"
  36. echo "=== `date` === hostname"
  37. hostname || :
  38. echo "=== `date` === uname -a"
  39. uname -a || :
  40. echo "=== `date` === uname -M"
  41. uname -M || :
  42. echo "=== `date` === uname -F"
  43. uname -F || :
  44. echo "=== `date` === /usr/sbin/lscfg | grep proc"
  45. /usr/sbin/lscfg | grep proc || :
  46. echo "=== `date` === /usr/sbin/lsattr -El proc0"
  47. /usr/sbin/lsattr -El proc0 || :
  48. echo "=== `date` === cat /proc/cpuinfo"
  49. cat /proc/cpuinfo || :
  50. echo "=== `date` === cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"
  51. cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq || :
  52. echo "=== `date` === cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq"
  53. cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq || :
  54. echo "=== `date` === cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq"
  55. cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq || :
  56. echo "=== `date` === cat /sys/devices/system/cpu/cpu0/clock_tick"
  57. cat /sys/devices/system/cpu/cpu0/clock_tick || :
  58. echo "=== `date` === sysctl hw.model"
  59. sysctl hw.model || :
  60. echo "=== `date` === sysctl machdep.tsc_freq"
  61. sysctl machdep.tsc_freq || :
  62. echo "=== `date` === /usr/sbin/psrinfo -v"
  63. /usr/sbin/psrinfo -v || :
  64. echo "=== `date` === building okcompilers"
  65. rm -rf "$work"
  66. mkdir -p "$work"
  67. cp -pr okcompilers/* "$work"
  68. ( cd "$work" && sh do )
  69. cp -p "$work"/bin/* "$bin"
  70. echo "=== `date` === building cpuid"
  71. rm -rf "$work"
  72. mkdir -p "$work"
  73. cp -pr cpuid/* "$work"
  74. ( cd "$work" && sh do )
  75. cp -pr "$work"/include/* "$include"
  76. echo "=== `date` === building inttypes"
  77. rm -rf "$work"
  78. mkdir -p "$work"
  79. cp -pr inttypes/* "$work"
  80. ( cd "$work" && sh do )
  81. cp -pr "$work"/include/* "$include"
  82. echo "=== `date` === building cpucycles"
  83. rm -rf "$work"
  84. mkdir -p "$work"
  85. cp -pr cpucycles/* "$work"
  86. ( cd "$work" && sh do )
  87. cp -pr "$work"/lib/* "$lib"
  88. cp -pr "$work"/include/* "$include"
  89. echo "=== `date` === building randombytes"
  90. rm -rf "$work"
  91. mkdir -p "$work"
  92. cp -pr randombytes/* "$work"
  93. ( cd "$work" && sh do )
  94. cp -pr "$work"/lib/* "$lib"
  95. cp -pr "$work"/include/* "$include"
  96. okabi \
  97. | while read abi
  98. do
  99. rm -rf "$work"
  100. mkdir -p "$work"
  101. echo 'void crypto_'"$project"'_base(void) { ; }' > "$work/${project}_base.c"
  102. okc-$abi \
  103. | while read compiler
  104. do
  105. ( cd "$work" && $compiler -c ${project}_base.c ) && break
  106. done
  107. okar-$abi cr "$lib/$abi/lib${project}.a" "$work/${project}_base.o"
  108. ( ranlib "$lib/$abi/lib${project}.a" || exit 0 )
  109. done
  110. # loop over operations
  111. cat OPERATIONS \
  112. | while read o
  113. do
  114. [ -d "$o" ] || continue
  115. selected=''
  116. [ -f "$o/selected" ] && selected=`cat "$o/selected"`
  117. # for each operation, loop over primitives
  118. ls "$o" \
  119. | sort \
  120. | while read p
  121. do
  122. [ -d "$o/$p" ] || continue
  123. expectedchecksum=''
  124. [ -f "$o/$p/checksum" ] && expectedchecksum=`cat "$o/$p/checksum"`
  125. op="${o}_${p}"
  126. startdate=`date +%Y%m%d`
  127. # for each operation primitive, loop over abis
  128. okabi \
  129. | while read abi
  130. do
  131. echo "=== `date` === $abi $o/$p"
  132. libs=`"oklibs-$abi"`
  133. libs="$lib/$abi/cpucycles.o $libs"
  134. [ -f "$lib/$abi/lib${project}.a" ] && libs="$lib/$abi/lib${project}.a $libs"
  135. rm -rf "$work"
  136. mkdir -p "$work"
  137. mkdir -p "$work/best"
  138. # for each operation primitive abi, loop over implementations
  139. find "$o/$p" -follow -name "api.h" \
  140. | sort \
  141. | while read doth
  142. do
  143. implementationdir=`dirname $doth`
  144. opi=`echo "$implementationdir" | tr ./- ___`
  145. echo "=== `date` === $abi $implementationdir"
  146. rm -rf "$work/compile"
  147. mkdir -p "$work/compile"
  148. cfiles=`ls "$implementationdir" | grep '\.c$' || :`
  149. sfiles=`ls "$implementationdir" | grep '\.[sS]$' || :`
  150. cppfiles=`ls "$o" | grep '\.cpp$' || :`
  151. cp -p "$o"/*.c "$work/compile/"
  152. cp -p "$o"/*.cpp "$work/compile/"
  153. cp -pr "$implementationdir"/* "$work/compile"
  154. cp -p "try-anything.c" "$work/compile/try-anything.c"
  155. cp -p "measure-anything.c" "$work/compile/measure-anything.c"
  156. cp -p MACROS "$work/compile/MACROS"
  157. cp -p PROTOTYPES.c "$work/compile/PROTOTYPES.c"
  158. cp -p PROTOTYPES.cpp "$work/compile/PROTOTYPES.cpp"
  159. (
  160. cd "$work/compile"
  161. (
  162. echo "#ifndef ${o}_H"
  163. echo "#define ${o}_H"
  164. echo ""
  165. echo "#include \"${op}.h\""
  166. echo ""
  167. egrep "${o}"'$|'"${o}"'\(|'"${o}"'_' < MACROS \
  168. | sed "s/$o/$op/" | while read mop
  169. do
  170. echo "#define ${mop} ${mop}" | sed "s/$op/$o/"
  171. done
  172. echo "#define ${o}_PRIMITIVE \"${p}\""
  173. echo "#define ${o}_IMPLEMENTATION ${op}_IMPLEMENTATION"
  174. echo "#define ${o}_VERSION ${op}_VERSION"
  175. echo ""
  176. echo "#endif"
  177. ) > "$o.h"
  178. (
  179. echo "#ifndef ${op}_H"
  180. echo "#define ${op}_H"
  181. echo ""
  182. sed 's/[ ]CRYPTO_/ '"${opi}"'_/g' < api.h
  183. echo '#ifdef __cplusplus'
  184. echo '#include <string>'
  185. egrep "${o}"'$|'"${o}"'\(|'"${o}"'_' < PROTOTYPES.cpp \
  186. | sed "s/$o/$opi/"
  187. echo 'extern "C" {'
  188. echo '#endif'
  189. egrep "${o}"'$|'"${o}"'\(|'"${o}"'_' < PROTOTYPES.c \
  190. | sed "s/$o/$opi/"
  191. echo '#ifdef __cplusplus'
  192. echo '}'
  193. echo '#endif'
  194. echo ""
  195. egrep "${o}"'$|'"${o}"'\(|'"${o}"'_' < MACROS \
  196. | sed "s/$o/$opi/" | while read mopi
  197. do
  198. echo "#define ${mopi} ${mopi}" | sed "s/$opi/$op/"
  199. done
  200. echo "#define ${op}_IMPLEMENTATION \"${implementationdir}\""
  201. echo "#ifndef ${opi}_VERSION"
  202. echo "#define ${opi}_VERSION \"-\""
  203. echo "#endif"
  204. echo "#define ${op}_VERSION ${opi}_VERSION"
  205. echo ""
  206. echo "#endif"
  207. ) > "$op.h"
  208. okc-$abi \
  209. | while read compiler
  210. do
  211. echo "=== `date` === $abi $implementationdir $compiler"
  212. compilerword=`echo "$compiler" | tr ' ' '_'`
  213. ok=1
  214. for f in $cfiles $sfiles
  215. do
  216. if [ "$ok" = 1 ]
  217. then
  218. $compiler \
  219. -I. -I"$include" -I"$include/$abi" \
  220. -c "$f" >../errors 2>&1 || ok=0
  221. ( if [ `wc -l < ../errors` -lt 25 ]
  222. then
  223. cat ../errors
  224. else
  225. head ../errors
  226. echo ...
  227. tail ../errors
  228. fi
  229. ) \
  230. | while read err
  231. do
  232. echo "$version $shorthostname $abi $startdate $o $p fromcompiler $implementationdir $compilerword $f $err" >&5
  233. done
  234. fi
  235. done
  236. [ "$ok" = 1 ] || continue
  237. okar-$abi cr "$op.a" *.o || continue
  238. ranlib "$op.a"
  239. $compiler \
  240. -I. -I"$include" -I"$include/$abi" \
  241. -o try try.c try-anything.c \
  242. "$op.a" $libs >../errors 2>&1 || ok=0
  243. cat ../errors \
  244. | while read err
  245. do
  246. echo "$version $shorthostname $abi $startdate $o $p fromcompiler $implementationdir $compilerword try.c $err" >&5
  247. done
  248. [ "$ok" = 1 ] || continue
  249. if sh -c './try || exit $?' >../outputs 2>../errors
  250. then
  251. checksum=`awk '{print $1}' < ../outputs`
  252. cycles=`awk '{print $2}' < ../outputs`
  253. checksumcycles=`awk '{print $3}' < ../outputs`
  254. cyclespersecond=`awk '{print $4}' < ../outputs`
  255. impl=`awk '{print $5}' < ../outputs`
  256. else
  257. echo "$version $shorthostname $abi $startdate $o $p tryfails $implementationdir $compilerword error $?" >&5
  258. cat ../outputs ../errors \
  259. | while read err
  260. do
  261. echo "$version $shorthostname $abi $startdate $o $p tryfails $implementationdir $compilerword $err" >&5
  262. done
  263. continue
  264. fi
  265. checksumok=fails
  266. [ "x$expectedchecksum" = "x$checksum" ] && checksumok=ok
  267. [ "x$expectedchecksum" = "x" ] && checksumok=unknown
  268. echo "$version $shorthostname $abi $startdate $o $p try $checksum $checksumok $cycles $checksumcycles $cyclespersecond $impl $compilerword" >&5
  269. [ "$checksumok" = fails ] && continue
  270. [ -s ../bestmedian ] && [ `cat ../bestmedian` -le $cycles ] && continue
  271. echo "$cycles" > ../bestmedian
  272. $compiler -D'COMPILER="'"$compiler"'"' \
  273. -DLOOPS=1 \
  274. -I. -I"$include" -I"$include/$abi" \
  275. -o measure measure.c measure-anything.c \
  276. "$op.a" $libs >../errors 2>&1 || ok=0
  277. cat ../errors \
  278. | while read err
  279. do
  280. echo "$version $shorthostname $abi $startdate $o $p fromcompiler $implementationdir $compilerword measure.c $err" >&5
  281. done
  282. [ "$ok" = 1 ] || continue
  283. for f in $cppfiles
  284. do
  285. okcpp-$abi \
  286. | while read cppcompiler
  287. do
  288. echo "=== `date` === $abi $implementationdir $cppcompiler"
  289. $cppcompiler \
  290. -I. -I"$include" -I"$include/$abi" \
  291. -c "$f" && break
  292. done
  293. done
  294. rm -f ../best/*.o ../best/measure || continue
  295. for f in *.o
  296. do
  297. cp -p "$f" "../best/${opi}-$f"
  298. done
  299. cp -p "$op.h" "../$op.h"
  300. cp -p "$o.h" "../$o.h"
  301. cp -p measure ../best/measure
  302. done
  303. )
  304. done
  305. echo "=== `date` === $abi $o/$p measuring"
  306. "$work/best/measure" \
  307. | while read measurement
  308. do
  309. echo "$version $shorthostname $abi $startdate $o $p $measurement" >&5
  310. done
  311. [ -f "$o/$p/used" ] \
  312. && okar-$abi cr "$lib/$abi/lib${project}.a" "$work/best"/*.o \
  313. && ( ranlib "$lib/$abi/lib${project}.a" || exit 0 ) \
  314. && cp -p "$work/$op.h" "$include/$abi/$op.h" \
  315. && [ -f "$o/$p/selected" ] \
  316. && cp -p "$work/$o.h" "$include/$abi/$o.h" \
  317. || :
  318. done
  319. done
  320. done
  321. for language in c cpp
  322. do
  323. for bintype in commandline tests
  324. do
  325. ls $bintype \
  326. | sed -n 's/\.'$language'$//p' \
  327. | sort \
  328. | while read cmd
  329. do
  330. echo "=== `date` === starting $bintype/$cmd"
  331. rm -rf "$work"
  332. mkdir -p "$work/compile"
  333. cp "$bintype/$cmd.$language" "$work/compile/$cmd.$language"
  334. [ "$bintype" = tests ] && cp -p "$bintype/$cmd.out" "$work/compile/$cmd.out"
  335. okabi \
  336. | while read abi
  337. do
  338. [ -x "$bin/$cmd" ] && break
  339. libs=`"oklibs-$abi"`
  340. libs="$lib/$abi/cpucycles.o $libs"
  341. libs="$libs $lib/$abi/randombytes.o"
  342. ok${language}-$abi \
  343. | while read compiler
  344. do
  345. [ -x "$bin/$cmd" ] && break
  346. echo "=== `date` === $bintype/$cmd $abi $compiler"
  347. (
  348. cd "$work/compile"
  349. if $compiler \
  350. -I"$include" -I"$include/$abi" \
  351. -o "$cmd" "$cmd.${language}" \
  352. "$lib/$abi/lib${project}.a" $libs
  353. then
  354. case "$bintype" in
  355. commandline) cp -p "$cmd" "$bin/$cmd" ;;
  356. tests) "./$cmd" | cmp - "$cmd.out" || "./$cmd" ;;
  357. esac
  358. fi
  359. )
  360. done
  361. done
  362. done
  363. done
  364. done
  365. echo "=== `date` === starting curvecp"
  366. okabi \
  367. | awk '
  368. { if ($1=="amd64" || $1=="ia64" || $1=="ppc64" || $1=="sparcv9" || $1=="mips64") print 1,$1
  369. else if ($1 == "mips32") print 2,$1
  370. else print 3,$1
  371. }
  372. ' \
  373. | sort \
  374. | while read okabipriority abi
  375. do
  376. [ -x "$bin/curvecpmessage" ] && break
  377. libs=`"oklibs-$abi"`
  378. libs="$lib/$abi/cpucycles.o $libs"
  379. libs="$libs $lib/$abi/randombytes.o"
  380. okc-$abi \
  381. | while read compiler
  382. do
  383. [ -x "$bin/curvecpmessage" ] && break
  384. echo "=== `date` === curvecp $abi $compiler"
  385. rm -rf "$work"
  386. mkdir -p "$work/compile"
  387. cp curvecp/* "$work/compile"
  388. (
  389. cd "$work/compile"
  390. cat SOURCES \
  391. | while read x
  392. do
  393. $compiler -I"$include" -I"$include/$abi" -c "$x.c"
  394. done
  395. if okar-$abi cr curvecplibs.a `cat LIBS`
  396. then
  397. cat TARGETS \
  398. | while read x
  399. do
  400. $compiler -I"$include" -I"$include/$abi" \
  401. -o "$x" "$x.o" \
  402. curvecplibs.a "$lib/$abi/lib${project}.a" $libs \
  403. && cp -p "$x" "$bin/$x"
  404. done
  405. fi
  406. )
  407. done
  408. done
  409. echo "=== `date` === finishing"