sha1-sparcv9a.pl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. #! /usr/bin/env perl
  2. # Copyright 2009-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the OpenSSL license (the "License"). You may not use
  5. # this file except in compliance with the License. You can obtain a copy
  6. # in the file LICENSE in the source distribution or at
  7. # https://www.openssl.org/source/license.html
  8. # ====================================================================
  9. # Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
  10. # project. The module is, however, dual licensed under OpenSSL and
  11. # CRYPTOGAMS licenses depending on where you obtain it. For further
  12. # details see http://www.openssl.org/~appro/cryptogams/.
  13. # ====================================================================
  14. # January 2009
  15. #
  16. # Provided that UltraSPARC VIS instructions are pipe-lined(*) and
  17. # pairable(*) with IALU ones, offloading of Xupdate to the UltraSPARC
  18. # Graphic Unit would make it possible to achieve higher instruction-
  19. # level parallelism, ILP, and thus higher performance. It should be
  20. # explicitly noted that ILP is the keyword, and it means that this
  21. # code would be unsuitable for cores like UltraSPARC-Tx. The idea is
  22. # not really novel, Sun had VIS-powered implementation for a while.
  23. # Unlike Sun's implementation this one can process multiple unaligned
  24. # input blocks, and as such works as drop-in replacement for OpenSSL
  25. # sha1_block_data_order. Performance improvement was measured to be
  26. # 40% over pure IALU sha1-sparcv9.pl on UltraSPARC-IIi, but 12% on
  27. # UltraSPARC-III. See below for discussion...
  28. #
  29. # The module does not present direct interest for OpenSSL, because
  30. # it doesn't provide better performance on contemporary SPARCv9 CPUs,
  31. # UltraSPARC-Tx and SPARC64-V[II] to be specific. Those who feel they
  32. # absolutely must score on UltraSPARC-I-IV can simply replace
  33. # crypto/sha/asm/sha1-sparcv9.pl with this module.
  34. #
  35. # (*) "Pipe-lined" means that even if it takes several cycles to
  36. # complete, next instruction using same functional unit [but not
  37. # depending on the result of the current instruction] can start
  38. # execution without having to wait for the unit. "Pairable"
  39. # means that two [or more] independent instructions can be
  40. # issued at the very same time.
  41. $bits=32;
  42. for (@ARGV) { $bits=64 if (/\-m64/ || /\-xarch\=v9/); }
  43. if ($bits==64) { $bias=2047; $frame=192; }
  44. else { $bias=0; $frame=112; }
  45. $output=shift;
  46. open STDOUT,">$output";
  47. $ctx="%i0";
  48. $inp="%i1";
  49. $len="%i2";
  50. $tmp0="%i3";
  51. $tmp1="%i4";
  52. $tmp2="%i5";
  53. $tmp3="%g5";
  54. $base="%g1";
  55. $align="%g4";
  56. $Xfer="%o5";
  57. $nXfer=$tmp3;
  58. $Xi="%o7";
  59. $A="%l0";
  60. $B="%l1";
  61. $C="%l2";
  62. $D="%l3";
  63. $E="%l4";
  64. @V=($A,$B,$C,$D,$E);
  65. $Actx="%o0";
  66. $Bctx="%o1";
  67. $Cctx="%o2";
  68. $Dctx="%o3";
  69. $Ectx="%o4";
  70. $fmul="%f32";
  71. $VK_00_19="%f34";
  72. $VK_20_39="%f36";
  73. $VK_40_59="%f38";
  74. $VK_60_79="%f40";
  75. @VK=($VK_00_19,$VK_20_39,$VK_40_59,$VK_60_79);
  76. @X=("%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
  77. "%f8", "%f9","%f10","%f11","%f12","%f13","%f14","%f15","%f16");
  78. # This is reference 2x-parallelized VIS-powered Xupdate procedure. It
  79. # covers even K_NN_MM addition...
  80. sub Xupdate {
  81. my ($i)=@_;
  82. my $K=@VK[($i+16)/20];
  83. my $j=($i+16)%16;
  84. # [ provided that GSR.alignaddr_offset is 5, $mul contains
  85. # 0x100ULL<<32|0x100 value and K_NN_MM are pre-loaded to
  86. # chosen registers... ]
  87. $code.=<<___;
  88. fxors @X[($j+13)%16],@X[$j],@X[$j] !-1/-1/-1:X[0]^=X[13]
  89. fxors @X[($j+14)%16],@X[$j+1],@X[$j+1]! 0/ 0/ 0:X[1]^=X[14]
  90. fxor @X[($j+2)%16],@X[($j+8)%16],%f18! 1/ 1/ 1:Tmp=X[2,3]^X[8,9]
  91. fxor %f18,@X[$j],@X[$j] ! 2/ 4/ 3:X[0,1]^=X[2,3]^X[8,9]
  92. faligndata @X[$j],@X[$j],%f18 ! 3/ 7/ 5:Tmp=X[0,1]>>>24
  93. fpadd32 @X[$j],@X[$j],@X[$j] ! 4/ 8/ 6:X[0,1]<<=1
  94. fmul8ulx16 %f18,$fmul,%f18 ! 5/10/ 7:Tmp>>=7, Tmp&=1
  95. ![fxors %f15,%f2,%f2]
  96. for %f18,@X[$j],@X[$j] ! 8/14/10:X[0,1]|=Tmp
  97. ![fxors %f0,%f3,%f3] !10/17/12:X[0] dependency
  98. fpadd32 $K,@X[$j],%f20
  99. std %f20,[$Xfer+`4*$j`]
  100. ___
  101. # The numbers delimited with slash are the earliest possible dispatch
  102. # cycles for given instruction assuming 1 cycle latency for simple VIS
  103. # instructions, such as on UltraSPARC-I&II, 3 cycles latency, such as
  104. # on UltraSPARC-III&IV, and 2 cycles latency(*), respectively. Being
  105. # 2x-parallelized the procedure is "worth" 5, 8.5 or 6 ticks per SHA1
  106. # round. As [long as] FPU/VIS instructions are perfectly pairable with
  107. # IALU ones, the round timing is defined by the maximum between VIS
  108. # and IALU timings. The latter varies from round to round and averages
  109. # out at 6.25 ticks. This means that USI&II should operate at IALU
  110. # rate, while USIII&IV - at VIS rate. This explains why performance
  111. # improvement varies among processors. Well, given that pure IALU
  112. # sha1-sparcv9.pl module exhibits virtually uniform performance of
  113. # ~9.3 cycles per SHA1 round. Timings mentioned above are theoretical
  114. # lower limits. Real-life performance was measured to be 6.6 cycles
  115. # per SHA1 round on USIIi and 8.3 on USIII. The latter is lower than
  116. # half-round VIS timing, because there are 16 Xupdate-free rounds,
  117. # which "push down" average theoretical timing to 8 cycles...
  118. # (*) SPARC64-V[II] was originally believed to have 2 cycles VIS
  119. # latency. Well, it might have, but it doesn't have dedicated
  120. # VIS-unit. Instead, VIS instructions are executed by other
  121. # functional units, ones used here - by IALU. This doesn't
  122. # improve effective ILP...
  123. }
  124. # The reference Xupdate procedure is then "strained" over *pairs* of
  125. # BODY_NN_MM and kind of modulo-scheduled in respect to X[n]^=X[n+13]
  126. # and K_NN_MM addition. It's "running" 15 rounds ahead, which leaves
  127. # plenty of room to amortize for read-after-write hazard, as well as
  128. # to fetch and align input for the next spin. The VIS instructions are
  129. # scheduled for latency of 2 cycles, because there are not enough IALU
  130. # instructions to schedule for latency of 3, while scheduling for 1
  131. # would give no gain on USI&II anyway.
  132. sub BODY_00_19 {
  133. my ($i,$a,$b,$c,$d,$e)=@_;
  134. my $j=$i&~1;
  135. my $k=($j+16+2)%16; # ahead reference
  136. my $l=($j+16-2)%16; # behind reference
  137. my $K=@VK[($j+16-2)/20];
  138. $j=($j+16)%16;
  139. $code.=<<___ if (!($i&1));
  140. sll $a,5,$tmp0 !! $i
  141. and $c,$b,$tmp3
  142. ld [$Xfer+`4*($i%16)`],$Xi
  143. fxors @X[($j+14)%16],@X[$j+1],@X[$j+1]! 0/ 0/ 0:X[1]^=X[14]
  144. srl $a,27,$tmp1
  145. add $tmp0,$e,$e
  146. fxor @X[($j+2)%16],@X[($j+8)%16],%f18! 1/ 1/ 1:Tmp=X[2,3]^X[8,9]
  147. sll $b,30,$tmp2
  148. add $tmp1,$e,$e
  149. andn $d,$b,$tmp1
  150. add $Xi,$e,$e
  151. fxor %f18,@X[$j],@X[$j] ! 2/ 4/ 3:X[0,1]^=X[2,3]^X[8,9]
  152. srl $b,2,$b
  153. or $tmp1,$tmp3,$tmp1
  154. or $tmp2,$b,$b
  155. add $tmp1,$e,$e
  156. faligndata @X[$j],@X[$j],%f18 ! 3/ 7/ 5:Tmp=X[0,1]>>>24
  157. ___
  158. $code.=<<___ if ($i&1);
  159. sll $a,5,$tmp0 !! $i
  160. and $c,$b,$tmp3
  161. ld [$Xfer+`4*($i%16)`],$Xi
  162. fpadd32 @X[$j],@X[$j],@X[$j] ! 4/ 8/ 6:X[0,1]<<=1
  163. srl $a,27,$tmp1
  164. add $tmp0,$e,$e
  165. fmul8ulx16 %f18,$fmul,%f18 ! 5/10/ 7:Tmp>>=7, Tmp&=1
  166. sll $b,30,$tmp2
  167. add $tmp1,$e,$e
  168. fpadd32 $K,@X[$l],%f20 !
  169. andn $d,$b,$tmp1
  170. add $Xi,$e,$e
  171. fxors @X[($k+13)%16],@X[$k],@X[$k] !-1/-1/-1:X[0]^=X[13]
  172. srl $b,2,$b
  173. or $tmp1,$tmp3,$tmp1
  174. fxor %f18,@X[$j],@X[$j] ! 8/14/10:X[0,1]|=Tmp
  175. or $tmp2,$b,$b
  176. add $tmp1,$e,$e
  177. ___
  178. $code.=<<___ if ($i&1 && $i>=2);
  179. std %f20,[$Xfer+`4*$l`] !
  180. ___
  181. }
  182. sub BODY_20_39 {
  183. my ($i,$a,$b,$c,$d,$e)=@_;
  184. my $j=$i&~1;
  185. my $k=($j+16+2)%16; # ahead reference
  186. my $l=($j+16-2)%16; # behind reference
  187. my $K=@VK[($j+16-2)/20];
  188. $j=($j+16)%16;
  189. $code.=<<___ if (!($i&1) && $i<64);
  190. sll $a,5,$tmp0 !! $i
  191. ld [$Xfer+`4*($i%16)`],$Xi
  192. fxors @X[($j+14)%16],@X[$j+1],@X[$j+1]! 0/ 0/ 0:X[1]^=X[14]
  193. srl $a,27,$tmp1
  194. add $tmp0,$e,$e
  195. fxor @X[($j+2)%16],@X[($j+8)%16],%f18! 1/ 1/ 1:Tmp=X[2,3]^X[8,9]
  196. xor $c,$b,$tmp0
  197. add $tmp1,$e,$e
  198. sll $b,30,$tmp2
  199. xor $d,$tmp0,$tmp1
  200. fxor %f18,@X[$j],@X[$j] ! 2/ 4/ 3:X[0,1]^=X[2,3]^X[8,9]
  201. srl $b,2,$b
  202. add $tmp1,$e,$e
  203. or $tmp2,$b,$b
  204. add $Xi,$e,$e
  205. faligndata @X[$j],@X[$j],%f18 ! 3/ 7/ 5:Tmp=X[0,1]>>>24
  206. ___
  207. $code.=<<___ if ($i&1 && $i<64);
  208. sll $a,5,$tmp0 !! $i
  209. ld [$Xfer+`4*($i%16)`],$Xi
  210. fpadd32 @X[$j],@X[$j],@X[$j] ! 4/ 8/ 6:X[0,1]<<=1
  211. srl $a,27,$tmp1
  212. add $tmp0,$e,$e
  213. fmul8ulx16 %f18,$fmul,%f18 ! 5/10/ 7:Tmp>>=7, Tmp&=1
  214. xor $c,$b,$tmp0
  215. add $tmp1,$e,$e
  216. fpadd32 $K,@X[$l],%f20 !
  217. sll $b,30,$tmp2
  218. xor $d,$tmp0,$tmp1
  219. fxors @X[($k+13)%16],@X[$k],@X[$k] !-1/-1/-1:X[0]^=X[13]
  220. srl $b,2,$b
  221. add $tmp1,$e,$e
  222. fxor %f18,@X[$j],@X[$j] ! 8/14/10:X[0,1]|=Tmp
  223. or $tmp2,$b,$b
  224. add $Xi,$e,$e
  225. std %f20,[$Xfer+`4*$l`] !
  226. ___
  227. $code.=<<___ if ($i==64);
  228. sll $a,5,$tmp0 !! $i
  229. ld [$Xfer+`4*($i%16)`],$Xi
  230. fpadd32 $K,@X[$l],%f20
  231. srl $a,27,$tmp1
  232. add $tmp0,$e,$e
  233. xor $c,$b,$tmp0
  234. add $tmp1,$e,$e
  235. sll $b,30,$tmp2
  236. xor $d,$tmp0,$tmp1
  237. std %f20,[$Xfer+`4*$l`]
  238. srl $b,2,$b
  239. add $tmp1,$e,$e
  240. or $tmp2,$b,$b
  241. add $Xi,$e,$e
  242. ___
  243. $code.=<<___ if ($i>64);
  244. sll $a,5,$tmp0 !! $i
  245. ld [$Xfer+`4*($i%16)`],$Xi
  246. srl $a,27,$tmp1
  247. add $tmp0,$e,$e
  248. xor $c,$b,$tmp0
  249. add $tmp1,$e,$e
  250. sll $b,30,$tmp2
  251. xor $d,$tmp0,$tmp1
  252. srl $b,2,$b
  253. add $tmp1,$e,$e
  254. or $tmp2,$b,$b
  255. add $Xi,$e,$e
  256. ___
  257. }
  258. sub BODY_40_59 {
  259. my ($i,$a,$b,$c,$d,$e)=@_;
  260. my $j=$i&~1;
  261. my $k=($j+16+2)%16; # ahead reference
  262. my $l=($j+16-2)%16; # behind reference
  263. my $K=@VK[($j+16-2)/20];
  264. $j=($j+16)%16;
  265. $code.=<<___ if (!($i&1));
  266. sll $a,5,$tmp0 !! $i
  267. ld [$Xfer+`4*($i%16)`],$Xi
  268. fxors @X[($j+14)%16],@X[$j+1],@X[$j+1]! 0/ 0/ 0:X[1]^=X[14]
  269. srl $a,27,$tmp1
  270. add $tmp0,$e,$e
  271. fxor @X[($j+2)%16],@X[($j+8)%16],%f18! 1/ 1/ 1:Tmp=X[2,3]^X[8,9]
  272. and $c,$b,$tmp0
  273. add $tmp1,$e,$e
  274. sll $b,30,$tmp2
  275. or $c,$b,$tmp1
  276. fxor %f18,@X[$j],@X[$j] ! 2/ 4/ 3:X[0,1]^=X[2,3]^X[8,9]
  277. srl $b,2,$b
  278. and $d,$tmp1,$tmp1
  279. add $Xi,$e,$e
  280. or $tmp1,$tmp0,$tmp1
  281. faligndata @X[$j],@X[$j],%f18 ! 3/ 7/ 5:Tmp=X[0,1]>>>24
  282. or $tmp2,$b,$b
  283. add $tmp1,$e,$e
  284. fpadd32 @X[$j],@X[$j],@X[$j] ! 4/ 8/ 6:X[0,1]<<=1
  285. ___
  286. $code.=<<___ if ($i&1);
  287. sll $a,5,$tmp0 !! $i
  288. ld [$Xfer+`4*($i%16)`],$Xi
  289. srl $a,27,$tmp1
  290. add $tmp0,$e,$e
  291. fmul8ulx16 %f18,$fmul,%f18 ! 5/10/ 7:Tmp>>=7, Tmp&=1
  292. and $c,$b,$tmp0
  293. add $tmp1,$e,$e
  294. fpadd32 $K,@X[$l],%f20 !
  295. sll $b,30,$tmp2
  296. or $c,$b,$tmp1
  297. fxors @X[($k+13)%16],@X[$k],@X[$k] !-1/-1/-1:X[0]^=X[13]
  298. srl $b,2,$b
  299. and $d,$tmp1,$tmp1
  300. fxor %f18,@X[$j],@X[$j] ! 8/14/10:X[0,1]|=Tmp
  301. add $Xi,$e,$e
  302. or $tmp1,$tmp0,$tmp1
  303. or $tmp2,$b,$b
  304. add $tmp1,$e,$e
  305. std %f20,[$Xfer+`4*$l`] !
  306. ___
  307. }
  308. # If there is more data to process, then we pre-fetch the data for
  309. # next iteration in last ten rounds...
  310. sub BODY_70_79 {
  311. my ($i,$a,$b,$c,$d,$e)=@_;
  312. my $j=$i&~1;
  313. my $m=($i%8)*2;
  314. $j=($j+16)%16;
  315. $code.=<<___ if ($i==70);
  316. sll $a,5,$tmp0 !! $i
  317. ld [$Xfer+`4*($i%16)`],$Xi
  318. srl $a,27,$tmp1
  319. add $tmp0,$e,$e
  320. ldd [$inp+64],@X[0]
  321. xor $c,$b,$tmp0
  322. add $tmp1,$e,$e
  323. sll $b,30,$tmp2
  324. xor $d,$tmp0,$tmp1
  325. srl $b,2,$b
  326. add $tmp1,$e,$e
  327. or $tmp2,$b,$b
  328. add $Xi,$e,$e
  329. and $inp,-64,$nXfer
  330. inc 64,$inp
  331. and $nXfer,255,$nXfer
  332. alignaddr %g0,$align,%g0
  333. add $base,$nXfer,$nXfer
  334. ___
  335. $code.=<<___ if ($i==71);
  336. sll $a,5,$tmp0 !! $i
  337. ld [$Xfer+`4*($i%16)`],$Xi
  338. srl $a,27,$tmp1
  339. add $tmp0,$e,$e
  340. xor $c,$b,$tmp0
  341. add $tmp1,$e,$e
  342. sll $b,30,$tmp2
  343. xor $d,$tmp0,$tmp1
  344. srl $b,2,$b
  345. add $tmp1,$e,$e
  346. or $tmp2,$b,$b
  347. add $Xi,$e,$e
  348. ___
  349. $code.=<<___ if ($i>=72);
  350. faligndata @X[$m],@X[$m+2],@X[$m]
  351. sll $a,5,$tmp0 !! $i
  352. ld [$Xfer+`4*($i%16)`],$Xi
  353. srl $a,27,$tmp1
  354. add $tmp0,$e,$e
  355. xor $c,$b,$tmp0
  356. add $tmp1,$e,$e
  357. fpadd32 $VK_00_19,@X[$m],%f20
  358. sll $b,30,$tmp2
  359. xor $d,$tmp0,$tmp1
  360. srl $b,2,$b
  361. add $tmp1,$e,$e
  362. or $tmp2,$b,$b
  363. add $Xi,$e,$e
  364. ___
  365. $code.=<<___ if ($i<77);
  366. ldd [$inp+`8*($i+1-70)`],@X[2*($i+1-70)]
  367. ___
  368. $code.=<<___ if ($i==77); # redundant if $inp was aligned
  369. add $align,63,$tmp0
  370. and $tmp0,-8,$tmp0
  371. ldd [$inp+$tmp0],@X[16]
  372. ___
  373. $code.=<<___ if ($i>=72);
  374. std %f20,[$nXfer+`4*$m`]
  375. ___
  376. }
  377. $code.=<<___;
  378. .section ".text",#alloc,#execinstr
  379. .align 64
  380. vis_const:
  381. .long 0x5a827999,0x5a827999 ! K_00_19
  382. .long 0x6ed9eba1,0x6ed9eba1 ! K_20_39
  383. .long 0x8f1bbcdc,0x8f1bbcdc ! K_40_59
  384. .long 0xca62c1d6,0xca62c1d6 ! K_60_79
  385. .long 0x00000100,0x00000100
  386. .align 64
  387. .type vis_const,#object
  388. .size vis_const,(.-vis_const)
  389. .globl sha1_block_data_order
  390. sha1_block_data_order:
  391. save %sp,-$frame,%sp
  392. add %fp,$bias-256,$base
  393. 1: call .+8
  394. add %o7,vis_const-1b,$tmp0
  395. ldd [$tmp0+0],$VK_00_19
  396. ldd [$tmp0+8],$VK_20_39
  397. ldd [$tmp0+16],$VK_40_59
  398. ldd [$tmp0+24],$VK_60_79
  399. ldd [$tmp0+32],$fmul
  400. ld [$ctx+0],$Actx
  401. and $base,-256,$base
  402. ld [$ctx+4],$Bctx
  403. sub $base,$bias+$frame,%sp
  404. ld [$ctx+8],$Cctx
  405. and $inp,7,$align
  406. ld [$ctx+12],$Dctx
  407. and $inp,-8,$inp
  408. ld [$ctx+16],$Ectx
  409. ! X[16] is maintained in FP register bank
  410. alignaddr %g0,$align,%g0
  411. ldd [$inp+0],@X[0]
  412. sub $inp,-64,$Xfer
  413. ldd [$inp+8],@X[2]
  414. and $Xfer,-64,$Xfer
  415. ldd [$inp+16],@X[4]
  416. and $Xfer,255,$Xfer
  417. ldd [$inp+24],@X[6]
  418. add $base,$Xfer,$Xfer
  419. ldd [$inp+32],@X[8]
  420. ldd [$inp+40],@X[10]
  421. ldd [$inp+48],@X[12]
  422. brz,pt $align,.Laligned
  423. ldd [$inp+56],@X[14]
  424. ldd [$inp+64],@X[16]
  425. faligndata @X[0],@X[2],@X[0]
  426. faligndata @X[2],@X[4],@X[2]
  427. faligndata @X[4],@X[6],@X[4]
  428. faligndata @X[6],@X[8],@X[6]
  429. faligndata @X[8],@X[10],@X[8]
  430. faligndata @X[10],@X[12],@X[10]
  431. faligndata @X[12],@X[14],@X[12]
  432. faligndata @X[14],@X[16],@X[14]
  433. .Laligned:
  434. mov 5,$tmp0
  435. dec 1,$len
  436. alignaddr %g0,$tmp0,%g0
  437. fpadd32 $VK_00_19,@X[0],%f16
  438. fpadd32 $VK_00_19,@X[2],%f18
  439. fpadd32 $VK_00_19,@X[4],%f20
  440. fpadd32 $VK_00_19,@X[6],%f22
  441. fpadd32 $VK_00_19,@X[8],%f24
  442. fpadd32 $VK_00_19,@X[10],%f26
  443. fpadd32 $VK_00_19,@X[12],%f28
  444. fpadd32 $VK_00_19,@X[14],%f30
  445. std %f16,[$Xfer+0]
  446. mov $Actx,$A
  447. std %f18,[$Xfer+8]
  448. mov $Bctx,$B
  449. std %f20,[$Xfer+16]
  450. mov $Cctx,$C
  451. std %f22,[$Xfer+24]
  452. mov $Dctx,$D
  453. std %f24,[$Xfer+32]
  454. mov $Ectx,$E
  455. std %f26,[$Xfer+40]
  456. fxors @X[13],@X[0],@X[0]
  457. std %f28,[$Xfer+48]
  458. ba .Loop
  459. std %f30,[$Xfer+56]
  460. .align 32
  461. .Loop:
  462. ___
  463. for ($i=0;$i<20;$i++) { &BODY_00_19($i,@V); unshift(@V,pop(@V)); }
  464. for (;$i<40;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
  465. for (;$i<60;$i++) { &BODY_40_59($i,@V); unshift(@V,pop(@V)); }
  466. for (;$i<70;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
  467. $code.=<<___;
  468. tst $len
  469. bz,pn `$bits==32?"%icc":"%xcc"`,.Ltail
  470. nop
  471. ___
  472. for (;$i<80;$i++) { &BODY_70_79($i,@V); unshift(@V,pop(@V)); }
  473. $code.=<<___;
  474. add $A,$Actx,$Actx
  475. add $B,$Bctx,$Bctx
  476. add $C,$Cctx,$Cctx
  477. add $D,$Dctx,$Dctx
  478. add $E,$Ectx,$Ectx
  479. mov 5,$tmp0
  480. fxors @X[13],@X[0],@X[0]
  481. mov $Actx,$A
  482. mov $Bctx,$B
  483. mov $Cctx,$C
  484. mov $Dctx,$D
  485. mov $Ectx,$E
  486. alignaddr %g0,$tmp0,%g0
  487. dec 1,$len
  488. ba .Loop
  489. mov $nXfer,$Xfer
  490. .align 32
  491. .Ltail:
  492. ___
  493. for($i=70;$i<80;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
  494. $code.=<<___;
  495. add $A,$Actx,$Actx
  496. add $B,$Bctx,$Bctx
  497. add $C,$Cctx,$Cctx
  498. add $D,$Dctx,$Dctx
  499. add $E,$Ectx,$Ectx
  500. st $Actx,[$ctx+0]
  501. st $Bctx,[$ctx+4]
  502. st $Cctx,[$ctx+8]
  503. st $Dctx,[$ctx+12]
  504. st $Ectx,[$ctx+16]
  505. ret
  506. restore
  507. .type sha1_block_data_order,#function
  508. .size sha1_block_data_order,(.-sha1_block_data_order)
  509. .asciz "SHA1 block transform for SPARCv9a, CRYPTOGAMS by <appro\@openssl.org>"
  510. .align 4
  511. ___
  512. # Purpose of these subroutines is to explicitly encode VIS instructions,
  513. # so that one can compile the module without having to specify VIS
  514. # extensions on compiler command line, e.g. -xarch=v9 vs. -xarch=v9a.
  515. # Idea is to reserve for option to produce "universal" binary and let
  516. # programmer detect if current CPU is VIS capable at run-time.
  517. sub unvis {
  518. my ($mnemonic,$rs1,$rs2,$rd)=@_;
  519. my ($ref,$opf);
  520. my %visopf = ( "fmul8ulx16" => 0x037,
  521. "faligndata" => 0x048,
  522. "fpadd32" => 0x052,
  523. "fxor" => 0x06c,
  524. "fxors" => 0x06d );
  525. $ref = "$mnemonic\t$rs1,$rs2,$rd";
  526. if ($opf=$visopf{$mnemonic}) {
  527. foreach ($rs1,$rs2,$rd) {
  528. return $ref if (!/%f([0-9]{1,2})/);
  529. $_=$1;
  530. if ($1>=32) {
  531. return $ref if ($1&1);
  532. # re-encode for upper double register addressing
  533. $_=($1|$1>>5)&31;
  534. }
  535. }
  536. return sprintf ".word\t0x%08x !%s",
  537. 0x81b00000|$rd<<25|$rs1<<14|$opf<<5|$rs2,
  538. $ref;
  539. } else {
  540. return $ref;
  541. }
  542. }
  543. sub unalignaddr {
  544. my ($mnemonic,$rs1,$rs2,$rd)=@_;
  545. my %bias = ( "g" => 0, "o" => 8, "l" => 16, "i" => 24 );
  546. my $ref="$mnemonic\t$rs1,$rs2,$rd";
  547. foreach ($rs1,$rs2,$rd) {
  548. if (/%([goli])([0-7])/) { $_=$bias{$1}+$2; }
  549. else { return $ref; }
  550. }
  551. return sprintf ".word\t0x%08x !%s",
  552. 0x81b00300|$rd<<25|$rs1<<14|$rs2,
  553. $ref;
  554. }
  555. $code =~ s/\`([^\`]*)\`/eval $1/gem;
  556. $code =~ s/\b(f[^\s]*)\s+(%f[0-9]{1,2}),(%f[0-9]{1,2}),(%f[0-9]{1,2})/
  557. &unvis($1,$2,$3,$4)
  558. /gem;
  559. $code =~ s/\b(alignaddr)\s+(%[goli][0-7]),(%[goli][0-7]),(%[goli][0-7])/
  560. &unalignaddr($1,$2,$3,$4)
  561. /gem;
  562. print $code;
  563. close STDOUT;