2 # Copyright 2007-2016 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the OpenSSL license (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
10 # ====================================================================
11 # Written by Andy Polyakov <appro@openssl.org> for the OpenSSL
12 # project. The module is, however, dual licensed under OpenSSL and
13 # CRYPTOGAMS licenses depending on where you obtain it. For further
14 # details see http://www.openssl.org/~appro/cryptogams/.
15 # ====================================================================
17 # SHA1 block procedure for s390x.
21 # Performance is >30% better than gcc 3.3 generated code. But the real
22 # twist is that SHA1 hardware support is detected and utilized. In
23 # which case performance can reach further >4.5x for larger chunks.
27 # Optimize Xupdate for amount of memory references and reschedule
28 # instructions to favour dual-issue z10 pipeline. On z10 hardware is
29 # "only" ~2.3x faster than software.
33 # Adapt for -m31 build. If kernel supports what's called "highgprs"
34 # feature on Linux [see /proc/cpuinfo], it's possible to use 64-bit
35 # instructions and achieve "64-bit" performance even in 31-bit legacy
36 # application context. The feature is not specific to any particular
37 # processor, as long as it's "z-CPU". Latter implies that the code
38 # remains z/Architecture specific. On z990 it was measured to perform
39 # 23% better than code generated by gcc 4.3.
41 $kimdfunc=1; # magic function code for kimd instruction
45 if ($flavour =~ /3[12]/) {
53 while (($output=shift) && ($output!~/\w[\w\-]*\.\w+$/)) {}
54 open STDOUT,">$output";
56 $K_00_39="%r0"; $K=$K_00_39;
58 $ctx="%r2"; $prefetch="%r2";
66 $E="%r9"; @V=($A,$B,$C,$D,$E);
69 @X=("%r12","%r13","%r14");
72 $stdframe=16*$SIZE_T+4*8;
73 $frame=$stdframe+16*4;
78 $code.=<<___ if ($i==15);
79 lg $prefetch,$stdframe($sp) ### Xupdate(16) warm-up
82 return if ($i&1); # Xupdate is vectorized and executed every 2nd cycle
83 $code.=<<___ if ($i<16);
84 lg $X[0],`$i*4`($inp) ### Xload($i)
87 $code.=<<___ if ($i>=16);
88 xgr $X[0],$prefetch ### Xupdate($i)
89 lg $prefetch,`$stdframe+4*(($i+2)%16)`($sp)
90 xg $X[0],`$stdframe+4*(($i+8)%16)`($sp)
96 lr $X[2],$X[1] # feedback
98 $code.=<<___ if ($i<=70);
99 stg $X[0],`$stdframe+4*($i%16)`($sp)
105 my ($i,$a,$b,$c,$d,$e)=@_;
124 my ($i,$a,$b,$c,$d,$e)=@_;
142 my ($i,$a,$b,$c,$d,$e)=@_;
163 #include "s390x_arch.h"
167 .type Ktable,\@object
168 Ktable: .long 0x5a827999,0x6ed9eba1,0x8f1bbcdc,0xca62c1d6
169 .skip 48 #.long 0,0,0,0,0,0,0,0,0,0,0,0
170 .size Ktable,.-Ktable
171 .globl sha1_block_data_order
172 .type sha1_block_data_order,\@function
173 sha1_block_data_order:
175 $code.=<<___ if ($kimdfunc);
176 larl %r1,OPENSSL_s390xcap_P
177 lg %r0,S390X_KIMD(%r1) # check kimd capabilities
178 tmhh %r0,`0x8000>>$kimdfunc`
184 .long 0xb93e0002 # kimd %r0,%r2
185 brc 1,.-4 # pay attention to "partial completion"
192 st${g} $ctx,`2*$SIZE_T`($sp)
193 stm${g} %r6,%r15,`6*$SIZE_T`($sp)
209 rllg $K_00_39,$K_00_39,32
211 for ($i=0;$i<20;$i++) { &BODY_00_19($i,@V); unshift(@V,pop(@V)); }
213 rllg $K_00_39,$K_00_39,32
215 for (;$i<40;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
216 $code.=<<___; $K=$K_40_79;
217 rllg $K_40_79,$K_40_79,32
219 for (;$i<60;$i++) { &BODY_40_59($i,@V); unshift(@V,pop(@V)); }
221 rllg $K_40_79,$K_40_79,32
223 for (;$i<80;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
226 l${g} $ctx,`$frame+2*$SIZE_T`($sp)
240 lm${g} %r6,%r15,`$frame+6*$SIZE_T`($sp)
242 .size sha1_block_data_order,.-sha1_block_data_order
243 .string "SHA1 block transform for s390x, CRYPTOGAMS by <appro\@openssl.org>"
246 $code =~ s/\`([^\`]*)\`/eval $1/gem;