block-sha1: improve code on large-register-set machines

For x86 performance (especially in 32-bit mode) I added that hack to write
the SHA1 internal temporary hash using a volatile pointer, in order to get
gcc to not try to cache the array contents. Because gcc will do all the
wrong things, and then spill things in insane random ways.

But on architectures like PPC, where you have 32 registers, it's actually
perfectly reasonable to put the whole temporary array[] into the register
set, and gcc can do so.

So make the 'volatile unsigned int *' cast be dependent on a
SMALL_REGISTER_SET preprocessor symbol, and enable it (currently) on just
x86 and x86-64.  With that, the routine is fairly reasonable even when
compared to the hand-scheduled PPC version. Ben Herrenschmidt reports on
a G5:

 * Paulus asm version:       about 3.67s
 * Yours with no change:     about 5.74s
 * Yours without "volatile": about 3.78s

so with this the C version is within about 3% of the asm one.

And add a lot of commentary on what the heck is going on.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 file changed
tree: 882344c9a83dd2f43129a2c4ba1d277edd8e5fe1
  1. arm/
  2. block-sha1/
  3. compat/
  4. contrib/
  5. Documentation/
  6. git-gui/
  7. gitk-git/
  8. gitweb/
  9. mozilla-sha1/
  10. perl/
  11. ppc/
  12. t/
  13. templates/
  14. xdiff/
  15. .gitattributes
  16. .gitignore
  17. .mailmap
  18. abspath.c
  19. alias.c
  20. alloc.c
  21. archive-tar.c
  22. archive-zip.c
  23. archive.c
  24. archive.h
  25. attr.c
  26. attr.h
  27. base85.c
  28. bisect.c
  29. bisect.h
  30. blob.c
  31. blob.h
  32. branch.c
  33. branch.h
  34. builtin-add.c
  35. builtin-annotate.c
  36. builtin-apply.c
  37. builtin-archive.c
  38. builtin-bisect--helper.c
  39. builtin-blame.c
  40. builtin-branch.c
  41. builtin-bundle.c
  42. builtin-cat-file.c
  43. builtin-check-attr.c
  44. builtin-check-ref-format.c
  45. builtin-checkout-index.c
  46. builtin-checkout.c
  47. builtin-clean.c
  48. builtin-clone.c
  49. builtin-commit-tree.c
  50. builtin-commit.c
  51. builtin-config.c
  52. builtin-count-objects.c
  53. builtin-describe.c
  54. builtin-diff-files.c
  55. builtin-diff-index.c
  56. builtin-diff-tree.c
  57. builtin-diff.c
  58. builtin-fast-export.c
  59. builtin-fetch--tool.c
  60. builtin-fetch-pack.c
  61. builtin-fetch.c
  62. builtin-fmt-merge-msg.c
  63. builtin-for-each-ref.c
  64. builtin-fsck.c
  65. builtin-gc.c
  66. builtin-grep.c
  67. builtin-help.c
  68. builtin-http-fetch.c
  69. builtin-init-db.c
  70. builtin-log.c
  71. builtin-ls-files.c
  72. builtin-ls-remote.c
  73. builtin-ls-tree.c
  74. builtin-mailinfo.c
  75. builtin-mailsplit.c
  76. builtin-merge-base.c
  77. builtin-merge-file.c
  78. builtin-merge-ours.c
  79. builtin-merge-recursive.c
  80. builtin-merge.c
  81. builtin-mktree.c
  82. builtin-mv.c
  83. builtin-name-rev.c
  84. builtin-pack-objects.c
  85. builtin-pack-refs.c
  86. builtin-prune-packed.c
  87. builtin-prune.c
  88. builtin-push.c
  89. builtin-read-tree.c
  90. builtin-receive-pack.c
  91. builtin-reflog.c
  92. builtin-remote.c
  93. builtin-rerere.c
  94. builtin-reset.c
  95. builtin-rev-list.c
  96. builtin-rev-parse.c
  97. builtin-revert.c
  98. builtin-rm.c
  99. builtin-send-pack.c
  100. builtin-shortlog.c
  101. builtin-show-branch.c
  102. builtin-show-ref.c
  103. builtin-stripspace.c
  104. builtin-symbolic-ref.c
  105. builtin-tag.c
  106. builtin-tar-tree.c
  107. builtin-unpack-objects.c
  108. builtin-update-index.c
  109. builtin-update-ref.c
  110. builtin-upload-archive.c
  111. builtin-verify-pack.c
  112. builtin-verify-tag.c
  113. builtin-write-tree.c
  114. builtin.h
  115. bundle.c
  116. bundle.h
  117. cache-tree.c
  118. cache-tree.h
  119. cache.h
  120. check-builtins.sh
  121. check-racy.c
  122. check_bindir
  123. color.c
  124. color.h
  125. combine-diff.c
  126. command-list.txt
  127. commit.c
  128. commit.h
  129. config.c
  130. config.mak.in
  131. configure.ac
  132. connect.c
  133. convert.c
  134. copy.c
  135. COPYING
  136. csum-file.c
  137. csum-file.h
  138. ctype.c
  139. daemon.c
  140. date.c
  141. decorate.c
  142. decorate.h
  143. delta.h
  144. diff-delta.c
  145. diff-lib.c
  146. diff-no-index.c
  147. diff.c
  148. diff.h
  149. diffcore-break.c
  150. diffcore-delta.c
  151. diffcore-order.c
  152. diffcore-pickaxe.c
  153. diffcore-rename.c
  154. diffcore.h
  155. dir.c
  156. dir.h
  157. editor.c
  158. entry.c
  159. environment.c
  160. exec_cmd.c
  161. exec_cmd.h
  162. fast-import.c
  163. fetch-pack.h
  164. fixup-builtins
  165. fsck.c
  166. fsck.h
  167. generate-cmdlist.sh
  168. git-add--interactive.perl
  169. git-am.sh
  170. git-archimport.perl
  171. git-bisect.sh
  172. git-compat-util.h
  173. git-cvsexportcommit.perl
  174. git-cvsimport.perl
  175. git-cvsserver.perl
  176. git-difftool--helper.sh
  177. git-difftool.perl
  178. git-filter-branch.sh
  179. git-instaweb.sh
  180. git-lost-found.sh
  181. git-merge-octopus.sh
  182. git-merge-one-file.sh
  183. git-merge-resolve.sh
  184. git-mergetool--lib.sh
  185. git-mergetool.sh
  186. git-parse-remote.sh
  187. git-pull.sh
  188. git-quiltimport.sh
  189. git-rebase--interactive.sh
  190. git-rebase.sh
  191. git-relink.perl
  192. git-repack.sh
  193. git-request-pull.sh
  194. git-send-email.perl
  195. git-sh-setup.sh
  196. git-stash.sh
  197. git-submodule.sh
  198. git-svn.perl
  199. GIT-VERSION-GEN
  200. git-web--browse.sh
  201. git.c
  202. git.spec.in
  203. graph.c
  204. graph.h
  205. grep.c
  206. grep.h
  207. hash-object.c
  208. hash.c
  209. hash.h
  210. help.c
  211. help.h
  212. http-push.c
  213. http-walker.c
  214. http.c
  215. http.h
  216. ident.c
  217. imap-send.c
  218. index-pack.c
  219. INSTALL
  220. levenshtein.c
  221. levenshtein.h
  222. list-objects.c
  223. list-objects.h
  224. ll-merge.c
  225. ll-merge.h
  226. lockfile.c
  227. log-tree.c
  228. log-tree.h
  229. mailmap.c
  230. mailmap.h
  231. Makefile
  232. match-trees.c
  233. merge-file.c
  234. merge-index.c
  235. merge-recursive.c
  236. merge-recursive.h
  237. merge-tree.c
  238. mktag.c
  239. name-hash.c
  240. object.c
  241. object.h
  242. pack-check.c
  243. pack-redundant.c
  244. pack-refs.c
  245. pack-refs.h
  246. pack-revindex.c
  247. pack-revindex.h
  248. pack-write.c
  249. pack.h
  250. pager.c
  251. parse-options.c
  252. parse-options.h
  253. patch-delta.c
  254. patch-id.c
  255. patch-ids.c
  256. patch-ids.h
  257. path.c
  258. pkt-line.c
  259. pkt-line.h
  260. preload-index.c
  261. pretty.c
  262. progress.c
  263. progress.h
  264. quote.c
  265. quote.h
  266. reachable.c
  267. reachable.h
  268. read-cache.c
  269. README
  270. reflog-walk.c
  271. reflog-walk.h
  272. refs.c
  273. refs.h
  274. remote.c
  275. remote.h
  276. rerere.c
  277. rerere.h
  278. revision.c
  279. revision.h
  280. run-command.c
  281. run-command.h
  282. send-pack.h
  283. server-info.c
  284. setup.c
  285. sha1-lookup.c
  286. sha1-lookup.h
  287. sha1_file.c
  288. sha1_name.c
  289. shallow.c
  290. shell.c
  291. shortlog.h
  292. show-index.c
  293. sideband.c
  294. sideband.h
  295. sigchain.c
  296. sigchain.h
  297. strbuf.c
  298. strbuf.h
  299. string-list.c
  300. string-list.h
  301. symlinks.c
  302. tag.c
  303. tag.h
  304. tar.h
  305. test-chmtime.c
  306. test-ctype.c
  307. test-date.c
  308. test-delta.c
  309. test-dump-cache-tree.c
  310. test-genrandom.c
  311. test-match-trees.c
  312. test-parse-options.c
  313. test-path-utils.c
  314. test-sha1.c
  315. test-sha1.sh
  316. test-sigchain.c
  317. thread-utils.c
  318. thread-utils.h
  319. trace.c
  320. transport.c
  321. transport.h
  322. tree-diff.c
  323. tree-walk.c
  324. tree-walk.h
  325. tree.c
  326. tree.h
  327. unimplemented.sh
  328. unpack-file.c
  329. unpack-trees.c
  330. unpack-trees.h
  331. update-server-info.c
  332. upload-pack.c
  333. usage.c
  334. userdiff.c
  335. userdiff.h
  336. utf8.c
  337. utf8.h
  338. var.c
  339. walker.c
  340. walker.h
  341. wrapper.c
  342. write_or_die.c
  343. ws.c
  344. wt-status.c
  345. wt-status.h
  346. xdiff-interface.c
  347. xdiff-interface.h