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.
33 $kimdfunc=1; # magic function code for kimd instruction
37 if ($flavour =~ /3[12]/) {
45 while (($output=shift) && ($output!~/^\w[\w\-]*\.\w+$/)) {}
46 open STDOUT
,">$output";
48 $K_00_39="%r0"; $K=$K_00_39;
50 $ctx="%r2"; $prefetch="%r2";
58 $E="%r9"; @V=($A,$B,$C,$D,$E);
61 @X=("%r12","%r13","%r14");
64 $stdframe=16*$SIZE_T+4*8;
65 $frame=$stdframe+16*4;
70 $code.=<<___
if ($i==15);
71 lg
$prefetch,$stdframe($sp) ### Xupdate(16) warm-up
74 return if ($i&1); # Xupdate is vectorized and executed every 2nd cycle
75 $code.=<<___
if ($i<16);
76 lg
$X[0],`$i*4`($inp) ### Xload($i)
79 $code.=<<___
if ($i>=16);
80 xgr
$X[0],$prefetch ### Xupdate($i)
81 lg
$prefetch,`$stdframe+4*(($i+2)%16)`($sp)
82 xg
$X[0],`$stdframe+4*(($i+8)%16)`($sp)
88 lr
$X[2],$X[1] # feedback
90 $code.=<<___
if ($i<=70);
91 stg
$X[0],`$stdframe+4*($i%16)`($sp)
97 my ($i,$a,$b,$c,$d,$e)=@_;
116 my ($i,$a,$b,$c,$d,$e)=@_;
134 my ($i,$a,$b,$c,$d,$e)=@_;
157 .type Ktable
,\
@object
158 Ktable
: .long
0x5a827999,0x6ed9eba1,0x8f1bbcdc,0xca62c1d6
159 .skip
48 #.long 0,0,0,0,0,0,0,0,0,0,0,0
160 .size Ktable
,.-Ktable
161 .globl sha1_block_data_order
162 .type sha1_block_data_order
,\
@function
163 sha1_block_data_order
:
165 $code.=<<___
if ($kimdfunc);
166 larl
%r1,OPENSSL_s390xcap_P
168 tmhl
%r0,0x4000 # check for message-security assist
171 la
%r1,`2*$SIZE_T`($sp)
172 .long
0xb93e0002 # kimd %r0,%r2
173 lg
%r0,`2*$SIZE_T`($sp)
174 tmhh
%r0,`0x8000>>$kimdfunc`
180 .long
0xb93e0002 # kimd %r0,%r2
181 brc
1,.-4 # pay attention to "partial completion"
188 st
${g
} $ctx,`2*$SIZE_T`($sp)
189 stm
${g
} %r6,%r15,`6*$SIZE_T`($sp)
205 rllg
$K_00_39,$K_00_39,32
207 for ($i=0;$i<20;$i++) { &BODY_00_19
($i,@V); unshift(@V,pop(@V)); }
209 rllg
$K_00_39,$K_00_39,32
211 for (;$i<40;$i++) { &BODY_20_39
($i,@V); unshift(@V,pop(@V)); }
212 $code.=<<___
; $K=$K_40_79;
213 rllg
$K_40_79,$K_40_79,32
215 for (;$i<60;$i++) { &BODY_40_59
($i,@V); unshift(@V,pop(@V)); }
217 rllg
$K_40_79,$K_40_79,32
219 for (;$i<80;$i++) { &BODY_20_39
($i,@V); unshift(@V,pop(@V)); }
222 l
${g
} $ctx,`$frame+2*$SIZE_T`($sp)
236 lm
${g
} %r6,%r15,`$frame+6*$SIZE_T`($sp)
238 .size sha1_block_data_order
,.-sha1_block_data_order
239 .string
"SHA1 block transform for s390x, CRYPTOGAMS by <appro\@openssl.org>"
240 .comm OPENSSL_s390xcap_P
,16,8
243 $code =~ s/\`([^\`]*)\`/eval $1/gem;