sha1-ia64.pl 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. #!/usr/bin/env perl
  2. #
  3. # ====================================================================
  4. # Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
  5. # project. Rights for redistribution and usage in source and binary
  6. # forms are granted according to the OpenSSL license.
  7. # ====================================================================
  8. #
  9. # Eternal question is what's wrong with compiler generated code? The
  10. # trick is that it's possible to reduce the number of shifts required
  11. # to perform rotations by maintaining copy of 32-bit value in upper
  12. # bits of 64-bit register. Just follow mux2 and shrp instructions...
  13. # Performance under big-endian OS such as HP-UX is 179MBps*1GHz, which
  14. # is >50% better than HP C and >2x better than gcc. As of this moment
  15. # performance under little-endian OS such as Linux and Windows will be
  16. # a bit lower, because data has to be picked in reverse byte-order.
  17. # It's possible to resolve this issue by implementing third function,
  18. # sha1_block_asm_data_order_aligned, which would temporarily flip
  19. # BE field in User Mask register...
  20. $code=<<___;
  21. .ident \"sha1-ia64.s, version 1.0\"
  22. .ident \"IA-64 ISA artwork by Andy Polyakov <appro\@fy.chalmers.se>\"
  23. .explicit
  24. ___
  25. if ($^O eq "hpux") {
  26. $ADDP="addp4";
  27. for (@ARGV) { $ADDP="add" if (/[\+DD|\-mlp]64/); }
  28. } else { $ADDP="add"; }
  29. for (@ARGV) { $big_endian=1 if (/\-DB_ENDIAN/);
  30. $big_endian=0 if (/\-DL_ENDIAN/); }
  31. if (!defined($big_endian))
  32. { $big_endian=(unpack('L',pack('N',1))==1); }
  33. #$human=1;
  34. if ($human) { # useful for visual code auditing...
  35. ($A,$B,$C,$D,$E,$T) = ("A","B","C","D","E","T");
  36. ($h0,$h1,$h2,$h3,$h4) = ("h0","h1","h2","h3","h4");
  37. ($K_00_19, $K_20_39, $K_40_59, $K_60_79) =
  38. ( "K_00_19","K_20_39","K_40_59","K_60_79" );
  39. @X= ( "X0", "X1", "X2", "X3", "X4", "X5", "X6", "X7",
  40. "X8", "X9","X10","X11","X12","X13","X14","X15" );
  41. }
  42. else {
  43. ($A,$B,$C,$D,$E,$T) = ("loc0","loc1","loc2","loc3","loc4","loc5");
  44. ($h0,$h1,$h2,$h3,$h4) = ("loc6","loc7","loc8","loc9","loc10");
  45. ($K_00_19, $K_20_39, $K_40_59, $K_60_79) =
  46. ( "r14", "r15", "loc11", "loc12" );
  47. @X= ( "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
  48. "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" );
  49. }
  50. sub BODY_00_15 {
  51. local *code=shift;
  52. local ($i,$a,$b,$c,$d,$e,$f,$unaligned)=@_;
  53. if ($unaligned) {
  54. $code.=<<___;
  55. { .mmi; ld1 tmp0=[inp],2 // MSB
  56. ld1 tmp1=[tmp3],2 };;
  57. { .mmi; ld1 tmp2=[inp],2
  58. ld1 $X[$i&0xf]=[tmp3],2 // LSB
  59. dep tmp1=tmp0,tmp1,8,8 };;
  60. { .mii; cmp.ne p16,p0=r0,r0 // no misaligned prefetch
  61. dep $X[$i&0xf]=tmp2,$X[$i&0xf],8,8;;
  62. dep $X[$i&0xf]=tmp1,$X[$i&0xf],16,16 };;
  63. { .mmi; nop.m 0
  64. ___
  65. }
  66. elsif ($i<15) {
  67. $code.=<<___;
  68. { .mmi; ld4 $X[($i+1)&0xf]=[inp],4 // prefetch
  69. ___
  70. }
  71. else {
  72. $code.=<<___;
  73. { .mmi; nop.m 0
  74. ___
  75. }
  76. if ($i<15) {
  77. $code.=<<___;
  78. and tmp0=$c,$b
  79. dep.z tmp5=$a,5,27 } // a<<5
  80. { .mmi; andcm tmp1=$d,$b
  81. add tmp4=$e,$K_00_19 };;
  82. { .mmi; or tmp0=tmp0,tmp1 // F_00_19(b,c,d)=(b&c)|(~b&d)
  83. add $f=tmp4,$X[$i&0xf] // f=xi+e+K_00_19
  84. extr.u tmp1=$a,27,5 };; // a>>27
  85. { .mib; add $f=$f,tmp0 // f+=F_00_19(b,c,d)
  86. shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30)
  87. { .mib; or tmp1=tmp1,tmp5 // ROTATE(a,5)
  88. mux2 tmp6=$a,0x44 };; // see b in next iteration
  89. { .mii; add $f=$f,tmp1 // f+=ROTATE(a,5)
  90. mux2 $X[$i&0xf]=$X[$i&0xf],0x44
  91. nop.i 0 };;
  92. ___
  93. }
  94. else {
  95. $code.=<<___;
  96. and tmp0=$c,$b
  97. dep.z tmp5=$a,5,27 } // a<<5 ;;?
  98. { .mmi; andcm tmp1=$d,$b
  99. add tmp4=$e,$K_00_19 };;
  100. { .mmi; or tmp0=tmp0,tmp1 // F_00_19(b,c,d)=(b&c)|(~b&d)
  101. add $f=tmp4,$X[$i&0xf] // f=xi+e+K_00_19
  102. extr.u tmp1=$a,27,5 } // a>>27
  103. { .mmi; xor tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf] // +1
  104. xor tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1
  105. nop.i 0 };;
  106. { .mmi; add $f=$f,tmp0 // f+=F_00_19(b,c,d)
  107. xor tmp2=tmp2,tmp3 // +1
  108. shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30)
  109. { .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5)
  110. mux2 tmp6=$a,0x44 };; // see b in next iteration
  111. { .mii; add $f=$f,tmp1 // f+=ROTATE(a,5)
  112. shrp $e=tmp2,tmp2,31 // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1)
  113. mux2 $X[$i&0xf]=$X[$i&0xf],0x44 };;
  114. ___
  115. }
  116. }
  117. sub BODY_16_19 {
  118. local *code=shift;
  119. local ($i,$a,$b,$c,$d,$e,$f)=@_;
  120. $code.=<<___;
  121. { .mmi; mov $X[$i&0xf]=$f // Xupdate
  122. and tmp0=$c,$b
  123. dep.z tmp5=$a,5,27 } // a<<5
  124. { .mmi; andcm tmp1=$d,$b
  125. add tmp4=$e,$K_00_19 };;
  126. { .mmi; or tmp0=tmp0,tmp1 // F_00_19(b,c,d)=(b&c)|(~b&d)
  127. add $f=$f,tmp4 // f+=e+K_00_19
  128. extr.u tmp1=$a,27,5 } // a>>27
  129. { .mmi; xor tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf] // +1
  130. xor tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1
  131. nop.i 0 };;
  132. { .mmi; add $f=$f,tmp0 // f+=F_00_19(b,c,d)
  133. xor tmp2=tmp2,tmp3 // +1
  134. shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30)
  135. { .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5)
  136. mux2 tmp6=$a,0x44 };; // see b in next iteration
  137. { .mii; add $f=$f,tmp1 // f+=ROTATE(a,5)
  138. shrp $e=tmp2,tmp2,31 // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1)
  139. nop.i 0 };;
  140. ___
  141. }
  142. sub BODY_20_39 {
  143. local *code=shift;
  144. local ($i,$a,$b,$c,$d,$e,$f,$Konst)=@_;
  145. $Konst = $K_20_39 if (!defined($Konst));
  146. if ($i<79) {
  147. $code.=<<___;
  148. { .mib; mov $X[$i&0xf]=$f // Xupdate
  149. dep.z tmp5=$a,5,27 } // a<<5
  150. { .mib; xor tmp0=$c,$b
  151. add tmp4=$e,$Konst };;
  152. { .mmi; xor tmp0=tmp0,$d // F_20_39(b,c,d)=b^c^d
  153. add $f=$f,tmp4 // f+=e+K_20_39
  154. extr.u tmp1=$a,27,5 } // a>>27
  155. { .mmi; xor tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf] // +1
  156. xor tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1
  157. nop.i 0 };;
  158. { .mmi; add $f=$f,tmp0 // f+=F_20_39(b,c,d)
  159. xor tmp2=tmp2,tmp3 // +1
  160. shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30)
  161. { .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5)
  162. mux2 tmp6=$a,0x44 };; // see b in next iteration
  163. { .mii; add $f=$f,tmp1 // f+=ROTATE(a,5)
  164. shrp $e=tmp2,tmp2,31 // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1)
  165. nop.i 0 };;
  166. ___
  167. }
  168. else {
  169. $code.=<<___;
  170. { .mib; mov $X[$i&0xf]=$f // Xupdate
  171. dep.z tmp5=$a,5,27 } // a<<5
  172. { .mib; xor tmp0=$c,$b
  173. add tmp4=$e,$Konst };;
  174. { .mib; xor tmp0=tmp0,$d // F_20_39(b,c,d)=b^c^d
  175. extr.u tmp1=$a,27,5 } // a>>27
  176. { .mib; add $f=$f,tmp4 // f+=e+K_20_39
  177. add $h1=$h1,$a };; // wrap up
  178. { .mmi;
  179. (p16) ld4.s $X[0]=[inp],4 // non-faulting prefetch
  180. add $f=$f,tmp0 // f+=F_20_39(b,c,d)
  181. shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30) ;;?
  182. { .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5)
  183. add $h3=$h3,$c };; // wrap up
  184. { .mib; add tmp3=1,inp // used in unaligned codepath
  185. add $f=$f,tmp1 } // f+=ROTATE(a,5)
  186. { .mib; add $h2=$h2,$b // wrap up
  187. add $h4=$h4,$d };; // wrap up
  188. ___
  189. }
  190. }
  191. sub BODY_40_59 {
  192. local *code=shift;
  193. local ($i,$a,$b,$c,$d,$e,$f)=@_;
  194. $code.=<<___;
  195. { .mmi; mov $X[$i&0xf]=$f // Xupdate
  196. and tmp0=$c,$b
  197. dep.z tmp5=$a,5,27 } // a<<5
  198. { .mmi; and tmp1=$d,$b
  199. add tmp4=$e,$K_40_59 };;
  200. { .mmi; or tmp0=tmp0,tmp1 // (b&c)|(b&d)
  201. add $f=$f,tmp4 // f+=e+K_40_59
  202. extr.u tmp1=$a,27,5 } // a>>27
  203. { .mmi; and tmp4=$c,$d
  204. xor tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf] // +1
  205. xor tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1
  206. };;
  207. { .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5)
  208. xor tmp2=tmp2,tmp3 // +1
  209. shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30)
  210. { .mmi; or tmp0=tmp0,tmp4 // F_40_59(b,c,d)=(b&c)|(b&d)|(c&d)
  211. mux2 tmp6=$a,0x44 };; // see b in next iteration
  212. { .mii; add $f=$f,tmp0 // f+=F_40_59(b,c,d)
  213. shrp $e=tmp2,tmp2,31;; // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1)
  214. add $f=$f,tmp1 };; // f+=ROTATE(a,5)
  215. ___
  216. }
  217. sub BODY_60_79 { &BODY_20_39(@_,$K_60_79); }
  218. $code.=<<___;
  219. .text
  220. tmp0=r8;
  221. tmp1=r9;
  222. tmp2=r10;
  223. tmp3=r11;
  224. ctx=r32; // in0
  225. inp=r33; // in1
  226. // void sha1_block_asm_host_order(SHA_CTX *c,const void *p,size_t num);
  227. .global sha1_block_asm_host_order#
  228. .proc sha1_block_asm_host_order#
  229. .align 32
  230. sha1_block_asm_host_order:
  231. .prologue
  232. { .mmi; alloc tmp1=ar.pfs,3,15,0,0
  233. $ADDP tmp0=4,ctx
  234. .save ar.lc,r3
  235. mov r3=ar.lc }
  236. { .mmi; $ADDP ctx=0,ctx
  237. $ADDP inp=0,inp
  238. mov r2=pr };;
  239. tmp4=in2;
  240. tmp5=loc13;
  241. tmp6=loc14;
  242. .body
  243. { .mlx; ld4 $h0=[ctx],8
  244. movl $K_00_19=0x5a827999 }
  245. { .mlx; ld4 $h1=[tmp0],8
  246. movl $K_20_39=0x6ed9eba1 };;
  247. { .mlx; ld4 $h2=[ctx],8
  248. movl $K_40_59=0x8f1bbcdc }
  249. { .mlx; ld4 $h3=[tmp0]
  250. movl $K_60_79=0xca62c1d6 };;
  251. { .mmi; ld4 $h4=[ctx],-16
  252. add in2=-1,in2 // adjust num for ar.lc
  253. mov ar.ec=1 };;
  254. { .mmi; ld4 $X[0]=[inp],4 // prefetch
  255. cmp.ne p16,p0=r0,in2 // prefecth at loop end
  256. mov ar.lc=in2 };; // brp.loop.imp: too far
  257. .Lhtop:
  258. { .mmi; mov $A=$h0
  259. mov $B=$h1
  260. mux2 tmp6=$h1,0x44 }
  261. { .mmi; mov $C=$h2
  262. mov $D=$h3
  263. mov $E=$h4 };;
  264. ___
  265. &BODY_00_15(\$code, 0,$A,$B,$C,$D,$E,$T);
  266. &BODY_00_15(\$code, 1,$T,$A,$B,$C,$D,$E);
  267. &BODY_00_15(\$code, 2,$E,$T,$A,$B,$C,$D);
  268. &BODY_00_15(\$code, 3,$D,$E,$T,$A,$B,$C);
  269. &BODY_00_15(\$code, 4,$C,$D,$E,$T,$A,$B);
  270. &BODY_00_15(\$code, 5,$B,$C,$D,$E,$T,$A);
  271. &BODY_00_15(\$code, 6,$A,$B,$C,$D,$E,$T);
  272. &BODY_00_15(\$code, 7,$T,$A,$B,$C,$D,$E);
  273. &BODY_00_15(\$code, 8,$E,$T,$A,$B,$C,$D);
  274. &BODY_00_15(\$code, 9,$D,$E,$T,$A,$B,$C);
  275. &BODY_00_15(\$code,10,$C,$D,$E,$T,$A,$B);
  276. &BODY_00_15(\$code,11,$B,$C,$D,$E,$T,$A);
  277. &BODY_00_15(\$code,12,$A,$B,$C,$D,$E,$T);
  278. &BODY_00_15(\$code,13,$T,$A,$B,$C,$D,$E);
  279. &BODY_00_15(\$code,14,$E,$T,$A,$B,$C,$D);
  280. &BODY_00_15(\$code,15,$D,$E,$T,$A,$B,$C);
  281. &BODY_16_19(\$code,16,$C,$D,$E,$T,$A,$B);
  282. &BODY_16_19(\$code,17,$B,$C,$D,$E,$T,$A);
  283. &BODY_16_19(\$code,18,$A,$B,$C,$D,$E,$T);
  284. &BODY_16_19(\$code,19,$T,$A,$B,$C,$D,$E);
  285. &BODY_20_39(\$code,20,$E,$T,$A,$B,$C,$D);
  286. &BODY_20_39(\$code,21,$D,$E,$T,$A,$B,$C);
  287. &BODY_20_39(\$code,22,$C,$D,$E,$T,$A,$B);
  288. &BODY_20_39(\$code,23,$B,$C,$D,$E,$T,$A);
  289. &BODY_20_39(\$code,24,$A,$B,$C,$D,$E,$T);
  290. &BODY_20_39(\$code,25,$T,$A,$B,$C,$D,$E);
  291. &BODY_20_39(\$code,26,$E,$T,$A,$B,$C,$D);
  292. &BODY_20_39(\$code,27,$D,$E,$T,$A,$B,$C);
  293. &BODY_20_39(\$code,28,$C,$D,$E,$T,$A,$B);
  294. &BODY_20_39(\$code,29,$B,$C,$D,$E,$T,$A);
  295. &BODY_20_39(\$code,30,$A,$B,$C,$D,$E,$T);
  296. &BODY_20_39(\$code,31,$T,$A,$B,$C,$D,$E);
  297. &BODY_20_39(\$code,32,$E,$T,$A,$B,$C,$D);
  298. &BODY_20_39(\$code,33,$D,$E,$T,$A,$B,$C);
  299. &BODY_20_39(\$code,34,$C,$D,$E,$T,$A,$B);
  300. &BODY_20_39(\$code,35,$B,$C,$D,$E,$T,$A);
  301. &BODY_20_39(\$code,36,$A,$B,$C,$D,$E,$T);
  302. &BODY_20_39(\$code,37,$T,$A,$B,$C,$D,$E);
  303. &BODY_20_39(\$code,38,$E,$T,$A,$B,$C,$D);
  304. &BODY_20_39(\$code,39,$D,$E,$T,$A,$B,$C);
  305. &BODY_40_59(\$code,40,$C,$D,$E,$T,$A,$B);
  306. &BODY_40_59(\$code,41,$B,$C,$D,$E,$T,$A);
  307. &BODY_40_59(\$code,42,$A,$B,$C,$D,$E,$T);
  308. &BODY_40_59(\$code,43,$T,$A,$B,$C,$D,$E);
  309. &BODY_40_59(\$code,44,$E,$T,$A,$B,$C,$D);
  310. &BODY_40_59(\$code,45,$D,$E,$T,$A,$B,$C);
  311. &BODY_40_59(\$code,46,$C,$D,$E,$T,$A,$B);
  312. &BODY_40_59(\$code,47,$B,$C,$D,$E,$T,$A);
  313. &BODY_40_59(\$code,48,$A,$B,$C,$D,$E,$T);
  314. &BODY_40_59(\$code,49,$T,$A,$B,$C,$D,$E);
  315. &BODY_40_59(\$code,50,$E,$T,$A,$B,$C,$D);
  316. &BODY_40_59(\$code,51,$D,$E,$T,$A,$B,$C);
  317. &BODY_40_59(\$code,52,$C,$D,$E,$T,$A,$B);
  318. &BODY_40_59(\$code,53,$B,$C,$D,$E,$T,$A);
  319. &BODY_40_59(\$code,54,$A,$B,$C,$D,$E,$T);
  320. &BODY_40_59(\$code,55,$T,$A,$B,$C,$D,$E);
  321. &BODY_40_59(\$code,56,$E,$T,$A,$B,$C,$D);
  322. &BODY_40_59(\$code,57,$D,$E,$T,$A,$B,$C);
  323. &BODY_40_59(\$code,58,$C,$D,$E,$T,$A,$B);
  324. &BODY_40_59(\$code,59,$B,$C,$D,$E,$T,$A);
  325. &BODY_60_79(\$code,60,$A,$B,$C,$D,$E,$T);
  326. &BODY_60_79(\$code,61,$T,$A,$B,$C,$D,$E);
  327. &BODY_60_79(\$code,62,$E,$T,$A,$B,$C,$D);
  328. &BODY_60_79(\$code,63,$D,$E,$T,$A,$B,$C);
  329. &BODY_60_79(\$code,64,$C,$D,$E,$T,$A,$B);
  330. &BODY_60_79(\$code,65,$B,$C,$D,$E,$T,$A);
  331. &BODY_60_79(\$code,66,$A,$B,$C,$D,$E,$T);
  332. &BODY_60_79(\$code,67,$T,$A,$B,$C,$D,$E);
  333. &BODY_60_79(\$code,68,$E,$T,$A,$B,$C,$D);
  334. &BODY_60_79(\$code,69,$D,$E,$T,$A,$B,$C);
  335. &BODY_60_79(\$code,70,$C,$D,$E,$T,$A,$B);
  336. &BODY_60_79(\$code,71,$B,$C,$D,$E,$T,$A);
  337. &BODY_60_79(\$code,72,$A,$B,$C,$D,$E,$T);
  338. &BODY_60_79(\$code,73,$T,$A,$B,$C,$D,$E);
  339. &BODY_60_79(\$code,74,$E,$T,$A,$B,$C,$D);
  340. &BODY_60_79(\$code,75,$D,$E,$T,$A,$B,$C);
  341. &BODY_60_79(\$code,76,$C,$D,$E,$T,$A,$B);
  342. &BODY_60_79(\$code,77,$B,$C,$D,$E,$T,$A);
  343. &BODY_60_79(\$code,78,$A,$B,$C,$D,$E,$T);
  344. &BODY_60_79(\$code,79,$T,$A,$B,$C,$D,$E);
  345. $code.=<<___;
  346. { .mmb; add $h0=$h0,$E
  347. nop.m 0
  348. br.ctop.dptk.many .Lhtop };;
  349. .Lhend:
  350. { .mmi; add tmp0=4,ctx
  351. mov ar.lc=r3 };;
  352. { .mmi; st4 [ctx]=$h0,8
  353. st4 [tmp0]=$h1,8 };;
  354. { .mmi; st4 [ctx]=$h2,8
  355. st4 [tmp0]=$h3 };;
  356. { .mib; st4 [ctx]=$h4,-16
  357. mov pr=r2,0x1ffff
  358. br.ret.sptk.many b0 };;
  359. .endp sha1_block_asm_host_order#
  360. ___
  361. $code.=<<___;
  362. // void sha1_block_asm_data_order(SHA_CTX *c,const void *p,size_t num);
  363. .global sha1_block_asm_data_order#
  364. .proc sha1_block_asm_data_order#
  365. .align 32
  366. sha1_block_asm_data_order:
  367. ___
  368. $code.=<<___ if ($big_endian);
  369. { .mmi; and r2=3,inp };;
  370. { .mib; cmp.eq p6,p0=r0,r2
  371. (p6) br.dptk.many sha1_block_asm_host_order };;
  372. ___
  373. $code.=<<___;
  374. .prologue
  375. { .mmi; alloc tmp1=ar.pfs,3,15,0,0
  376. $ADDP tmp0=4,ctx
  377. .save ar.lc,r3
  378. mov r3=ar.lc }
  379. { .mmi; $ADDP ctx=0,ctx
  380. $ADDP inp=0,inp
  381. mov r2=pr };;
  382. tmp4=in2;
  383. tmp5=loc13;
  384. tmp6=loc14;
  385. .body
  386. { .mlx; ld4 $h0=[ctx],8
  387. movl $K_00_19=0x5a827999 }
  388. { .mlx; ld4 $h1=[tmp0],8
  389. movl $K_20_39=0x6ed9eba1 };;
  390. { .mlx; ld4 $h2=[ctx],8
  391. movl $K_40_59=0x8f1bbcdc }
  392. { .mlx; ld4 $h3=[tmp0]
  393. movl $K_60_79=0xca62c1d6 };;
  394. { .mmi; ld4 $h4=[ctx],-16
  395. add in2=-1,in2 // adjust num for ar.lc
  396. mov ar.ec=1 };;
  397. { .mmi; nop.m 0
  398. add tmp3=1,inp
  399. mov ar.lc=in2 };; // brp.loop.imp: too far
  400. .Ldtop:
  401. { .mmi; mov $A=$h0
  402. mov $B=$h1
  403. mux2 tmp6=$h1,0x44 }
  404. { .mmi; mov $C=$h2
  405. mov $D=$h3
  406. mov $E=$h4 };;
  407. ___
  408. &BODY_00_15(\$code, 0,$A,$B,$C,$D,$E,$T,1);
  409. &BODY_00_15(\$code, 1,$T,$A,$B,$C,$D,$E,1);
  410. &BODY_00_15(\$code, 2,$E,$T,$A,$B,$C,$D,1);
  411. &BODY_00_15(\$code, 3,$D,$E,$T,$A,$B,$C,1);
  412. &BODY_00_15(\$code, 4,$C,$D,$E,$T,$A,$B,1);
  413. &BODY_00_15(\$code, 5,$B,$C,$D,$E,$T,$A,1);
  414. &BODY_00_15(\$code, 6,$A,$B,$C,$D,$E,$T,1);
  415. &BODY_00_15(\$code, 7,$T,$A,$B,$C,$D,$E,1);
  416. &BODY_00_15(\$code, 8,$E,$T,$A,$B,$C,$D,1);
  417. &BODY_00_15(\$code, 9,$D,$E,$T,$A,$B,$C,1);
  418. &BODY_00_15(\$code,10,$C,$D,$E,$T,$A,$B,1);
  419. &BODY_00_15(\$code,11,$B,$C,$D,$E,$T,$A,1);
  420. &BODY_00_15(\$code,12,$A,$B,$C,$D,$E,$T,1);
  421. &BODY_00_15(\$code,13,$T,$A,$B,$C,$D,$E,1);
  422. &BODY_00_15(\$code,14,$E,$T,$A,$B,$C,$D,1);
  423. &BODY_00_15(\$code,15,$D,$E,$T,$A,$B,$C,1);
  424. &BODY_16_19(\$code,16,$C,$D,$E,$T,$A,$B);
  425. &BODY_16_19(\$code,17,$B,$C,$D,$E,$T,$A);
  426. &BODY_16_19(\$code,18,$A,$B,$C,$D,$E,$T);
  427. &BODY_16_19(\$code,19,$T,$A,$B,$C,$D,$E);
  428. &BODY_20_39(\$code,20,$E,$T,$A,$B,$C,$D);
  429. &BODY_20_39(\$code,21,$D,$E,$T,$A,$B,$C);
  430. &BODY_20_39(\$code,22,$C,$D,$E,$T,$A,$B);
  431. &BODY_20_39(\$code,23,$B,$C,$D,$E,$T,$A);
  432. &BODY_20_39(\$code,24,$A,$B,$C,$D,$E,$T);
  433. &BODY_20_39(\$code,25,$T,$A,$B,$C,$D,$E);
  434. &BODY_20_39(\$code,26,$E,$T,$A,$B,$C,$D);
  435. &BODY_20_39(\$code,27,$D,$E,$T,$A,$B,$C);
  436. &BODY_20_39(\$code,28,$C,$D,$E,$T,$A,$B);
  437. &BODY_20_39(\$code,29,$B,$C,$D,$E,$T,$A);
  438. &BODY_20_39(\$code,30,$A,$B,$C,$D,$E,$T);
  439. &BODY_20_39(\$code,31,$T,$A,$B,$C,$D,$E);
  440. &BODY_20_39(\$code,32,$E,$T,$A,$B,$C,$D);
  441. &BODY_20_39(\$code,33,$D,$E,$T,$A,$B,$C);
  442. &BODY_20_39(\$code,34,$C,$D,$E,$T,$A,$B);
  443. &BODY_20_39(\$code,35,$B,$C,$D,$E,$T,$A);
  444. &BODY_20_39(\$code,36,$A,$B,$C,$D,$E,$T);
  445. &BODY_20_39(\$code,37,$T,$A,$B,$C,$D,$E);
  446. &BODY_20_39(\$code,38,$E,$T,$A,$B,$C,$D);
  447. &BODY_20_39(\$code,39,$D,$E,$T,$A,$B,$C);
  448. &BODY_40_59(\$code,40,$C,$D,$E,$T,$A,$B);
  449. &BODY_40_59(\$code,41,$B,$C,$D,$E,$T,$A);
  450. &BODY_40_59(\$code,42,$A,$B,$C,$D,$E,$T);
  451. &BODY_40_59(\$code,43,$T,$A,$B,$C,$D,$E);
  452. &BODY_40_59(\$code,44,$E,$T,$A,$B,$C,$D);
  453. &BODY_40_59(\$code,45,$D,$E,$T,$A,$B,$C);
  454. &BODY_40_59(\$code,46,$C,$D,$E,$T,$A,$B);
  455. &BODY_40_59(\$code,47,$B,$C,$D,$E,$T,$A);
  456. &BODY_40_59(\$code,48,$A,$B,$C,$D,$E,$T);
  457. &BODY_40_59(\$code,49,$T,$A,$B,$C,$D,$E);
  458. &BODY_40_59(\$code,50,$E,$T,$A,$B,$C,$D);
  459. &BODY_40_59(\$code,51,$D,$E,$T,$A,$B,$C);
  460. &BODY_40_59(\$code,52,$C,$D,$E,$T,$A,$B);
  461. &BODY_40_59(\$code,53,$B,$C,$D,$E,$T,$A);
  462. &BODY_40_59(\$code,54,$A,$B,$C,$D,$E,$T);
  463. &BODY_40_59(\$code,55,$T,$A,$B,$C,$D,$E);
  464. &BODY_40_59(\$code,56,$E,$T,$A,$B,$C,$D);
  465. &BODY_40_59(\$code,57,$D,$E,$T,$A,$B,$C);
  466. &BODY_40_59(\$code,58,$C,$D,$E,$T,$A,$B);
  467. &BODY_40_59(\$code,59,$B,$C,$D,$E,$T,$A);
  468. &BODY_60_79(\$code,60,$A,$B,$C,$D,$E,$T);
  469. &BODY_60_79(\$code,61,$T,$A,$B,$C,$D,$E);
  470. &BODY_60_79(\$code,62,$E,$T,$A,$B,$C,$D);
  471. &BODY_60_79(\$code,63,$D,$E,$T,$A,$B,$C);
  472. &BODY_60_79(\$code,64,$C,$D,$E,$T,$A,$B);
  473. &BODY_60_79(\$code,65,$B,$C,$D,$E,$T,$A);
  474. &BODY_60_79(\$code,66,$A,$B,$C,$D,$E,$T);
  475. &BODY_60_79(\$code,67,$T,$A,$B,$C,$D,$E);
  476. &BODY_60_79(\$code,68,$E,$T,$A,$B,$C,$D);
  477. &BODY_60_79(\$code,69,$D,$E,$T,$A,$B,$C);
  478. &BODY_60_79(\$code,70,$C,$D,$E,$T,$A,$B);
  479. &BODY_60_79(\$code,71,$B,$C,$D,$E,$T,$A);
  480. &BODY_60_79(\$code,72,$A,$B,$C,$D,$E,$T);
  481. &BODY_60_79(\$code,73,$T,$A,$B,$C,$D,$E);
  482. &BODY_60_79(\$code,74,$E,$T,$A,$B,$C,$D);
  483. &BODY_60_79(\$code,75,$D,$E,$T,$A,$B,$C);
  484. &BODY_60_79(\$code,76,$C,$D,$E,$T,$A,$B);
  485. &BODY_60_79(\$code,77,$B,$C,$D,$E,$T,$A);
  486. &BODY_60_79(\$code,78,$A,$B,$C,$D,$E,$T);
  487. &BODY_60_79(\$code,79,$T,$A,$B,$C,$D,$E);
  488. $code.=<<___;
  489. { .mmb; add $h0=$h0,$E
  490. nop.m 0
  491. br.ctop.dptk.many .Ldtop };;
  492. .Ldend:
  493. { .mmi; add tmp0=4,ctx
  494. mov ar.lc=r3 };;
  495. { .mmi; st4 [ctx]=$h0,8
  496. st4 [tmp0]=$h1,8 };;
  497. { .mmi; st4 [ctx]=$h2,8
  498. st4 [tmp0]=$h3 };;
  499. { .mib; st4 [ctx]=$h4,-16
  500. mov pr=r2,0x1ffff
  501. br.ret.sptk.many b0 };;
  502. .endp sha1_block_asm_data_order#
  503. ___
  504. print $code;