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.
18 $kimdfunc=1; # magic function code for kimd instruction
21 open STDOUT,">$output";
33 $E="%r9"; @V=($A,$B,$C,$D,$E);
44 my ($i,$a,$b,$c,$d,$e)=@_;
45 my $xi=($i&1)?$Xi:$t1;
47 $code.=<<___ if ($i<16 && !($i&1));
51 alr $e,$K_00_19 ### $i
61 $code.=<<___ if ($i<16 && !($i&1));
63 stg $Xi,`160+$i*4`($sp)
73 return if ($i&1); # Xupdate is vectorized and executed every 2nd cycle
75 lg $Xi,`160+4*($i%16)`($sp) ### Xupdate($i)
76 xg $Xi,`160+4*(($i+2)%16)`($sp)
77 xg $Xi,`160+4*(($i+8)%16)`($sp)
79 if ((($i+13)%16)==15) {
81 llgf $t0,`160+4*15`($sp)
88 xg $Xi,`160+4*(($i+13)%16)`($sp)
96 stg $Xi,`160+4*($i%16)`($sp)
106 my ($i,$a,$b,$c,$d,$e)=@_;
107 my $xi=($i&1)?$Xi:$t1;
108 my $K_XX_XX=($i<40)?$K_20_39:$K_60_79;
112 alr $e,$K_XX_XX ### $i
125 my ($i,$a,$b,$c,$d,$e)=@_;
126 my $xi=($i&1)?$Xi:$t1;
130 alr $e,$K_40_59 ### $i
147 .globl sha1_block_data_order
148 .type sha1_block_data_order,\@function
149 sha1_block_data_order:
151 $code.=<<___ if ($kimdfunc);
154 .long 0xb93e0002 # kimd %r0,%r2
156 tmhh %r0,`0x8000>>$kimdfunc`
162 .long 0xb93e0002 # kimd %r0,%r2
163 brc 1,.-4 # pay attention to "partial completion"
168 stmg %r6,%r15,48($sp)
182 llilh $K_00_19,0x5a82
184 llilh $K_20_39,0x6ed9
186 llilh $K_40_59,0x8f1b
188 llilh $K_60_79,0xca62
192 for ($i=0;$i<16;$i++) { &BODY_00_15($i,@V); unshift(@V,pop(@V)); }
193 for (;$i<20;$i++) { &BODY_16_19($i,@V); unshift(@V,pop(@V)); }
194 for (;$i<40;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
195 for (;$i<60;$i++) { &BODY_40_59($i,@V); unshift(@V,pop(@V)); }
196 for (;$i<80;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); }
213 lmg %r6,%r15,`$frame+48`($sp)
215 .size sha1_block_data_order,.-sha1_block_data_order
216 .string "SHA1 block transform for s390x, CRYPTOGAMS by <appro\@openssl.org>"
219 $code =~ s/\`([^\`]*)\`/eval $1/gem;