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, ... And there
12 # is a gimmick. X[16] vector is packed to 8 64-bit registers and as
13 # result nothing is spilled on stack. In addition input data is loaded
14 # in compact instruction sequence, thus minimizing the window when the
15 # code is subject to [inter-thread] cache-thrashing hazard. The goal
16 # is to ensure scalability on UltraSPARC T1, or rather to avoid decay
17 # when amount of active threads exceeds the number of physical cores.
20 for (@ARGV) { $bits=64 if (/\-m64/ || /\-xarch\=v9/); }
21 if ($bits==64) { $bias=2047; $frame=192; }
22 else { $bias=0; $frame=112; }
25 open STDOUT,">$output";
27 @X=("%o0","%o1","%o2","%o3","%o4","%o5","%g1","%o7");
41 @K=($K_00_19,$K_20_39,$K_40_59,$K_60_79);
51 my ($i,$a,$b,$c,$d,$e)=@_;
52 my $xi=($i&1)?@X[($i/2)%8]:$Xi;
70 " srlx @X[(($i+1)/2)%8],32,$Xi\n";
78 my ($i,$a,$b,$c,$d,$e)=@_;
89 sllx @X[($j+6)%8],32,$Xi ! Xupdate($i)
90 xor @X[($j+1)%8],@X[$j%8],@X[$j%8]
91 srlx @X[($j+7)%8],32,$tmp1
92 xor @X[($j+4)%8],@X[$j%8],@X[$j%8]
95 add @K[$i/20],$e,$e !!
96 xor $Xi,@X[$j%8],@X[$j%8]
98 add @X[$j%8],@X[$j%8],@X[$j%8]
100 andn @X[$j%8],$rot1m,@X[$j%8]
102 or $Xi,@X[$j%8],@X[$j%8]
108 my ($i,$a,$b,$c,$d,$e)=@_;
115 $code.="\tsrlx @X[($i/2)%8],32,$xi\n";
132 my ($i,$a,$b,$c,$d,$e)=@_;
139 $code.="\tsrlx @X[($i/2)%8],32,$xi\n";
155 my ($i,$a,$b,$c,$d,$e)=@_;
162 $code.="\tsrlx @X[($i/2)%8],32,$xi\n";
179 $code.=<<___ if ($bits==64);
180 .register %g2,#scratch
181 .register %g3,#scratch
184 .section ".text",#alloc,#execinstr
187 .globl sha1_block_data_order
188 sha1_block_data_order:
194 sllx $rot1m,32,$rot1m
204 sethi %hi(0x5a827999),$K_00_19
205 or $K_00_19,%lo(0x5a827999),$K_00_19
206 sethi %hi(0x6ed9eba1),$K_20_39
207 or $K_20_39,%lo(0x6ed9eba1),$K_20_39
208 sethi %hi(0x8f1bbcdc),$K_40_59
209 or $K_40_59,%lo(0x8f1bbcdc),$K_40_59
210 sethi %hi(0xca62c1d6),$K_60_79
211 or $K_60_79,%lo(0xca62c1d6),$K_60_79
222 subcc %g0,$tmp1,$tmp2 ! should be 64-$tmp1, but -$tmp1 works too
227 sllx @X[0],$tmp1,@X[0]
228 ldx [$tmp0+64],$tmp64
232 srlx @X[$i+1],$tmp2,$Xi
233 sllx @X[$i+1],$tmp1,@X[$i+1]
238 srlx $tmp64,$tmp2,$tmp64
239 or $tmp64,@X[7],@X[7]
243 for ($i=0;$i<16;$i++) { &BODY_00_15($i,@V); unshift(@V,pop(@V)); }
244 for (;$i<20;$i++) { &BODY_16_19($i,@V); unshift(@V,pop(@V)); }
245 for (;$i<40;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
246 for (;$i<60;$i++) { &BODY_40_59($i,@V); unshift(@V,pop(@V)); }
247 for (;$i<80;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
269 bne `$bits==64?"%xcc":"%icc"`,.Lloop
274 .type sha1_block_data_order,#function
275 .size sha1_block_data_order,(.-sha1_block_data_order)
276 .asciz "SHA1 block transform for SPARCv9, CRYPTOGAMS by <appro\@openssl.org>"
279 $code =~ s/\`([^\`]*)\`/eval $1/gem;