sha1-sparcv9a.pl 16 KB

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