3 # ====================================================================
4 # Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
5 # project. The module is, however, dual licensed under OpenSSL and
6 # CRYPTOGAMS licenses depending on where you obtain it. For further
7 # details see http://www.openssl.org/~appro/cryptogams/.
8 # ====================================================================
10 # Performance improvement is not really impressive on pre-T1 CPU: +8%
11 # over Sun C and +25% over gcc [3.3]. While on T1, a.k.a. Niagara, it
12 # turned to be 40% faster than 64-bit code generated by Sun C 5.8 and
13 # >2x than 64-bit code generated by gcc 3.4. And there is a gimmick.
14 # X[16] vector is packed to 8 64-bit registers and as result nothing
15 # is spilled on stack. In addition input data is loaded in compact
16 # instruction sequence, thus minimizing the window when the code is
17 # subject to [inter-thread] cache-thrashing hazard. The goal is to
18 # ensure scalability on UltraSPARC T1, or rather to avoid decay when
19 # amount of active threads exceeds the number of physical cores.
22 for (@ARGV) { $bits=64 if (/\-m64/ || /\-xarch\=v9/); }
23 if ($bits==64) { $bias=2047; $frame=192; }
24 else { $bias=0; $frame=112; }
27 open STDOUT,">$output";
29 @X=("%o0","%o1","%o2","%o3","%o4","%o5","%g1","%o7");
43 @K=($K_00_19,$K_20_39,$K_40_59,$K_60_79);
53 my ($i,$a,$b,$c,$d,$e)=@_;
54 my $xi=($i&1)?@X[($i/2)%8]:$Xi;
72 " srlx @X[(($i+1)/2)%8],32,$Xi\n";
80 my ($i,$a,$b,$c,$d,$e)=@_;
91 sllx @X[($j+6)%8],32,$Xi ! Xupdate($i)
92 xor @X[($j+1)%8],@X[$j%8],@X[$j%8]
93 srlx @X[($j+7)%8],32,$tmp1
94 xor @X[($j+4)%8],@X[$j%8],@X[$j%8]
97 add @K[$i/20],$e,$e !!
98 xor $Xi,@X[$j%8],@X[$j%8]
100 add @X[$j%8],@X[$j%8],@X[$j%8]
102 andn @X[$j%8],$rot1m,@X[$j%8]
104 or $Xi,@X[$j%8],@X[$j%8]
110 my ($i,$a,$b,$c,$d,$e)=@_;
117 $code.="\tsrlx @X[($i/2)%8],32,$xi\n";
134 my ($i,$a,$b,$c,$d,$e)=@_;
141 $code.="\tsrlx @X[($i/2)%8],32,$xi\n";
157 my ($i,$a,$b,$c,$d,$e)=@_;
164 $code.="\tsrlx @X[($i/2)%8],32,$xi\n";
181 $code.=<<___ if ($bits==64);
182 .register %g2,#scratch
183 .register %g3,#scratch
186 .section ".text",#alloc,#execinstr
189 .globl sha1_block_data_order
190 sha1_block_data_order:
196 sllx $rot1m,32,$rot1m
206 sethi %hi(0x5a827999),$K_00_19
207 or $K_00_19,%lo(0x5a827999),$K_00_19
208 sethi %hi(0x6ed9eba1),$K_20_39
209 or $K_20_39,%lo(0x6ed9eba1),$K_20_39
210 sethi %hi(0x8f1bbcdc),$K_40_59
211 or $K_40_59,%lo(0x8f1bbcdc),$K_40_59
212 sethi %hi(0xca62c1d6),$K_60_79
213 or $K_60_79,%lo(0xca62c1d6),$K_60_79
224 subcc %g0,$tmp1,$tmp2 ! should be 64-$tmp1, but -$tmp1 works too
229 sllx @X[0],$tmp1,@X[0]
230 ldx [$tmp0+64],$tmp64
234 srlx @X[$i+1],$tmp2,$Xi
235 sllx @X[$i+1],$tmp1,@X[$i+1]
240 srlx $tmp64,$tmp2,$tmp64
241 or $tmp64,@X[7],@X[7]
245 for ($i=0;$i<16;$i++) { &BODY_00_15($i,@V); unshift(@V,pop(@V)); }
246 for (;$i<20;$i++) { &BODY_16_19($i,@V); unshift(@V,pop(@V)); }
247 for (;$i<40;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
248 for (;$i<60;$i++) { &BODY_40_59($i,@V); unshift(@V,pop(@V)); }
249 for (;$i<80;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
271 bne `$bits==64?"%xcc":"%icc"`,.Lloop
276 .type sha1_block_data_order,#function
277 .size sha1_block_data_order,(.-sha1_block_data_order)
278 .asciz "SHA1 block transform for SPARCv9, CRYPTOGAMS by <appro\@openssl.org>"
281 $code =~ s/\`([^\`]*)\`/eval $1/gem;