3 # ====================================================================
4 # [Re]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 # "[Re]written" was achieved in two major overhauls. In 2004 BODY_*
11 # functions were re-implemented to address P4 performance issue [see
12 # commentary below], and in 2006 the rest was rewritten in order to
13 # gain freedom to liberate licensing terms.
15 # January, September 2004.
17 # It was noted that Intel IA-32 C compiler generates code which
18 # performs ~30% *faster* on P4 CPU than original *hand-coded*
19 # SHA1 assembler implementation. To address this problem (and
20 # prove that humans are still better than machines:-), the
21 # original code was overhauled, which resulted in following
22 # performance changes:
24 # compared with original compared with Intel cc
25 # assembler impl. generated code
30 # As you can see Pentium came out as looser:-( Yet I reckoned that
31 # improvement on P4 outweights the loss and incorporate this
32 # re-tuned code to 0.9.7 and later.
33 # ----------------------------------------------------------------
34 # <appro@fy.chalmers.se>
38 # George Spelvin has tipped that F_40_59(b,c,d) can be rewritten as
39 # '(c&d) + (b&(c^d))', which allows to accumulate partial results
40 # and lighten "pressure" on scratch registers. This resulted in
41 # >12% performance improvement on contemporary AMD cores (with no
42 # degradation on other CPUs:-). Also, the code was revised to maximize
43 # "distance" between instructions producing input to 'lea' instruction
44 # and the 'lea' instruction itself, which is essential for Intel Atom
45 # core and resulted in ~15% improvement.
49 # Add SSSE3, Supplemental[!] SSE3, implementation. The idea behind it
50 # is to offload message schedule denoted by Wt in NIST specification,
51 # or Xupdate in OpenSSL source, to SIMD unit. The idea is not novel,
52 # and in SSE2 context was first explored by Dean Gaudet in 2004, see
53 # http://arctic.org/~dean/crypto/sha1.html. Since then several things
54 # have changed that made it interesting again:
56 # a) XMM units became faster and wider;
57 # b) instruction set became more versatile;
58 # c) an important observation was made by Max Locktykhin, which made
59 # it possible to reduce amount of instructions required to perform
60 # the operation in question, for further details see
61 # http://software.intel.com/en-us/articles/improving-the-performance-of-the-secure-hash-algorithm-1/.
65 # Add AVX code path, probably most controversial... The thing is that
66 # switch to AVX alone improves performance by as little as 4% in
67 # comparison to SSSE3 code path. But below result doesn't look like
68 # 4% improvement... Trouble is that Sandy Bridge decodes 'ro[rl]' as
69 # pair of µ-ops, and it's the additional µ-ops, two per round, that
70 # make it run slower than Core2 and Westmere. But 'sh[rl]d' is decoded
71 # as single µ-op by Sandy Bridge and it's replacing 'ro[rl]' with
72 # equivalent 'sh[rl]d' that is responsible for the impressive 5.1
73 # cycles per processed byte. But 'sh[rl]d' is not something that used
74 # to be fast, nor does it appear to be fast in upcoming Bulldozer
75 # [according to its optimization manual]. Which is why AVX code path
76 # is guarded by *both* AVX and synthetic bit denoting Intel CPUs.
77 # One can argue that it's unfair to AMD, but without 'sh[rl]d' it
78 # makes no sense to keep the AVX code path. If somebody feels that
79 # strongly, it's probably more appropriate to discuss possibility of
80 # using vector rotate XOP on AMD...
82 ######################################################################
83 # Current performance is summarized in following table. Numbers are
84 # CPU clock cycles spent to process single byte (less is better).
91 # Core2 7.3 6.1/+20% -
92 # Atom 12.5 9.5(*)/+32% -
93 # Westmere 7.3 5.6/+30% -
94 # Sandy Bridge 8.8 6.2/+40% 5.1(**)/+70%
96 # (*) Loop is 1056 instructions long and expected result is ~8.25.
97 # It remains mystery [to me] why ILP is limited to 1.7.
99 # (**) As per above comment, the result is for AVX *plus* sh[rl]d.
101 $0 =~ m/(.*[\/\\])[^\
/\\]+$/; $dir=$1;
102 push(@INC,"${dir}","${dir}../../perlasm");
105 &asm_init
($ARGV[0],"sha1-586.pl",$ARGV[$#ARGV] eq "386");
108 for (@ARGV) { $xmm=1 if (/-DOPENSSL_IA32_SSE2/); }
111 `$ENV{CC} -Wa,-v -c -o /dev/null -x assembler /dev/null 2>&1`
112 =~ /GNU assembler version ([2-9]\.[0-9]+)/ &&
113 $1>=2.19); # first version supporting AVX
115 $ymm=1 if ($xmm && !$ymm && $ARGV[0] eq "win32n" &&
116 `nasm -v 2>&1` =~ /NASM version ([2-9]\.[0-9]+)/ &&
117 $1>=2.03); # first version supporting AVX
119 &external_label
("OPENSSL_ia32cap_P") if ($xmm);
130 @V=($A,$B,$C,$D,$E,$T);
132 $alt=0; # 1 denotes alternative IALU implementation, which performs
133 # 8% *worse* on P4, same on Westmere and Atom, 2% better on
138 local($n,$a,$b,$c,$d,$e,$f)=@_;
140 &comment
("00_15 $n");
142 &mov
($f,$c); # f to hold F_00_19(b,c,d)
143 if ($n==0) { &mov
($tmp1,$a); }
144 else { &mov
($a,$tmp1); }
145 &rotl
($tmp1,5); # tmp1=ROTATE(a,5)
147 &add
($tmp1,$e); # tmp1+=e;
148 &mov
($e,&swtmp
($n%16)); # e becomes volatile and is loaded
149 # with xi, also note that e becomes
152 &rotr
($b,2); # b=ROTATE(b,30)
153 &xor($f,$d); # f holds F_00_19(b,c,d)
154 &lea
($tmp1,&DWP
(0x5a827999,$tmp1,$e)); # tmp1+=K_00_19+xi
156 if ($n==15) { &mov
($e,&swtmp
(($n+1)%16));# pre-fetch f for next round
157 &add
($f,$tmp1); } # f+=tmp1
158 else { &add
($tmp1,$f); } # f becomes a in next round
159 &mov
($tmp1,$a) if ($alt && $n==15);
164 local($n,$a,$b,$c,$d,$e,$f)=@_;
166 &comment
("16_19 $n");
170 &xor($f,&swtmp
(($n+2)%16)); # f to hold Xupdate(xi,xa,xb,xc,xd)
171 &and($tmp1,$c); # tmp1 to hold F_00_19(b,c,d), b&=c^d
172 &xor($f,&swtmp
(($n+8)%16));
173 &xor($tmp1,$d); # tmp1=F_00_19(b,c,d)
174 &xor($f,&swtmp
(($n+13)%16)); # f holds xa^xb^xc^xd
175 &rotl
($f,1); # f=ROTATE(f,1)
176 &add
($e,$tmp1); # e+=F_00_19(b,c,d)
177 &xor($c,$d); # restore $c
178 &mov
($tmp1,$a); # b in next round
179 &rotr
($b,$n==16?
2:7); # b=ROTATE(b,30)
180 &mov
(&swtmp
($n%16),$f); # xi=f
181 &rotl
($a,5); # ROTATE(a,5)
182 &lea
($f,&DWP
(0x5a827999,$f,$e));# f+=F_00_19(b,c,d)+e
183 &mov
($e,&swtmp
(($n+1)%16)); # pre-fetch f for next round
184 &add
($f,$a); # f+=ROTATE(a,5)
186 &mov
($tmp1,$c); # tmp1 to hold F_00_19(b,c,d)
187 &xor($f,&swtmp
(($n+2)%16)); # f to hold Xupdate(xi,xa,xb,xc,xd)
189 &xor($f,&swtmp
(($n+8)%16));
191 &xor($f,&swtmp
(($n+13)%16)); # f holds xa^xb^xc^xd
192 &rotl
($f,1); # f=ROTATE(f,1)
193 &xor($tmp1,$d); # tmp1=F_00_19(b,c,d)
194 &add
($e,$tmp1); # e+=F_00_19(b,c,d)
196 &rotr
($b,2); # b=ROTATE(b,30)
197 &mov
(&swtmp
($n%16),$f); # xi=f
198 &rotl
($tmp1,5); # ROTATE(a,5)
199 &lea
($f,&DWP
(0x5a827999,$f,$e));# f+=F_00_19(b,c,d)+e
200 &mov
($e,&swtmp
(($n+1)%16)); # pre-fetch f for next round
201 &add
($f,$tmp1); # f+=ROTATE(a,5)
207 local($n,$a,$b,$c,$d,$e,$f)=@_;
208 local $K=($n<40)?
0x6ed9eba1:0xca62c1d6;
210 &comment
("20_39 $n");
213 &xor($tmp1,$c); # tmp1 to hold F_20_39(b,c,d), b^=c
214 &xor($f,&swtmp
(($n+2)%16)); # f to hold Xupdate(xi,xa,xb,xc,xd)
215 &xor($tmp1,$d); # tmp1 holds F_20_39(b,c,d)
216 &xor($f,&swtmp
(($n+8)%16));
217 &add
($e,$tmp1); # e+=F_20_39(b,c,d)
218 &xor($f,&swtmp
(($n+13)%16)); # f holds xa^xb^xc^xd
219 &rotl
($f,1); # f=ROTATE(f,1)
220 &mov
($tmp1,$a); # b in next round
221 &rotr
($b,7); # b=ROTATE(b,30)
222 &mov
(&swtmp
($n%16),$f) if($n<77);# xi=f
223 &rotl
($a,5); # ROTATE(a,5)
224 &xor($b,$c) if($n==39);# warm up for BODY_40_59
225 &and($tmp1,$b) if($n==39);
226 &lea
($f,&DWP
($K,$f,$e)); # f+=e+K_XX_YY
227 &mov
($e,&swtmp
(($n+1)%16)) if($n<79);# pre-fetch f for next round
228 &add
($f,$a); # f+=ROTATE(a,5)
229 &rotr
($a,5) if ($n==79);
231 &mov
($tmp1,$b); # tmp1 to hold F_20_39(b,c,d)
232 &xor($f,&swtmp
(($n+2)%16)); # f to hold Xupdate(xi,xa,xb,xc,xd)
234 &xor($f,&swtmp
(($n+8)%16));
235 &xor($tmp1,$d); # tmp1 holds F_20_39(b,c,d)
236 &xor($f,&swtmp
(($n+13)%16)); # f holds xa^xb^xc^xd
237 &rotl
($f,1); # f=ROTATE(f,1)
238 &add
($e,$tmp1); # e+=F_20_39(b,c,d)
239 &rotr
($b,2); # b=ROTATE(b,30)
241 &rotl
($tmp1,5); # ROTATE(a,5)
242 &mov
(&swtmp
($n%16),$f) if($n<77);# xi=f
243 &lea
($f,&DWP
($K,$f,$e)); # f+=e+K_XX_YY
244 &mov
($e,&swtmp
(($n+1)%16)) if($n<79);# pre-fetch f for next round
245 &add
($f,$tmp1); # f+=ROTATE(a,5)
251 local($n,$a,$b,$c,$d,$e,$f)=@_;
253 &comment
("40_59 $n");
256 &add
($e,$tmp1); # e+=b&(c^d)
257 &xor($f,&swtmp
(($n+2)%16)); # f to hold Xupdate(xi,xa,xb,xc,xd)
259 &xor($f,&swtmp
(($n+8)%16));
260 &xor($c,$d); # restore $c
261 &xor($f,&swtmp
(($n+13)%16)); # f holds xa^xb^xc^xd
262 &rotl
($f,1); # f=ROTATE(f,1)
264 &rotr
($b,7); # b=ROTATE(b,30)
265 &add
($e,$tmp1); # e+=c&d
266 &mov
($tmp1,$a); # b in next round
267 &mov
(&swtmp
($n%16),$f); # xi=f
268 &rotl
($a,5); # ROTATE(a,5)
269 &xor($b,$c) if ($n<59);
270 &and($tmp1,$b) if ($n<59);# tmp1 to hold F_40_59(b,c,d)
271 &lea
($f,&DWP
(0x8f1bbcdc,$f,$e));# f+=K_40_59+e+(b&(c^d))
272 &mov
($e,&swtmp
(($n+1)%16)); # pre-fetch f for next round
273 &add
($f,$a); # f+=ROTATE(a,5)
275 &mov
($tmp1,$c); # tmp1 to hold F_40_59(b,c,d)
276 &xor($f,&swtmp
(($n+2)%16)); # f to hold Xupdate(xi,xa,xb,xc,xd)
278 &xor($f,&swtmp
(($n+8)%16));
280 &xor($f,&swtmp
(($n+13)%16)); # f holds xa^xb^xc^xd
281 &rotl
($f,1); # f=ROTATE(f,1)
282 &add
($tmp1,$e); # b&(c^d)+=e
283 &rotr
($b,2); # b=ROTATE(b,30)
284 &mov
($e,$a); # e becomes volatile
285 &rotl
($e,5); # ROTATE(a,5)
286 &mov
(&swtmp
($n%16),$f); # xi=f
287 &lea
($f,&DWP
(0x8f1bbcdc,$f,$tmp1));# f+=K_40_59+e+(b&(c^d))
289 &add
($f,$e); # f+=ROTATE(a,5)
291 &mov
($e,&swtmp
(($n+1)%16)); # pre-fetch f for next round
292 &add
($f,$tmp1); # f+=c&d
296 &function_begin
("sha1_block_data_order");
298 &static_label
("ssse3_shortcut");
299 &static_label
("avx_shortcut") if ($ymm);
300 &static_label
("K_XX_XX");
302 &call
(&label
("pic_point")); # make it PIC!
303 &set_label
("pic_point");
305 &picmeup
($T,"OPENSSL_ia32cap_P",$tmp1,&label
("pic_point"));
306 &lea
($tmp1,&DWP
(&label
("K_XX_XX")."-".&label
("pic_point"),$tmp1));
308 &mov
($A,&DWP
(0,$T));
309 &mov
($D,&DWP
(4,$T));
310 &test
($D,1<<9); # check SSSE3 bit
312 &test
($A,1<<24); # check FXSR bit
315 &and ($D,1<<28); # mask AVX bit
316 &and ($A,1<<30); # mask "Intel CPU" bit
318 &cmp ($A,1<<28|1<<30);
319 &je
(&label
("avx_shortcut"));
321 &jmp
(&label
("ssse3_shortcut"));
322 &set_label
("x86",16);
324 &mov
($tmp1,&wparam
(0)); # SHA_CTX *c
325 &mov
($T,&wparam
(1)); # const void *input
326 &mov
($A,&wparam
(2)); # size_t num
327 &stack_push
(16+3); # allocate X[16]
330 &mov
(&wparam
(2),$A); # pointer beyond the end of input
331 &mov
($E,&DWP
(16,$tmp1));# pre-load E
332 &jmp
(&label
("loop"));
334 &set_label
("loop",16);
336 # copy input chunk to X, but reversing byte order!
337 for ($i=0; $i<16; $i+=4)
339 &mov
($A,&DWP
(4*($i+0),$T));
340 &mov
($B,&DWP
(4*($i+1),$T));
341 &mov
($C,&DWP
(4*($i+2),$T));
342 &mov
($D,&DWP
(4*($i+3),$T));
347 &mov
(&swtmp
($i+0),$A);
348 &mov
(&swtmp
($i+1),$B);
349 &mov
(&swtmp
($i+2),$C);
350 &mov
(&swtmp
($i+3),$D);
352 &mov
(&wparam
(1),$T); # redundant in 1st spin
354 &mov
($A,&DWP
(0,$tmp1)); # load SHA_CTX
355 &mov
($B,&DWP
(4,$tmp1));
356 &mov
($C,&DWP
(8,$tmp1));
357 &mov
($D,&DWP
(12,$tmp1));
360 for($i=0;$i<16;$i++) { &BODY_00_15
($i,@V); unshift(@V,pop(@V)); }
361 for(;$i<20;$i++) { &BODY_16_19
($i,@V); unshift(@V,pop(@V)); }
362 for(;$i<40;$i++) { &BODY_20_39
($i,@V); unshift(@V,pop(@V)); }
363 for(;$i<60;$i++) { &BODY_40_59
($i,@V); unshift(@V,pop(@V)); }
364 for(;$i<80;$i++) { &BODY_20_39
($i,@V); unshift(@V,pop(@V)); }
366 (($V[5] eq $D) and ($V[0] eq $E)) or die; # double-check
368 &mov
($tmp1,&wparam
(0)); # re-load SHA_CTX*
369 &mov
($D,&wparam
(1)); # D is last "T" and is discarded
371 &add
($E,&DWP
(0,$tmp1)); # E is last "A"...
372 &add
($T,&DWP
(4,$tmp1));
373 &add
($A,&DWP
(8,$tmp1));
374 &add
($B,&DWP
(12,$tmp1));
375 &add
($C,&DWP
(16,$tmp1));
377 &mov
(&DWP
(0,$tmp1),$E); # update SHA_CTX
378 &add
($D,64); # advance input pointer
379 &mov
(&DWP
(4,$tmp1),$T);
380 &cmp($D,&wparam
(2)); # have we reached the end yet?
381 &mov
(&DWP
(8,$tmp1),$A);
382 &mov
($E,$C); # C is last "E" which needs to be "pre-loaded"
383 &mov
(&DWP
(12,$tmp1),$B);
384 &mov
($T,$D); # input pointer
385 &mov
(&DWP
(16,$tmp1),$C);
389 &function_end
("sha1_block_data_order");
392 ######################################################################
393 # The SSSE3 implementation.
395 # %xmm[0-7] are used as ring @X[] buffer containing quadruples of last
396 # 32 elements of the message schedule or Xupdate outputs. First 4
397 # quadruples are simply byte-swapped input, next 4 are calculated
398 # according to method originally suggested by Dean Gaudet (modulo
399 # being implemented in SSSE3). Once 8 quadruples or 32 elements are
400 # collected, it switches to routine proposed by Max Locktyukhin.
402 # Calculations inevitably require temporary reqisters, and there are
403 # no %xmm registers left to spare. For this reason part of the ring
404 # buffer, X[2..4] to be specific, is offloaded to 3 quadriples ring
405 # buffer on the stack. Keep in mind that X[2] is alias X[-6], X[3] -
406 # X[-5], and X[4] - X[-4]...
408 # Another notable optimization is aggressive stack frame compression
409 # aiming to minimize amount of 9-byte instructions...
411 # Yet another notable optimization is "jumping" $B variable. It means
412 # that there is no register permanently allocated for $B value. This
413 # allowed to eliminate one instruction from body_20_39...
415 my $Xi=4; # 4xSIMD Xupdate round, start pre-seeded
416 my @X=map("xmm$_",(4..7,0..3)); # pre-seeded for $Xi=4
417 my @V=($A,$B,$C,$D,$E);
418 my $j=0; # hash round
422 my $_rol=sub { &rol
(@_) };
423 my $_ror=sub { &ror
(@_) };
425 &function_begin
("_sha1_block_data_order_ssse3");
426 &call
(&label
("pic_point")); # make it PIC!
427 &set_label
("pic_point");
429 &lea
($tmp1,&DWP
(&label
("K_XX_XX")."-".&label
("pic_point"),$tmp1));
430 &set_label
("ssse3_shortcut");
432 &movdqa
(@X[3],&QWP
(0,$tmp1)); # K_00_19
433 &movdqa
(@X[4],&QWP
(16,$tmp1)); # K_20_39
434 &movdqa
(@X[5],&QWP
(32,$tmp1)); # K_40_59
435 &movdqa
(@X[6],&QWP
(48,$tmp1)); # K_60_79
436 &movdqa
(@X[2],&QWP
(64,$tmp1)); # pbswap mask
438 &mov
($E,&wparam
(0)); # load argument block
439 &mov
($inp=@T[1],&wparam
(1));
440 &mov
($D,&wparam
(2));
445 # +0 X[0]+K X[1]+K X[2]+K X[3]+K # XMM->IALU xfer area
446 # X[4]+K X[5]+K X[6]+K X[7]+K
447 # X[8]+K X[9]+K X[10]+K X[11]+K
448 # X[12]+K X[13]+K X[14]+K X[15]+K
450 # +64 X[0] X[1] X[2] X[3] # XMM->XMM backtrace area
451 # X[4] X[5] X[6] X[7]
452 # X[8] X[9] X[10] X[11] # even borrowed for K_00_19
454 # +112 K_20_39 K_20_39 K_20_39 K_20_39 # constants
455 # K_40_59 K_40_59 K_40_59 K_40_59
456 # K_60_79 K_60_79 K_60_79 K_60_79
457 # K_00_19 K_00_19 K_00_19 K_00_19
460 # +192 ctx # argument block
467 &movdqa
(&QWP
(112+0,"esp"),@X[4]); # copy constants
468 &movdqa
(&QWP
(112+16,"esp"),@X[5]);
469 &movdqa
(&QWP
(112+32,"esp"),@X[6]);
470 &shl
($D,6); # len*64
471 &movdqa
(&QWP
(112+48,"esp"),@X[3]);
472 &add
($D,$inp); # end of input
473 &movdqa
(&QWP
(112+64,"esp"),@X[2]);
475 &mov
(&DWP
(192+0,"esp"),$E); # save argument block
476 &mov
(&DWP
(192+4,"esp"),$inp);
477 &mov
(&DWP
(192+8,"esp"),$D);
478 &mov
(&DWP
(192+12,"esp"),@T[0]); # save original %esp
480 &mov
($A,&DWP
(0,$E)); # load context
481 &mov
($B,&DWP
(4,$E));
482 &mov
($C,&DWP
(8,$E));
483 &mov
($D,&DWP
(12,$E));
484 &mov
($E,&DWP
(16,$E));
485 &mov
(@T[0],$B); # magic seed
487 &movdqu
(@X[-4&7],&QWP
(-64,$inp)); # load input to %xmm[0-3]
488 &movdqu
(@X[-3&7],&QWP
(-48,$inp));
489 &movdqu
(@X[-2&7],&QWP
(-32,$inp));
490 &movdqu
(@X[-1&7],&QWP
(-16,$inp));
491 &pshufb
(@X[-4&7],@X[2]); # byte swap
492 &pshufb
(@X[-3&7],@X[2]);
493 &pshufb
(@X[-2&7],@X[2]);
494 &movdqa
(&QWP
(112-16,"esp"),@X[3]); # borrow last backtrace slot
495 &pshufb
(@X[-1&7],@X[2]);
496 &paddd
(@X[-4&7],@X[3]); # add K_00_19
497 &paddd
(@X[-3&7],@X[3]);
498 &paddd
(@X[-2&7],@X[3]);
499 &movdqa
(&QWP
(0,"esp"),@X[-4&7]); # X[]+K xfer to IALU
500 &psubd
(@X[-4&7],@X[3]); # restore X[]
501 &movdqa
(&QWP
(0+16,"esp"),@X[-3&7]);
502 &psubd
(@X[-3&7],@X[3]);
503 &movdqa
(&QWP
(0+32,"esp"),@X[-2&7]);
504 &psubd
(@X[-2&7],@X[3]);
505 &movdqa
(@X[0],@X[-3&7]);
506 &jmp
(&label
("loop"));
508 ######################################################################
509 # SSE instruction sequence is first broken to groups of indepentent
510 # instructions, independent in respect to their inputs and shifter
511 # (not all architectures have more than one). Then IALU instructions
512 # are "knitted in" between the SSE groups. Distance is maintained for
513 # SSE latency of 2 in hope that it fits better upcoming AMD Bulldozer
514 # [which allegedly also implements SSSE3]...
516 # Temporary registers usage. X[2] is volatile at the entry and at the
517 # end is restored from backtrace ring buffer. X[3] is expected to
518 # contain current K_XX_XX constant and is used to caclulate X[-1]+K
519 # from previous round, it becomes volatile the moment the value is
520 # saved to stack for transfer to IALU. X[4] becomes volatile whenever
521 # X[-4] is accumulated and offloaded to backtrace ring buffer, at the
522 # end it is loaded with next K_XX_XX [which becomes X[3] in next
525 sub Xupdate_ssse3_16_31
() # recall that $Xi starts wtih 4
528 my @insns = (&$body,&$body,&$body,&$body); # 40 instructions
533 &palignr
(@X[0],@X[-4&7],8); # compose "X[-14]" in "X[0]"
534 &movdqa
(@X[2],@X[-1&7]);
538 &paddd
(@X[3],@X[-1&7]);
539 &movdqa
(&QWP
(64+16*(($Xi-4)%3),"esp"),@X[-4&7]);# save X[] to backtrace buffer
542 &psrldq
(@X[2],4); # "X[-3]", 3 dwords
545 &pxor
(@X[0],@X[-4&7]); # "X[0]"^="X[-16]"
549 &pxor
(@X[2],@X[-2&7]); # "X[-3]"^"X[-8]"
555 &pxor
(@X[0],@X[2]); # "X[0]"^="X[-3]"^"X[-8]"
558 &movdqa
(&QWP
(0+16*(($Xi-1)&3),"esp"),@X[3]); # X[]+K xfer to IALU
562 &movdqa
(@X[4],@X[0]);
563 &movdqa
(@X[2],@X[0]);
569 &pslldq
(@X[4],12); # "X[0]"<<96, extract one dword
570 &paddd
(@X[0],@X[0]);
579 &movdqa
(@X[3],@X[4]);
584 &por
(@X[0],@X[2]); # "X[0]"<<<=1
587 &movdqa
(@X[2],&QWP
(64+16*(($Xi-6)%3),"esp")) if ($Xi>5); # restore X[] from backtrace buffer
595 &movdqa
(@X[4],&QWP
(112-16+16*(($Xi)/5),"esp")); # K_XX_XX
599 &pxor
(@X[0],@X[3]); # "X[0]"^=("X[0]"<<96)<<<2
600 &movdqa
(@X[1],@X[-2&7]) if ($Xi<7);
604 foreach (@insns) { eval; } # remaining instructions [if any]
606 $Xi++; push(@X,shift(@X)); # "rotate" X[]
609 sub Xupdate_ssse3_32_79
()
612 my @insns = (&$body,&$body,&$body,&$body); # 32 to 48 instructions
615 &movdqa
(@X[2],@X[-1&7]) if ($Xi==8);
616 eval(shift(@insns)); # body_20_39
617 &pxor
(@X[0],@X[-4&7]); # "X[0]"="X[-32]"^"X[-16]"
618 &palignr
(@X[2],@X[-2&7],8); # compose "X[-6]"
621 eval(shift(@insns)); # rol
623 &pxor
(@X[0],@X[-7&7]); # "X[0]"^="X[-28]"
624 &movdqa
(&QWP
(64+16*(($Xi-4)%3),"esp"),@X[-4&7]); # save X[] to backtrace buffer
628 &movdqa
(@X[4],@X[3]); # "perpetuate" K_XX_XX...
629 } else { # ... or load next one
630 &movdqa
(@X[4],&QWP
(112-16+16*($Xi/5),"esp"));
632 &paddd
(@X[3],@X[-1&7]);
633 eval(shift(@insns)); # ror
636 &pxor
(@X[0],@X[2]); # "X[0]"^="X[-6]"
637 eval(shift(@insns)); # body_20_39
640 eval(shift(@insns)); # rol
642 &movdqa
(@X[2],@X[0]);
643 &movdqa
(&QWP
(0+16*(($Xi-1)&3),"esp"),@X[3]); # X[]+K xfer to IALU
646 eval(shift(@insns)); # ror
650 eval(shift(@insns)); # body_20_39
654 eval(shift(@insns)); # rol
657 eval(shift(@insns)); # ror
660 &por
(@X[0],@X[2]); # "X[0]"<<<=2
661 eval(shift(@insns)); # body_20_39
663 &movdqa
(@X[2],&QWP
(64+16*(($Xi-6)%3),"esp")) if($Xi<19); # restore X[] from backtrace buffer
665 eval(shift(@insns)); # rol
668 eval(shift(@insns)); # ror
669 &movdqa
(@X[3],@X[0]) if ($Xi<19);
672 foreach (@insns) { eval; } # remaining instructions
674 $Xi++; push(@X,shift(@X)); # "rotate" X[]
677 sub Xuplast_ssse3_80
()
680 my @insns = (&$body,&$body,&$body,&$body); # 32 instructions
684 &paddd
(@X[3],@X[-1&7]);
690 &movdqa
(&QWP
(0+16*(($Xi-1)&3),"esp"),@X[3]); # X[]+K xfer IALU
692 foreach (@insns) { eval; } # remaining instructions
694 &mov
($inp=@T[1],&DWP
(192+4,"esp"));
695 &cmp ($inp,&DWP
(192+8,"esp"));
696 &je
(&label
("done"));
698 &movdqa
(@X[3],&QWP
(112+48,"esp")); # K_00_19
699 &movdqa
(@X[2],&QWP
(112+64,"esp")); # pbswap mask
700 &movdqu
(@X[-4&7],&QWP
(0,$inp)); # load input
701 &movdqu
(@X[-3&7],&QWP
(16,$inp));
702 &movdqu
(@X[-2&7],&QWP
(32,$inp));
703 &movdqu
(@X[-1&7],&QWP
(48,$inp));
705 &pshufb
(@X[-4&7],@X[2]); # byte swap
706 &mov
(&DWP
(192+4,"esp"),$inp);
707 &movdqa
(&QWP
(112-16,"esp"),@X[3]); # borrow last backtrace slot
715 my @insns = (&$body,&$body,&$body,&$body); # 32 instructions
720 &pshufb
(@X[($Xi-3)&7],@X[2]);
723 &paddd
(@X[($Xi-4)&7],@X[3]);
728 &movdqa
(&QWP
(0+16*$Xi,"esp"),@X[($Xi-4)&7]); # X[]+K xfer to IALU
731 &psubd
(@X[($Xi-4)&7],@X[3]);
733 foreach (@insns) { eval; }
740 my @insns = (&$body,&$body,&$body,&$body); # 32 instructions
743 foreach (@insns) { eval; }
748 '($a,$b,$c,$d,$e)=@V;'.
749 '&add ($e,&DWP(4*($j&15),"esp"));', # X[]+K xfer
751 '&mov (@T[1],$a);', # $b in next round
753 '&and (@T[0],$c);', # ($b&($c^$d))
754 '&xor ($c,$d);', # restore $c
757 '&$_ror ($b,$j?7:2);', # $b>>>2
758 '&add ($e,@T[0]);' .'$j++; unshift(@V,pop(@V)); unshift(@T,pop(@T));'
764 '($a,$b,$c,$d,$e)=@V;'.
765 '&add ($e,&DWP(4*($j++&15),"esp"));', # X[]+K xfer
766 '&xor (@T[0],$d);', # ($b^$d)
767 '&mov (@T[1],$a);', # $b in next round
769 '&xor (@T[0],$c);', # ($b^$d^$c)
771 '&$_ror ($b,7);', # $b>>>2
772 '&add ($e,@T[0]);' .'unshift(@V,pop(@V)); unshift(@T,pop(@T));'
778 '($a,$b,$c,$d,$e)=@V;'.
781 '&add ($e,&DWP(4*($j++&15),"esp"));', # X[]+K xfer
783 '&and (@T[0],$c);', # ($b&($c^$d))
784 '&$_ror ($b,7);', # $b>>>2
786 '&mov (@T[1],$a);', # $b in next round
789 '&xor ($c,$d);', # restore $c
790 '&add ($e,$a);' .'unshift(@V,pop(@V)); unshift(@T,pop(@T));'
794 &set_label
("loop",16);
795 &Xupdate_ssse3_16_31
(\
&body_00_19
);
796 &Xupdate_ssse3_16_31
(\
&body_00_19
);
797 &Xupdate_ssse3_16_31
(\
&body_00_19
);
798 &Xupdate_ssse3_16_31
(\
&body_00_19
);
799 &Xupdate_ssse3_32_79
(\
&body_00_19
);
800 &Xupdate_ssse3_32_79
(\
&body_20_39
);
801 &Xupdate_ssse3_32_79
(\
&body_20_39
);
802 &Xupdate_ssse3_32_79
(\
&body_20_39
);
803 &Xupdate_ssse3_32_79
(\
&body_20_39
);
804 &Xupdate_ssse3_32_79
(\
&body_20_39
);
805 &Xupdate_ssse3_32_79
(\
&body_40_59
);
806 &Xupdate_ssse3_32_79
(\
&body_40_59
);
807 &Xupdate_ssse3_32_79
(\
&body_40_59
);
808 &Xupdate_ssse3_32_79
(\
&body_40_59
);
809 &Xupdate_ssse3_32_79
(\
&body_40_59
);
810 &Xupdate_ssse3_32_79
(\
&body_20_39
);
811 &Xuplast_ssse3_80
(\
&body_20_39
); # can jump to "done"
813 $saved_j=$j; @saved_V=@V;
815 &Xloop_ssse3
(\
&body_20_39
);
816 &Xloop_ssse3
(\
&body_20_39
);
817 &Xloop_ssse3
(\
&body_20_39
);
819 &mov
(@T[1],&DWP
(192,"esp")); # update context
820 &add
($A,&DWP
(0,@T[1]));
821 &add
(@T[0],&DWP
(4,@T[1])); # $b
822 &add
($C,&DWP
(8,@T[1]));
823 &mov
(&DWP
(0,@T[1]),$A);
824 &add
($D,&DWP
(12,@T[1]));
825 &mov
(&DWP
(4,@T[1]),@T[0]);
826 &add
($E,&DWP
(16,@T[1]));
827 &mov
(&DWP
(8,@T[1]),$C);
829 &mov
(&DWP
(12,@T[1]),$D);
830 &mov
(&DWP
(16,@T[1]),$E);
831 &movdqa
(@X[0],@X[-3&7]);
833 &jmp
(&label
("loop"));
835 &set_label
("done",16); $j=$saved_j; @V=@saved_V;
837 &Xtail_ssse3
(\
&body_20_39
);
838 &Xtail_ssse3
(\
&body_20_39
);
839 &Xtail_ssse3
(\
&body_20_39
);
841 &mov
(@T[1],&DWP
(192,"esp")); # update context
842 &add
($A,&DWP
(0,@T[1]));
843 &mov
("esp",&DWP
(192+12,"esp")); # restore %esp
844 &add
(@T[0],&DWP
(4,@T[1])); # $b
845 &add
($C,&DWP
(8,@T[1]));
846 &mov
(&DWP
(0,@T[1]),$A);
847 &add
($D,&DWP
(12,@T[1]));
848 &mov
(&DWP
(4,@T[1]),@T[0]);
849 &add
($E,&DWP
(16,@T[1]));
850 &mov
(&DWP
(8,@T[1]),$C);
851 &mov
(&DWP
(12,@T[1]),$D);
852 &mov
(&DWP
(16,@T[1]),$E);
854 &function_end
("_sha1_block_data_order_ssse3");
857 my $Xi=4; # 4xSIMD Xupdate round, start pre-seeded
858 my @X=map("xmm$_",(4..7,0..3)); # pre-seeded for $Xi=4
859 my @V=($A,$B,$C,$D,$E);
860 my $j=0; # hash round
864 my $_rol=sub { &shld
(@_[0],@_) };
865 my $_ror=sub { &shrd
(@_[0],@_) };
867 &function_begin
("_sha1_block_data_order_avx");
868 &call
(&label
("pic_point")); # make it PIC!
869 &set_label
("pic_point");
871 &lea
($tmp1,&DWP
(&label
("K_XX_XX")."-".&label
("pic_point"),$tmp1));
872 &set_label
("avx_shortcut");
875 &vmovdqa
(@X[3],&QWP
(0,$tmp1)); # K_00_19
876 &vmovdqa
(@X[4],&QWP
(16,$tmp1)); # K_20_39
877 &vmovdqa
(@X[5],&QWP
(32,$tmp1)); # K_40_59
878 &vmovdqa
(@X[6],&QWP
(48,$tmp1)); # K_60_79
879 &vmovdqa
(@X[2],&QWP
(64,$tmp1)); # pbswap mask
881 &mov
($E,&wparam
(0)); # load argument block
882 &mov
($inp=@T[1],&wparam
(1));
883 &mov
($D,&wparam
(2));
888 # +0 X[0]+K X[1]+K X[2]+K X[3]+K # XMM->IALU xfer area
889 # X[4]+K X[5]+K X[6]+K X[7]+K
890 # X[8]+K X[9]+K X[10]+K X[11]+K
891 # X[12]+K X[13]+K X[14]+K X[15]+K
893 # +64 X[0] X[1] X[2] X[3] # XMM->XMM backtrace area
894 # X[4] X[5] X[6] X[7]
895 # X[8] X[9] X[10] X[11] # even borrowed for K_00_19
897 # +112 K_20_39 K_20_39 K_20_39 K_20_39 # constants
898 # K_40_59 K_40_59 K_40_59 K_40_59
899 # K_60_79 K_60_79 K_60_79 K_60_79
900 # K_00_19 K_00_19 K_00_19 K_00_19
903 # +192 ctx # argument block
910 &vmovdqa
(&QWP
(112+0,"esp"),@X[4]); # copy constants
911 &vmovdqa
(&QWP
(112+16,"esp"),@X[5]);
912 &vmovdqa
(&QWP
(112+32,"esp"),@X[6]);
913 &shl
($D,6); # len*64
914 &vmovdqa
(&QWP
(112+48,"esp"),@X[3]);
915 &add
($D,$inp); # end of input
916 &vmovdqa
(&QWP
(112+64,"esp"),@X[2]);
918 &mov
(&DWP
(192+0,"esp"),$E); # save argument block
919 &mov
(&DWP
(192+4,"esp"),$inp);
920 &mov
(&DWP
(192+8,"esp"),$D);
921 &mov
(&DWP
(192+12,"esp"),@T[0]); # save original %esp
923 &mov
($A,&DWP
(0,$E)); # load context
924 &mov
($B,&DWP
(4,$E));
925 &mov
($C,&DWP
(8,$E));
926 &mov
($D,&DWP
(12,$E));
927 &mov
($E,&DWP
(16,$E));
928 &mov
(@T[0],$B); # magic seed
930 &vmovdqu
(@X[-4&7],&QWP
(-64,$inp)); # load input to %xmm[0-3]
931 &vmovdqu
(@X[-3&7],&QWP
(-48,$inp));
932 &vmovdqu
(@X[-2&7],&QWP
(-32,$inp));
933 &vmovdqu
(@X[-1&7],&QWP
(-16,$inp));
934 &vpshufb
(@X[-4&7],@X[-4&7],@X[2]); # byte swap
935 &vpshufb
(@X[-3&7],@X[-3&7],@X[2]);
936 &vpshufb
(@X[-2&7],@X[-2&7],@X[2]);
937 &vmovdqa
(&QWP
(112-16,"esp"),@X[3]); # borrow last backtrace slot
938 &vpshufb
(@X[-1&7],@X[-1&7],@X[2]);
939 &vpaddd
(@X[0],@X[-4&7],@X[3]); # add K_00_19
940 &vpaddd
(@X[1],@X[-3&7],@X[3]);
941 &vpaddd
(@X[2],@X[-2&7],@X[3]);
942 &vmovdqa
(&QWP
(0,"esp"),@X[0]); # X[]+K xfer to IALU
943 &vmovdqa
(&QWP
(0+16,"esp"),@X[1]);
944 &vmovdqa
(&QWP
(0+32,"esp"),@X[2]);
945 &jmp
(&label
("loop"));
947 sub Xupdate_avx_16_31
() # recall that $Xi starts wtih 4
950 my @insns = (&$body,&$body,&$body,&$body); # 40 instructions
955 &vpalignr
(@X[0],@X[-3&7],@X[-4&7],8); # compose "X[-14]" in "X[0]"
959 &vpaddd
(@X[3],@X[3],@X[-1&7]);
960 &vmovdqa
(&QWP
(64+16*(($Xi-4)%3),"esp"),@X[-4&7]);# save X[] to backtrace buffer
963 &vpsrldq
(@X[2],@X[-1&7],4); # "X[-3]", 3 dwords
966 &vpxor
(@X[0],@X[0],@X[-4&7]); # "X[0]"^="X[-16]"
970 &vpxor
(@X[2],@X[2],@X[-2&7]); # "X[-3]"^"X[-8]"
973 &vmovdqa
(&QWP
(0+16*(($Xi-1)&3),"esp"),@X[3]); # X[]+K xfer to IALU
977 &vpxor
(@X[0],@X[0],@X[2]); # "X[0]"^="X[-3]"^"X[-8]"
983 &vpsrld
(@X[2],@X[0],31);
989 &vpslldq
(@X[4],@X[0],12); # "X[0]"<<96, extract one dword
990 &vpaddd
(@X[0],@X[0],@X[0]);
996 &vpsrld
(@X[3],@X[4],30);
997 &vpor
(@X[0],@X[0],@X[2]); # "X[0]"<<<=1
1000 eval(shift(@insns));
1001 eval(shift(@insns));
1003 &vpslld
(@X[4],@X[4],2);
1004 &vmovdqa
(@X[2],&QWP
(64+16*(($Xi-6)%3),"esp")) if ($Xi>5); # restore X[] from backtrace buffer
1005 eval(shift(@insns));
1006 eval(shift(@insns));
1007 &vpxor
(@X[0],@X[0],@X[3]);
1008 eval(shift(@insns));
1009 eval(shift(@insns));
1010 eval(shift(@insns));
1011 eval(shift(@insns));
1013 &vpxor
(@X[0],@X[0],@X[4]); # "X[0]"^=("X[0]"<<96)<<<2
1014 eval(shift(@insns));
1015 eval(shift(@insns));
1016 &vmovdqa
(@X[4],&QWP
(112-16+16*(($Xi)/5),"esp")); # K_XX_XX
1017 eval(shift(@insns));
1018 eval(shift(@insns));
1020 foreach (@insns) { eval; } # remaining instructions [if any]
1022 $Xi++; push(@X,shift(@X)); # "rotate" X[]
1025 sub Xupdate_avx_32_79
()
1028 my @insns = (&$body,&$body,&$body,&$body); # 32 to 48 instructions
1029 my ($a,$b,$c,$d,$e);
1031 &vpalignr
(@X[2],@X[-1&7],@X[-2&7],8); # compose "X[-6]"
1032 &vpxor
(@X[0],@X[0],@X[-4&7]); # "X[0]"="X[-32]"^"X[-16]"
1033 eval(shift(@insns)); # body_20_39
1034 eval(shift(@insns));
1035 eval(shift(@insns));
1036 eval(shift(@insns)); # rol
1038 &vpxor
(@X[0],@X[0],@X[-7&7]); # "X[0]"^="X[-28]"
1039 &vmovdqa
(&QWP
(64+16*(($Xi-4)%3),"esp"),@X[-4&7]); # save X[] to backtrace buffer
1040 eval(shift(@insns));
1041 eval(shift(@insns));
1043 &vmovdqa
(@X[4],@X[3]); # "perpetuate" K_XX_XX...
1044 } else { # ... or load next one
1045 &vmovdqa
(@X[4],&QWP
(112-16+16*($Xi/5),"esp"));
1047 &vpaddd
(@X[3],@X[3],@X[-1&7]);
1048 eval(shift(@insns)); # ror
1049 eval(shift(@insns));
1051 &vpxor
(@X[0],@X[0],@X[2]); # "X[0]"^="X[-6]"
1052 eval(shift(@insns)); # body_20_39
1053 eval(shift(@insns));
1054 eval(shift(@insns));
1055 eval(shift(@insns)); # rol
1057 &vpsrld
(@X[2],@X[0],30);
1058 &vmovdqa
(&QWP
(0+16*(($Xi-1)&3),"esp"),@X[3]); # X[]+K xfer to IALU
1059 eval(shift(@insns));
1060 eval(shift(@insns));
1061 eval(shift(@insns)); # ror
1062 eval(shift(@insns));
1064 &vpslld
(@X[0],@X[0],2);
1065 eval(shift(@insns)); # body_20_39
1066 eval(shift(@insns));
1067 eval(shift(@insns));
1068 eval(shift(@insns)); # rol
1069 eval(shift(@insns));
1070 eval(shift(@insns));
1071 eval(shift(@insns)); # ror
1072 eval(shift(@insns));
1074 &vpor
(@X[0],@X[0],@X[2]); # "X[0]"<<<=2
1075 eval(shift(@insns)); # body_20_39
1076 eval(shift(@insns));
1077 &vmovdqa
(@X[2],&QWP
(64+16*(($Xi-6)%3),"esp")) if($Xi<19); # restore X[] from backtrace buffer
1078 eval(shift(@insns));
1079 eval(shift(@insns)); # rol
1080 eval(shift(@insns));
1081 eval(shift(@insns));
1082 eval(shift(@insns)); # ror
1083 eval(shift(@insns));
1085 foreach (@insns) { eval; } # remaining instructions
1087 $Xi++; push(@X,shift(@X)); # "rotate" X[]
1090 sub Xuplast_avx_80
()
1093 my @insns = (&$body,&$body,&$body,&$body); # 32 instructions
1094 my ($a,$b,$c,$d,$e);
1096 eval(shift(@insns));
1097 &vpaddd
(@X[3],@X[3],@X[-1&7]);
1098 eval(shift(@insns));
1099 eval(shift(@insns));
1100 eval(shift(@insns));
1101 eval(shift(@insns));
1103 &vmovdqa
(&QWP
(0+16*(($Xi-1)&3),"esp"),@X[3]); # X[]+K xfer IALU
1105 foreach (@insns) { eval; } # remaining instructions
1107 &mov
($inp=@T[1],&DWP
(192+4,"esp"));
1108 &cmp ($inp,&DWP
(192+8,"esp"));
1109 &je
(&label
("done"));
1111 &vmovdqa
(@X[3],&QWP
(112+48,"esp")); # K_00_19
1112 &vmovdqa
(@X[2],&QWP
(112+64,"esp")); # pbswap mask
1113 &vmovdqu
(@X[-4&7],&QWP
(0,$inp)); # load input
1114 &vmovdqu
(@X[-3&7],&QWP
(16,$inp));
1115 &vmovdqu
(@X[-2&7],&QWP
(32,$inp));
1116 &vmovdqu
(@X[-1&7],&QWP
(48,$inp));
1118 &vpshufb
(@X[-4&7],@X[-4&7],@X[2]); # byte swap
1119 &mov
(&DWP
(192+4,"esp"),$inp);
1120 &vmovdqa
(&QWP
(112-16,"esp"),@X[3]); # borrow last backtrace slot
1128 my @insns = (&$body,&$body,&$body,&$body); # 32 instructions
1129 my ($a,$b,$c,$d,$e);
1131 eval(shift(@insns));
1132 eval(shift(@insns));
1133 &vpshufb
(@X[($Xi-3)&7],@X[($Xi-3)&7],@X[2]);
1134 eval(shift(@insns));
1135 eval(shift(@insns));
1136 &vpaddd
(@X[$Xi&7],@X[($Xi-4)&7],@X[3]);
1137 eval(shift(@insns));
1138 eval(shift(@insns));
1139 eval(shift(@insns));
1140 eval(shift(@insns));
1141 &vmovdqa
(&QWP
(0+16*$Xi,"esp"),@X[$Xi&7]); # X[]+K xfer to IALU
1142 eval(shift(@insns));
1143 eval(shift(@insns));
1145 foreach (@insns) { eval; }
1152 my @insns = (&$body,&$body,&$body,&$body); # 32 instructions
1153 my ($a,$b,$c,$d,$e);
1155 foreach (@insns) { eval; }
1158 &set_label
("loop",16);
1159 &Xupdate_avx_16_31
(\
&body_00_19
);
1160 &Xupdate_avx_16_31
(\
&body_00_19
);
1161 &Xupdate_avx_16_31
(\
&body_00_19
);
1162 &Xupdate_avx_16_31
(\
&body_00_19
);
1163 &Xupdate_avx_32_79
(\
&body_00_19
);
1164 &Xupdate_avx_32_79
(\
&body_20_39
);
1165 &Xupdate_avx_32_79
(\
&body_20_39
);
1166 &Xupdate_avx_32_79
(\
&body_20_39
);
1167 &Xupdate_avx_32_79
(\
&body_20_39
);
1168 &Xupdate_avx_32_79
(\
&body_20_39
);
1169 &Xupdate_avx_32_79
(\
&body_40_59
);
1170 &Xupdate_avx_32_79
(\
&body_40_59
);
1171 &Xupdate_avx_32_79
(\
&body_40_59
);
1172 &Xupdate_avx_32_79
(\
&body_40_59
);
1173 &Xupdate_avx_32_79
(\
&body_40_59
);
1174 &Xupdate_avx_32_79
(\
&body_20_39
);
1175 &Xuplast_avx_80
(\
&body_20_39
); # can jump to "done"
1177 $saved_j=$j; @saved_V=@V;
1179 &Xloop_avx
(\
&body_20_39
);
1180 &Xloop_avx
(\
&body_20_39
);
1181 &Xloop_avx
(\
&body_20_39
);
1183 &mov
(@T[1],&DWP
(192,"esp")); # update context
1184 &add
($A,&DWP
(0,@T[1]));
1185 &add
(@T[0],&DWP
(4,@T[1])); # $b
1186 &add
($C,&DWP
(8,@T[1]));
1187 &mov
(&DWP
(0,@T[1]),$A);
1188 &add
($D,&DWP
(12,@T[1]));
1189 &mov
(&DWP
(4,@T[1]),@T[0]);
1190 &add
($E,&DWP
(16,@T[1]));
1191 &mov
(&DWP
(8,@T[1]),$C);
1193 &mov
(&DWP
(12,@T[1]),$D);
1194 &mov
(&DWP
(16,@T[1]),$E);
1196 &jmp
(&label
("loop"));
1198 &set_label
("done",16); $j=$saved_j; @V=@saved_V;
1200 &Xtail_avx
(\
&body_20_39
);
1201 &Xtail_avx
(\
&body_20_39
);
1202 &Xtail_avx
(\
&body_20_39
);
1206 &mov
(@T[1],&DWP
(192,"esp")); # update context
1207 &add
($A,&DWP
(0,@T[1]));
1208 &mov
("esp",&DWP
(192+12,"esp")); # restore %esp
1209 &add
(@T[0],&DWP
(4,@T[1])); # $b
1210 &add
($C,&DWP
(8,@T[1]));
1211 &mov
(&DWP
(0,@T[1]),$A);
1212 &add
($D,&DWP
(12,@T[1]));
1213 &mov
(&DWP
(4,@T[1]),@T[0]);
1214 &add
($E,&DWP
(16,@T[1]));
1215 &mov
(&DWP
(8,@T[1]),$C);
1216 &mov
(&DWP
(12,@T[1]),$D);
1217 &mov
(&DWP
(16,@T[1]),$E);
1218 &function_end
("_sha1_block_data_order_avx");
1220 &set_label
("K_XX_XX",64);
1221 &data_word
(0x5a827999,0x5a827999,0x5a827999,0x5a827999); # K_00_19
1222 &data_word
(0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1); # K_20_39
1223 &data_word
(0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc); # K_40_59
1224 &data_word
(0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6); # K_60_79
1225 &data_word
(0x00010203,0x04050607,0x08090a0b,0x0c0d0e0f); # pbswap mask
1227 &asciz
("SHA1 block transform for x86, CRYPTOGAMS by <appro\@openssl.org>");