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 # SHA1 block procedure for s390x.
14 # Performance is >30% better than gcc 3.3 generated code. But the real
15 # twist is that SHA1 hardware support is detected and utilized. In
16 # which case performance can reach further >4.5x for larger chunks.
20 # Optimize Xupdate for amount of memory references and reschedule
21 # instructions to favour dual-issue z10 pipeline. On z10 hardware is
22 # "only" ~2.3x faster than software.
26 # Adapt for -m31 build. If kernel supports what's called "highgprs"
27 # feature on Linux [see /proc/cpuinfo], it's possible to use 64-bit
28 # instructions and achieve "64-bit" performance even in 31-bit legacy
29 # application context. The feature is not specific to any particular
30 # processor, as long as it's "z-CPU". Latter implies that the code
31 # remains z/Architecture specific. On z990 it was measured to peform
32 # 23% better than code generated by gcc 4.3.
34 $kimdfunc=1; # magic function code for kimd instruction
38 if ($flavour =~ /3[12]/) {
46 while (($output=shift) && ($output!~/^\w[\w\-]*\.\w+$/)) {}
47 open STDOUT,">$output";
49 $K_00_39="%r0"; $K=$K_00_39;
51 $ctx="%r2"; $prefetch="%r2";
59 $E="%r9"; @V=($A,$B,$C,$D,$E);
62 @X=("%r12","%r13","%r14");
65 $stdframe=16*$SIZE_T+4*8;
66 $frame=$stdframe+16*4;
71 $code.=<<___ if ($i==15);
72 lg $prefetch,$stdframe($sp) ### Xupdate(16) warm-up
75 return if ($i&1); # Xupdate is vectorized and executed every 2nd cycle
76 $code.=<<___ if ($i<16);
77 lg $X[0],`$i*4`($inp) ### Xload($i)
80 $code.=<<___ if ($i>=16);
81 xgr $X[0],$prefetch ### Xupdate($i)
82 lg $prefetch,`$stdframe+4*(($i+2)%16)`($sp)
83 xg $X[0],`$stdframe+4*(($i+8)%16)`($sp)
89 lr $X[2],$X[1] # feedback
91 $code.=<<___ if ($i<=70);
92 stg $X[0],`$stdframe+4*($i%16)`($sp)
98 my ($i,$a,$b,$c,$d,$e)=@_;
117 my ($i,$a,$b,$c,$d,$e)=@_;
135 my ($i,$a,$b,$c,$d,$e)=@_;
158 .type Ktable,\@object
159 Ktable: .long 0x5a827999,0x6ed9eba1,0x8f1bbcdc,0xca62c1d6
160 .skip 48 #.long 0,0,0,0,0,0,0,0,0,0,0,0
161 .size Ktable,.-Ktable
162 .globl sha1_block_data_order
163 .type sha1_block_data_order,\@function
164 sha1_block_data_order:
166 $code.=<<___ if ($kimdfunc);
167 larl %r1,OPENSSL_s390xcap_P
169 tmhl %r0,0x4000 # check for message-security assist
172 la %r1,`2*$SIZE_T`($sp)
173 .long 0xb93e0002 # kimd %r0,%r2
174 lg %r0,`2*$SIZE_T`($sp)
175 tmhh %r0,`0x8000>>$kimdfunc`
181 .long 0xb93e0002 # kimd %r0,%r2
182 brc 1,.-4 # pay attention to "partial completion"
189 st${g} $ctx,`2*$SIZE_T`($sp)
190 stm${g} %r6,%r15,`6*$SIZE_T`($sp)
206 rllg $K_00_39,$K_00_39,32
208 for ($i=0;$i<20;$i++) { &BODY_00_19($i,@V); unshift(@V,pop(@V)); }
210 rllg $K_00_39,$K_00_39,32
212 for (;$i<40;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
213 $code.=<<___; $K=$K_40_79;
214 rllg $K_40_79,$K_40_79,32
216 for (;$i<60;$i++) { &BODY_40_59($i,@V); unshift(@V,pop(@V)); }
218 rllg $K_40_79,$K_40_79,32
220 for (;$i<80;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
223 l${g} $ctx,`$frame+2*$SIZE_T`($sp)
237 lm${g} %r6,%r15,`$frame+6*$SIZE_T`($sp)
239 .size sha1_block_data_order,.-sha1_block_data_order
240 .string "SHA1 block transform for s390x, CRYPTOGAMS by <appro\@openssl.org>"
241 .comm OPENSSL_s390xcap_P,16,8
244 $code =~ s/\`([^\`]*)\`/eval $1/gem;