summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/aes/asm/aesni-sha1-x86_64.pl
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/aes/asm/aesni-sha1-x86_64.pl')
-rw-r--r--src/lib/libcrypto/aes/asm/aesni-sha1-x86_64.pl1237
1 files changed, 0 insertions, 1237 deletions
diff --git a/src/lib/libcrypto/aes/asm/aesni-sha1-x86_64.pl b/src/lib/libcrypto/aes/asm/aesni-sha1-x86_64.pl
deleted file mode 100644
index 5eb5b7bf65..0000000000
--- a/src/lib/libcrypto/aes/asm/aesni-sha1-x86_64.pl
+++ /dev/null
@@ -1,1237 +0,0 @@
1#!/usr/bin/env perl
2#
3# ====================================================================
4# Written by Andy Polyakov <appro@openssl.org> 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# ====================================================================
9#
10# June 2011
11#
12# This is AESNI-CBC+SHA1 "stitch" implementation. The idea, as spelled
13# in http://download.intel.com/design/intarch/papers/323686.pdf, is
14# that since AESNI-CBC encrypt exhibit *very* low instruction-level
15# parallelism, interleaving it with another algorithm would allow to
16# utilize processor resources better and achieve better performance.
17# SHA1 instruction sequences(*) are taken from sha1-x86_64.pl and
18# AESNI code is weaved into it. Below are performance numbers in
19# cycles per processed byte, less is better, for standalone AESNI-CBC
20# encrypt, sum of the latter and standalone SHA1, and "stitched"
21# subroutine:
22#
23# AES-128-CBC +SHA1 stitch gain
24# Westmere 3.77[+5.6] 9.37 6.65 +41%
25# Sandy Bridge 5.05[+5.2(6.3)] 10.25(11.35) 6.16(7.08) +67%(+60%)
26#
27# AES-192-CBC
28# Westmere 4.51 10.11 6.97 +45%
29# Sandy Bridge 6.05 11.25(12.35) 6.34(7.27) +77%(+70%)
30#
31# AES-256-CBC
32# Westmere 5.25 10.85 7.25 +50%
33# Sandy Bridge 7.05 12.25(13.35) 7.06(7.70) +74%(+73%)
34#
35# (*) There are two code paths: SSSE3 and AVX. See sha1-568.pl for
36# background information. Above numbers in parentheses are SSSE3
37# results collected on AVX-capable CPU, i.e. apply on OSes that
38# don't support AVX.
39#
40# Needless to mention that it makes no sense to implement "stitched"
41# *decrypt* subroutine. Because *both* AESNI-CBC decrypt and SHA1
42# fully utilize parallelism, so stitching would not give any gain
43# anyway. Well, there might be some, e.g. because of better cache
44# locality... For reference, here are performance results for
45# standalone AESNI-CBC decrypt:
46#
47# AES-128-CBC AES-192-CBC AES-256-CBC
48# Westmere 1.31 1.55 1.80
49# Sandy Bridge 0.93 1.06 1.22
50
51$flavour = shift;
52$output = shift;
53if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
54
55$win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
56
57$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
58( $xlate="${dir}x86_64-xlate.pl" and -f $xlate ) or
59( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
60die "can't locate x86_64-xlate.pl";
61
62$avx=1 if (`$ENV{CC} -Wa,-v -c -o /dev/null -x assembler /dev/null 2>&1`
63 =~ /GNU assembler version ([2-9]\.[0-9]+)/ &&
64 $1>=2.19);
65$avx=1 if (!$avx && $win64 && ($flavour =~ /nasm/ || $ENV{ASM} =~ /nasm/) &&
66 `nasm -v 2>&1` =~ /NASM version ([2-9]\.[0-9]+)/ &&
67 $1>=2.09);
68$avx=1 if (!$avx && $win64 && ($flavour =~ /masm/ || $ENV{ASM} =~ /ml64/) &&
69 `ml64 2>&1` =~ /Version ([0-9]+)\./ &&
70 $1>=10);
71
72open OUT,"| \"$^X\" $xlate $flavour $output";
73*STDOUT=*OUT;
74
75# void aesni_cbc_sha1_enc(const void *inp,
76# void *out,
77# size_t length,
78# const AES_KEY *key,
79# unsigned char *iv,
80# SHA_CTX *ctx,
81# const void *in0);
82
83$code.=<<___;
84.text
85.extern OPENSSL_ia32cap_P
86.hidden OPENSSL_ia32cap_P
87
88.globl aesni_cbc_sha1_enc
89.type aesni_cbc_sha1_enc,\@abi-omnipotent
90.align 16
91aesni_cbc_sha1_enc:
92 _CET_ENDBR
93 # caller should check for SSSE3 and AES-NI bits
94 mov OPENSSL_ia32cap_P+0(%rip),%r10d
95 mov OPENSSL_ia32cap_P+4(%rip),%r11d
96___
97$code.=<<___ if ($avx);
98 and \$IA32CAP_MASK1_AVX,%r11d # mask AVX bit
99 and \$IA32CAP_MASK0_INTEL,%r10d # mask "Intel CPU" bit
100 or %r11d,%r10d
101 cmp \$(IA32CAP_MASK1_AVX|IA32CAP_MASK0_INTEL),%r10d
102 je aesni_cbc_sha1_enc_avx
103___
104$code.=<<___;
105 jmp aesni_cbc_sha1_enc_ssse3
106 ret
107.size aesni_cbc_sha1_enc,.-aesni_cbc_sha1_enc
108___
109
110my ($in0,$out,$len,$key,$ivp,$ctx,$inp)=("%rdi","%rsi","%rdx","%rcx","%r8","%r9","%r10");
111
112my $Xi=4;
113my @X=map("%xmm$_",(4..7,0..3));
114my @Tx=map("%xmm$_",(8..10));
115my @V=($A,$B,$C,$D,$E)=("%eax","%ebx","%ecx","%edx","%ebp"); # size optimization
116my @T=("%esi","%edi");
117my $j=0; my $jj=0; my $r=0; my $sn=0;
118my $K_XX_XX="%r11";
119my ($iv,$in,$rndkey0)=map("%xmm$_",(11..13));
120my @rndkey=("%xmm14","%xmm15");
121
122sub AUTOLOAD() # thunk [simplified] 32-bit style perlasm
123{ my $opcode = $AUTOLOAD; $opcode =~ s/.*:://;
124 my $arg = pop;
125 $arg = "\$$arg" if ($arg*1 eq $arg);
126 $code .= "\t$opcode\t".join(',',$arg,reverse @_)."\n";
127}
128
129my $_rol=sub { &rol(@_) };
130my $_ror=sub { &ror(@_) };
131
132$code.=<<___;
133.type aesni_cbc_sha1_enc_ssse3,\@function,6
134.align 16
135aesni_cbc_sha1_enc_ssse3:
136 _CET_ENDBR
137 mov `($win64?56:8)`(%rsp),$inp # load 7th argument
138 #shr \$6,$len # debugging artefact
139 #jz .Lepilogue_ssse3 # debugging artefact
140 push %rbx
141 push %rbp
142 push %r12
143 push %r13
144 push %r14
145 push %r15
146 lea `-104-($win64?10*16:0)`(%rsp),%rsp
147 #mov $in0,$inp # debugging artefact
148 #lea 64(%rsp),$ctx # debugging artefact
149___
150$code.=<<___ if ($win64);
151 movaps %xmm6,96+0(%rsp)
152 movaps %xmm7,96+16(%rsp)
153 movaps %xmm8,96+32(%rsp)
154 movaps %xmm9,96+48(%rsp)
155 movaps %xmm10,96+64(%rsp)
156 movaps %xmm11,96+80(%rsp)
157 movaps %xmm12,96+96(%rsp)
158 movaps %xmm13,96+112(%rsp)
159 movaps %xmm14,96+128(%rsp)
160 movaps %xmm15,96+144(%rsp)
161.Lprologue_ssse3:
162___
163$code.=<<___;
164 mov $in0,%r12 # reassign arguments
165 mov $out,%r13
166 mov $len,%r14
167 mov $key,%r15
168 movdqu ($ivp),$iv # load IV
169 mov $ivp,88(%rsp) # save $ivp
170___
171my ($in0,$out,$len,$key)=map("%r$_",(12..15)); # reassign arguments
172my $rounds="${ivp}d";
173$code.=<<___;
174 shl \$6,$len
175 sub $in0,$out
176 mov 240($key),$rounds
177 add $inp,$len # end of input
178
179 lea K_XX_XX(%rip),$K_XX_XX
180 mov 0($ctx),$A # load context
181 mov 4($ctx),$B
182 mov 8($ctx),$C
183 mov 12($ctx),$D
184 mov $B,@T[0] # magic seed
185 mov 16($ctx),$E
186
187 movdqa 64($K_XX_XX),@X[2] # pbswap mask
188 movdqa 0($K_XX_XX),@Tx[1] # K_00_19
189 movdqu 0($inp),@X[-4&7] # load input to %xmm[0-3]
190 movdqu 16($inp),@X[-3&7]
191 movdqu 32($inp),@X[-2&7]
192 movdqu 48($inp),@X[-1&7]
193 pshufb @X[2],@X[-4&7] # byte swap
194 add \$64,$inp
195 pshufb @X[2],@X[-3&7]
196 pshufb @X[2],@X[-2&7]
197 pshufb @X[2],@X[-1&7]
198 paddd @Tx[1],@X[-4&7] # add K_00_19
199 paddd @Tx[1],@X[-3&7]
200 paddd @Tx[1],@X[-2&7]
201 movdqa @X[-4&7],0(%rsp) # X[]+K xfer to IALU
202 psubd @Tx[1],@X[-4&7] # restore X[]
203 movdqa @X[-3&7],16(%rsp)
204 psubd @Tx[1],@X[-3&7]
205 movdqa @X[-2&7],32(%rsp)
206 psubd @Tx[1],@X[-2&7]
207 movups ($key),$rndkey0 # $key[0]
208 movups 16($key),$rndkey[0] # forward reference
209 jmp .Loop_ssse3
210___
211
212my $aesenc=sub {
213 use integer;
214 my ($n,$k)=($r/10,$r%10);
215 if ($k==0) {
216 $code.=<<___;
217 movups `16*$n`($in0),$in # load input
218 xorps $rndkey0,$in
219___
220 $code.=<<___ if ($n);
221 movups $iv,`16*($n-1)`($out,$in0) # write output
222___
223 $code.=<<___;
224 xorps $in,$iv
225 aesenc $rndkey[0],$iv
226 movups `32+16*$k`($key),$rndkey[1]
227___
228 } elsif ($k==9) {
229 $sn++;
230 $code.=<<___;
231 cmp \$11,$rounds
232 jb .Laesenclast$sn
233 movups `32+16*($k+0)`($key),$rndkey[1]
234 aesenc $rndkey[0],$iv
235 movups `32+16*($k+1)`($key),$rndkey[0]
236 aesenc $rndkey[1],$iv
237 je .Laesenclast$sn
238 movups `32+16*($k+2)`($key),$rndkey[1]
239 aesenc $rndkey[0],$iv
240 movups `32+16*($k+3)`($key),$rndkey[0]
241 aesenc $rndkey[1],$iv
242.Laesenclast$sn:
243 aesenclast $rndkey[0],$iv
244 movups 16($key),$rndkey[1] # forward reference
245___
246 } else {
247 $code.=<<___;
248 aesenc $rndkey[0],$iv
249 movups `32+16*$k`($key),$rndkey[1]
250___
251 }
252 $r++; unshift(@rndkey,pop(@rndkey));
253};
254
255sub Xupdate_ssse3_16_31() # recall that $Xi starts with 4
256{ use integer;
257 my $body = shift;
258 my @insns = (&$body,&$body,&$body,&$body); # 40 instructions
259 my ($a,$b,$c,$d,$e);
260
261 &movdqa (@X[0],@X[-3&7]);
262 eval(shift(@insns));
263 eval(shift(@insns));
264 &movdqa (@Tx[0],@X[-1&7]);
265 &palignr(@X[0],@X[-4&7],8); # compose "X[-14]" in "X[0]"
266 eval(shift(@insns));
267 eval(shift(@insns));
268
269 &paddd (@Tx[1],@X[-1&7]);
270 eval(shift(@insns));
271 eval(shift(@insns));
272 &psrldq (@Tx[0],4); # "X[-3]", 3 dwords
273 eval(shift(@insns));
274 eval(shift(@insns));
275 &pxor (@X[0],@X[-4&7]); # "X[0]"^="X[-16]"
276 eval(shift(@insns));
277 eval(shift(@insns));
278
279 &pxor (@Tx[0],@X[-2&7]); # "X[-3]"^"X[-8]"
280 eval(shift(@insns));
281 eval(shift(@insns));
282 eval(shift(@insns));
283 eval(shift(@insns));
284
285 &pxor (@X[0],@Tx[0]); # "X[0]"^="X[-3]"^"X[-8]"
286 eval(shift(@insns));
287 eval(shift(@insns));
288 &movdqa (eval(16*(($Xi-1)&3))."(%rsp)",@Tx[1]); # X[]+K xfer to IALU
289 eval(shift(@insns));
290 eval(shift(@insns));
291
292 &movdqa (@Tx[2],@X[0]);
293 &movdqa (@Tx[0],@X[0]);
294 eval(shift(@insns));
295 eval(shift(@insns));
296 eval(shift(@insns));
297 eval(shift(@insns));
298
299 &pslldq (@Tx[2],12); # "X[0]"<<96, extract one dword
300 &paddd (@X[0],@X[0]);
301 eval(shift(@insns));
302 eval(shift(@insns));
303 eval(shift(@insns));
304 eval(shift(@insns));
305
306 &psrld (@Tx[0],31);
307 eval(shift(@insns));
308 eval(shift(@insns));
309 &movdqa (@Tx[1],@Tx[2]);
310 eval(shift(@insns));
311 eval(shift(@insns));
312
313 &psrld (@Tx[2],30);
314 &por (@X[0],@Tx[0]); # "X[0]"<<<=1
315 eval(shift(@insns));
316 eval(shift(@insns));
317 eval(shift(@insns));
318 eval(shift(@insns));
319
320 &pslld (@Tx[1],2);
321 &pxor (@X[0],@Tx[2]);
322 eval(shift(@insns));
323 eval(shift(@insns));
324 &movdqa (@Tx[2],eval(16*(($Xi)/5))."($K_XX_XX)"); # K_XX_XX
325 eval(shift(@insns));
326 eval(shift(@insns));
327
328 &pxor (@X[0],@Tx[1]); # "X[0]"^=("X[0]">>96)<<<2
329
330 foreach (@insns) { eval; } # remaining instructions [if any]
331
332 $Xi++; push(@X,shift(@X)); # "rotate" X[]
333 push(@Tx,shift(@Tx));
334}
335
336sub Xupdate_ssse3_32_79()
337{ use integer;
338 my $body = shift;
339 my @insns = (&$body,&$body,&$body,&$body); # 32 to 48 instructions
340 my ($a,$b,$c,$d,$e);
341
342 &movdqa (@Tx[0],@X[-1&7]) if ($Xi==8);
343 eval(shift(@insns)); # body_20_39
344 &pxor (@X[0],@X[-4&7]); # "X[0]"="X[-32]"^"X[-16]"
345 &palignr(@Tx[0],@X[-2&7],8); # compose "X[-6]"
346 eval(shift(@insns));
347 eval(shift(@insns));
348 eval(shift(@insns)); # rol
349
350 &pxor (@X[0],@X[-7&7]); # "X[0]"^="X[-28]"
351 eval(shift(@insns));
352 eval(shift(@insns)) if (@insns[0] !~ /&ro[rl]/);
353 if ($Xi%5) {
354 &movdqa (@Tx[2],@Tx[1]);# "perpetuate" K_XX_XX...
355 } else { # ... or load next one
356 &movdqa (@Tx[2],eval(16*($Xi/5))."($K_XX_XX)");
357 }
358 &paddd (@Tx[1],@X[-1&7]);
359 eval(shift(@insns)); # ror
360 eval(shift(@insns));
361
362 &pxor (@X[0],@Tx[0]); # "X[0]"^="X[-6]"
363 eval(shift(@insns)); # body_20_39
364 eval(shift(@insns));
365 eval(shift(@insns));
366 eval(shift(@insns)); # rol
367
368 &movdqa (@Tx[0],@X[0]);
369 &movdqa (eval(16*(($Xi-1)&3))."(%rsp)",@Tx[1]); # X[]+K xfer to IALU
370 eval(shift(@insns));
371 eval(shift(@insns));
372 eval(shift(@insns)); # ror
373 eval(shift(@insns));
374
375 &pslld (@X[0],2);
376 eval(shift(@insns)); # body_20_39
377 eval(shift(@insns));
378 &psrld (@Tx[0],30);
379 eval(shift(@insns));
380 eval(shift(@insns)); # rol
381 eval(shift(@insns));
382 eval(shift(@insns));
383 eval(shift(@insns)); # ror
384 eval(shift(@insns));
385
386 &por (@X[0],@Tx[0]); # "X[0]"<<<=2
387 eval(shift(@insns)); # body_20_39
388 eval(shift(@insns));
389 &movdqa (@Tx[1],@X[0]) if ($Xi<19);
390 eval(shift(@insns));
391 eval(shift(@insns)); # rol
392 eval(shift(@insns));
393 eval(shift(@insns));
394 eval(shift(@insns)); # rol
395 eval(shift(@insns));
396
397 foreach (@insns) { eval; } # remaining instructions
398
399 $Xi++; push(@X,shift(@X)); # "rotate" X[]
400 push(@Tx,shift(@Tx));
401}
402
403sub Xuplast_ssse3_80()
404{ use integer;
405 my $body = shift;
406 my @insns = (&$body,&$body,&$body,&$body); # 32 instructions
407 my ($a,$b,$c,$d,$e);
408
409 eval(shift(@insns));
410 &paddd (@Tx[1],@X[-1&7]);
411 eval(shift(@insns));
412 eval(shift(@insns));
413 eval(shift(@insns));
414 eval(shift(@insns));
415
416 &movdqa (eval(16*(($Xi-1)&3))."(%rsp)",@Tx[1]); # X[]+K xfer IALU
417
418 foreach (@insns) { eval; } # remaining instructions
419
420 &cmp ($inp,$len);
421 &je (".Ldone_ssse3");
422
423 unshift(@Tx,pop(@Tx));
424
425 &movdqa (@X[2],"64($K_XX_XX)"); # pbswap mask
426 &movdqa (@Tx[1],"0($K_XX_XX)"); # K_00_19
427 &movdqu (@X[-4&7],"0($inp)"); # load input
428 &movdqu (@X[-3&7],"16($inp)");
429 &movdqu (@X[-2&7],"32($inp)");
430 &movdqu (@X[-1&7],"48($inp)");
431 &pshufb (@X[-4&7],@X[2]); # byte swap
432 &add ($inp,64);
433
434 $Xi=0;
435}
436
437sub Xloop_ssse3()
438{ use integer;
439 my $body = shift;
440 my @insns = (&$body,&$body,&$body,&$body); # 32 instructions
441 my ($a,$b,$c,$d,$e);
442
443 eval(shift(@insns));
444 eval(shift(@insns));
445 &pshufb (@X[($Xi-3)&7],@X[2]);
446 eval(shift(@insns));
447 eval(shift(@insns));
448 &paddd (@X[($Xi-4)&7],@Tx[1]);
449 eval(shift(@insns));
450 eval(shift(@insns));
451 eval(shift(@insns));
452 eval(shift(@insns));
453 &movdqa (eval(16*$Xi)."(%rsp)",@X[($Xi-4)&7]); # X[]+K xfer to IALU
454 eval(shift(@insns));
455 eval(shift(@insns));
456 &psubd (@X[($Xi-4)&7],@Tx[1]);
457
458 foreach (@insns) { eval; }
459 $Xi++;
460}
461
462sub Xtail_ssse3()
463{ use integer;
464 my $body = shift;
465 my @insns = (&$body,&$body,&$body,&$body); # 32 instructions
466 my ($a,$b,$c,$d,$e);
467
468 foreach (@insns) { eval; }
469}
470
471sub body_00_19 () {
472 use integer;
473 my ($k,$n);
474 my @r=(
475 '($a,$b,$c,$d,$e)=@V;'.
476 '&add ($e,eval(4*($j&15))."(%rsp)");', # X[]+K xfer
477 '&xor ($c,$d);',
478 '&mov (@T[1],$a);', # $b in next round
479 '&$_rol ($a,5);',
480 '&and (@T[0],$c);', # ($b&($c^$d))
481 '&xor ($c,$d);', # restore $c
482 '&xor (@T[0],$d);',
483 '&add ($e,$a);',
484 '&$_ror ($b,$j?7:2);', # $b>>>2
485 '&add ($e,@T[0]);' .'$j++; unshift(@V,pop(@V)); unshift(@T,pop(@T));'
486 );
487 $n = scalar(@r);
488 $k = (($jj+1)*12/20)*20*$n/12; # 12 aesencs per these 20 rounds
489 @r[$k%$n].='&$aesenc();' if ($jj==$k/$n);
490 $jj++;
491 return @r;
492}
493
494sub body_20_39 () {
495 use integer;
496 my ($k,$n);
497 my @r=(
498 '($a,$b,$c,$d,$e)=@V;'.
499 '&add ($e,eval(4*($j++&15))."(%rsp)");', # X[]+K xfer
500 '&xor (@T[0],$d);', # ($b^$d)
501 '&mov (@T[1],$a);', # $b in next round
502 '&$_rol ($a,5);',
503 '&xor (@T[0],$c);', # ($b^$d^$c)
504 '&add ($e,$a);',
505 '&$_ror ($b,7);', # $b>>>2
506 '&add ($e,@T[0]);' .'unshift(@V,pop(@V)); unshift(@T,pop(@T));'
507 );
508 $n = scalar(@r);
509 $k = (($jj+1)*8/20)*20*$n/8; # 8 aesencs per these 20 rounds
510 @r[$k%$n].='&$aesenc();' if ($jj==$k/$n);
511 $jj++;
512 return @r;
513}
514
515sub body_40_59 () {
516 use integer;
517 my ($k,$n);
518 my @r=(
519 '($a,$b,$c,$d,$e)=@V;'.
520 '&mov (@T[1],$c);',
521 '&xor ($c,$d);',
522 '&add ($e,eval(4*($j++&15))."(%rsp)");', # X[]+K xfer
523 '&and (@T[1],$d);',
524 '&and (@T[0],$c);', # ($b&($c^$d))
525 '&$_ror ($b,7);', # $b>>>2
526 '&add ($e,@T[1]);',
527 '&mov (@T[1],$a);', # $b in next round
528 '&$_rol ($a,5);',
529 '&add ($e,@T[0]);',
530 '&xor ($c,$d);', # restore $c
531 '&add ($e,$a);' .'unshift(@V,pop(@V)); unshift(@T,pop(@T));'
532 );
533 $n = scalar(@r);
534 $k=(($jj+1)*12/20)*20*$n/12; # 12 aesencs per these 20 rounds
535 @r[$k%$n].='&$aesenc();' if ($jj==$k/$n);
536 $jj++;
537 return @r;
538}
539$code.=<<___;
540.align 16
541.Loop_ssse3:
542___
543 &Xupdate_ssse3_16_31(\&body_00_19);
544 &Xupdate_ssse3_16_31(\&body_00_19);
545 &Xupdate_ssse3_16_31(\&body_00_19);
546 &Xupdate_ssse3_16_31(\&body_00_19);
547 &Xupdate_ssse3_32_79(\&body_00_19);
548 &Xupdate_ssse3_32_79(\&body_20_39);
549 &Xupdate_ssse3_32_79(\&body_20_39);
550 &Xupdate_ssse3_32_79(\&body_20_39);
551 &Xupdate_ssse3_32_79(\&body_20_39);
552 &Xupdate_ssse3_32_79(\&body_20_39);
553 &Xupdate_ssse3_32_79(\&body_40_59);
554 &Xupdate_ssse3_32_79(\&body_40_59);
555 &Xupdate_ssse3_32_79(\&body_40_59);
556 &Xupdate_ssse3_32_79(\&body_40_59);
557 &Xupdate_ssse3_32_79(\&body_40_59);
558 &Xupdate_ssse3_32_79(\&body_20_39);
559 &Xuplast_ssse3_80(\&body_20_39); # can jump to "done"
560
561 $saved_j=$j; @saved_V=@V;
562 $saved_r=$r; @saved_rndkey=@rndkey;
563
564 &Xloop_ssse3(\&body_20_39);
565 &Xloop_ssse3(\&body_20_39);
566 &Xloop_ssse3(\&body_20_39);
567
568$code.=<<___;
569 movups $iv,48($out,$in0) # write output
570 lea 64($in0),$in0
571
572 add 0($ctx),$A # update context
573 add 4($ctx),@T[0]
574 add 8($ctx),$C
575 add 12($ctx),$D
576 mov $A,0($ctx)
577 add 16($ctx),$E
578 mov @T[0],4($ctx)
579 mov @T[0],$B # magic seed
580 mov $C,8($ctx)
581 mov $D,12($ctx)
582 mov $E,16($ctx)
583 jmp .Loop_ssse3
584
585.align 16
586.Ldone_ssse3:
587___
588 $jj=$j=$saved_j; @V=@saved_V;
589 $r=$saved_r; @rndkey=@saved_rndkey;
590
591 &Xtail_ssse3(\&body_20_39);
592 &Xtail_ssse3(\&body_20_39);
593 &Xtail_ssse3(\&body_20_39);
594
595$code.=<<___;
596 movups $iv,48($out,$in0) # write output
597 mov 88(%rsp),$ivp # restore $ivp
598
599 add 0($ctx),$A # update context
600 add 4($ctx),@T[0]
601 add 8($ctx),$C
602 mov $A,0($ctx)
603 add 12($ctx),$D
604 mov @T[0],4($ctx)
605 add 16($ctx),$E
606 mov $C,8($ctx)
607 mov $D,12($ctx)
608 mov $E,16($ctx)
609 movups $iv,($ivp) # write IV
610___
611$code.=<<___ if ($win64);
612 movaps 96+0(%rsp),%xmm6
613 movaps 96+16(%rsp),%xmm7
614 movaps 96+32(%rsp),%xmm8
615 movaps 96+48(%rsp),%xmm9
616 movaps 96+64(%rsp),%xmm10
617 movaps 96+80(%rsp),%xmm11
618 movaps 96+96(%rsp),%xmm12
619 movaps 96+112(%rsp),%xmm13
620 movaps 96+128(%rsp),%xmm14
621 movaps 96+144(%rsp),%xmm15
622___
623$code.=<<___;
624 lea `104+($win64?10*16:0)`(%rsp),%rsi
625 mov 0(%rsi),%r15
626 mov 8(%rsi),%r14
627 mov 16(%rsi),%r13
628 mov 24(%rsi),%r12
629 mov 32(%rsi),%rbp
630 mov 40(%rsi),%rbx
631 lea 48(%rsi),%rsp
632.Lepilogue_ssse3:
633 ret
634.size aesni_cbc_sha1_enc_ssse3,.-aesni_cbc_sha1_enc_ssse3
635___
636
637$j=$jj=$r=$sn=0;
638
639if ($avx) {
640my ($in0,$out,$len,$key,$ivp,$ctx,$inp)=("%rdi","%rsi","%rdx","%rcx","%r8","%r9","%r10");
641
642my $Xi=4;
643my @X=map("%xmm$_",(4..7,0..3));
644my @Tx=map("%xmm$_",(8..10));
645my @V=($A,$B,$C,$D,$E)=("%eax","%ebx","%ecx","%edx","%ebp"); # size optimization
646my @T=("%esi","%edi");
647
648my $_rol=sub { &shld(@_[0],@_) };
649my $_ror=sub { &shrd(@_[0],@_) };
650
651$code.=<<___;
652.type aesni_cbc_sha1_enc_avx,\@function,6
653.align 16
654aesni_cbc_sha1_enc_avx:
655 _CET_ENDBR
656 mov `($win64?56:8)`(%rsp),$inp # load 7th argument
657 #shr \$6,$len # debugging artefact
658 #jz .Lepilogue_avx # debugging artefact
659 push %rbx
660 push %rbp
661 push %r12
662 push %r13
663 push %r14
664 push %r15
665 lea `-104-($win64?10*16:0)`(%rsp),%rsp
666 #mov $in0,$inp # debugging artefact
667 #lea 64(%rsp),$ctx # debugging artefact
668___
669$code.=<<___ if ($win64);
670 movaps %xmm6,96+0(%rsp)
671 movaps %xmm7,96+16(%rsp)
672 movaps %xmm8,96+32(%rsp)
673 movaps %xmm9,96+48(%rsp)
674 movaps %xmm10,96+64(%rsp)
675 movaps %xmm11,96+80(%rsp)
676 movaps %xmm12,96+96(%rsp)
677 movaps %xmm13,96+112(%rsp)
678 movaps %xmm14,96+128(%rsp)
679 movaps %xmm15,96+144(%rsp)
680.Lprologue_avx:
681___
682$code.=<<___;
683 vzeroall
684 mov $in0,%r12 # reassign arguments
685 mov $out,%r13
686 mov $len,%r14
687 mov $key,%r15
688 vmovdqu ($ivp),$iv # load IV
689 mov $ivp,88(%rsp) # save $ivp
690___
691my ($in0,$out,$len,$key)=map("%r$_",(12..15)); # reassign arguments
692my $rounds="${ivp}d";
693$code.=<<___;
694 shl \$6,$len
695 sub $in0,$out
696 mov 240($key),$rounds
697 add \$112,$key # size optimization
698 add $inp,$len # end of input
699
700 lea K_XX_XX(%rip),$K_XX_XX
701 mov 0($ctx),$A # load context
702 mov 4($ctx),$B
703 mov 8($ctx),$C
704 mov 12($ctx),$D
705 mov $B,@T[0] # magic seed
706 mov 16($ctx),$E
707
708 vmovdqa 64($K_XX_XX),@X[2] # pbswap mask
709 vmovdqa 0($K_XX_XX),@Tx[1] # K_00_19
710 vmovdqu 0($inp),@X[-4&7] # load input to %xmm[0-3]
711 vmovdqu 16($inp),@X[-3&7]
712 vmovdqu 32($inp),@X[-2&7]
713 vmovdqu 48($inp),@X[-1&7]
714 vpshufb @X[2],@X[-4&7],@X[-4&7] # byte swap
715 add \$64,$inp
716 vpshufb @X[2],@X[-3&7],@X[-3&7]
717 vpshufb @X[2],@X[-2&7],@X[-2&7]
718 vpshufb @X[2],@X[-1&7],@X[-1&7]
719 vpaddd @Tx[1],@X[-4&7],@X[0] # add K_00_19
720 vpaddd @Tx[1],@X[-3&7],@X[1]
721 vpaddd @Tx[1],@X[-2&7],@X[2]
722 vmovdqa @X[0],0(%rsp) # X[]+K xfer to IALU
723 vmovdqa @X[1],16(%rsp)
724 vmovdqa @X[2],32(%rsp)
725 vmovups -112($key),$rndkey0 # $key[0]
726 vmovups 16-112($key),$rndkey[0] # forward reference
727 jmp .Loop_avx
728___
729
730my $aesenc=sub {
731 use integer;
732 my ($n,$k)=($r/10,$r%10);
733 if ($k==0) {
734 $code.=<<___;
735 vmovups `16*$n`($in0),$in # load input
736 vxorps $rndkey0,$in,$in
737___
738 $code.=<<___ if ($n);
739 vmovups $iv,`16*($n-1)`($out,$in0) # write output
740___
741 $code.=<<___;
742 vxorps $in,$iv,$iv
743 vaesenc $rndkey[0],$iv,$iv
744 vmovups `32+16*$k-112`($key),$rndkey[1]
745___
746 } elsif ($k==9) {
747 $sn++;
748 $code.=<<___;
749 cmp \$11,$rounds
750 jb .Lvaesenclast$sn
751 vaesenc $rndkey[0],$iv,$iv
752 vmovups `32+16*($k+0)-112`($key),$rndkey[1]
753 vaesenc $rndkey[1],$iv,$iv
754 vmovups `32+16*($k+1)-112`($key),$rndkey[0]
755 je .Lvaesenclast$sn
756 vaesenc $rndkey[0],$iv,$iv
757 vmovups `32+16*($k+2)-112`($key),$rndkey[1]
758 vaesenc $rndkey[1],$iv,$iv
759 vmovups `32+16*($k+3)-112`($key),$rndkey[0]
760.Lvaesenclast$sn:
761 vaesenclast $rndkey[0],$iv,$iv
762 vmovups 16-112($key),$rndkey[1] # forward reference
763___
764 } else {
765 $code.=<<___;
766 vaesenc $rndkey[0],$iv,$iv
767 vmovups `32+16*$k-112`($key),$rndkey[1]
768___
769 }
770 $r++; unshift(@rndkey,pop(@rndkey));
771};
772
773sub Xupdate_avx_16_31() # recall that $Xi starts with 4
774{ use integer;
775 my $body = shift;
776 my @insns = (&$body,&$body,&$body,&$body); # 40 instructions
777 my ($a,$b,$c,$d,$e);
778
779 eval(shift(@insns));
780 eval(shift(@insns));
781 &vpalignr(@X[0],@X[-3&7],@X[-4&7],8); # compose "X[-14]" in "X[0]"
782 eval(shift(@insns));
783 eval(shift(@insns));
784
785 &vpaddd (@Tx[1],@Tx[1],@X[-1&7]);
786 eval(shift(@insns));
787 eval(shift(@insns));
788 &vpsrldq(@Tx[0],@X[-1&7],4); # "X[-3]", 3 dwords
789 eval(shift(@insns));
790 eval(shift(@insns));
791 &vpxor (@X[0],@X[0],@X[-4&7]); # "X[0]"^="X[-16]"
792 eval(shift(@insns));
793 eval(shift(@insns));
794
795 &vpxor (@Tx[0],@Tx[0],@X[-2&7]); # "X[-3]"^"X[-8]"
796 eval(shift(@insns));
797 eval(shift(@insns));
798 eval(shift(@insns));
799 eval(shift(@insns));
800
801 &vpxor (@X[0],@X[0],@Tx[0]); # "X[0]"^="X[-3]"^"X[-8]"
802 eval(shift(@insns));
803 eval(shift(@insns));
804 &vmovdqa (eval(16*(($Xi-1)&3))."(%rsp)",@Tx[1]); # X[]+K xfer to IALU
805 eval(shift(@insns));
806 eval(shift(@insns));
807
808 &vpsrld (@Tx[0],@X[0],31);
809 eval(shift(@insns));
810 eval(shift(@insns));
811 eval(shift(@insns));
812 eval(shift(@insns));
813
814 &vpslldq(@Tx[2],@X[0],12); # "X[0]"<<96, extract one dword
815 &vpaddd (@X[0],@X[0],@X[0]);
816 eval(shift(@insns));
817 eval(shift(@insns));
818 eval(shift(@insns));
819 eval(shift(@insns));
820
821 &vpsrld (@Tx[1],@Tx[2],30);
822 &vpor (@X[0],@X[0],@Tx[0]); # "X[0]"<<<=1
823 eval(shift(@insns));
824 eval(shift(@insns));
825 eval(shift(@insns));
826 eval(shift(@insns));
827
828 &vpslld (@Tx[2],@Tx[2],2);
829 &vpxor (@X[0],@X[0],@Tx[1]);
830 eval(shift(@insns));
831 eval(shift(@insns));
832 eval(shift(@insns));
833 eval(shift(@insns));
834
835 &vpxor (@X[0],@X[0],@Tx[2]); # "X[0]"^=("X[0]">>96)<<<2
836 eval(shift(@insns));
837 eval(shift(@insns));
838 &vmovdqa (@Tx[2],eval(16*(($Xi)/5))."($K_XX_XX)"); # K_XX_XX
839 eval(shift(@insns));
840 eval(shift(@insns));
841
842
843 foreach (@insns) { eval; } # remaining instructions [if any]
844
845 $Xi++; push(@X,shift(@X)); # "rotate" X[]
846 push(@Tx,shift(@Tx));
847}
848
849sub Xupdate_avx_32_79()
850{ use integer;
851 my $body = shift;
852 my @insns = (&$body,&$body,&$body,&$body); # 32 to 48 instructions
853 my ($a,$b,$c,$d,$e);
854
855 &vpalignr(@Tx[0],@X[-1&7],@X[-2&7],8); # compose "X[-6]"
856 &vpxor (@X[0],@X[0],@X[-4&7]); # "X[0]"="X[-32]"^"X[-16]"
857 eval(shift(@insns)); # body_20_39
858 eval(shift(@insns));
859 eval(shift(@insns));
860 eval(shift(@insns)); # rol
861
862 &vpxor (@X[0],@X[0],@X[-7&7]); # "X[0]"^="X[-28]"
863 eval(shift(@insns));
864 eval(shift(@insns)) if (@insns[0] !~ /&ro[rl]/);
865 if ($Xi%5) {
866 &vmovdqa (@Tx[2],@Tx[1]);# "perpetuate" K_XX_XX...
867 } else { # ... or load next one
868 &vmovdqa (@Tx[2],eval(16*($Xi/5))."($K_XX_XX)");
869 }
870 &vpaddd (@Tx[1],@Tx[1],@X[-1&7]);
871 eval(shift(@insns)); # ror
872 eval(shift(@insns));
873
874 &vpxor (@X[0],@X[0],@Tx[0]); # "X[0]"^="X[-6]"
875 eval(shift(@insns)); # body_20_39
876 eval(shift(@insns));
877 eval(shift(@insns));
878 eval(shift(@insns)); # rol
879
880 &vpsrld (@Tx[0],@X[0],30);
881 &vmovdqa (eval(16*(($Xi-1)&3))."(%rsp)",@Tx[1]); # X[]+K xfer to IALU
882 eval(shift(@insns));
883 eval(shift(@insns));
884 eval(shift(@insns)); # ror
885 eval(shift(@insns));
886
887 &vpslld (@X[0],@X[0],2);
888 eval(shift(@insns)); # body_20_39
889 eval(shift(@insns));
890 eval(shift(@insns));
891 eval(shift(@insns)); # rol
892 eval(shift(@insns));
893 eval(shift(@insns));
894 eval(shift(@insns)); # ror
895 eval(shift(@insns));
896
897 &vpor (@X[0],@X[0],@Tx[0]); # "X[0]"<<<=2
898 eval(shift(@insns)); # body_20_39
899 eval(shift(@insns));
900 &vmovdqa (@Tx[1],@X[0]) if ($Xi<19);
901 eval(shift(@insns));
902 eval(shift(@insns)); # rol
903 eval(shift(@insns));
904 eval(shift(@insns));
905 eval(shift(@insns)); # rol
906 eval(shift(@insns));
907
908 foreach (@insns) { eval; } # remaining instructions
909
910 $Xi++; push(@X,shift(@X)); # "rotate" X[]
911 push(@Tx,shift(@Tx));
912}
913
914sub Xuplast_avx_80()
915{ use integer;
916 my $body = shift;
917 my @insns = (&$body,&$body,&$body,&$body); # 32 instructions
918 my ($a,$b,$c,$d,$e);
919
920 eval(shift(@insns));
921 &vpaddd (@Tx[1],@Tx[1],@X[-1&7]);
922 eval(shift(@insns));
923 eval(shift(@insns));
924 eval(shift(@insns));
925 eval(shift(@insns));
926
927 &movdqa (eval(16*(($Xi-1)&3))."(%rsp)",@Tx[1]); # X[]+K xfer IALU
928
929 foreach (@insns) { eval; } # remaining instructions
930
931 &cmp ($inp,$len);
932 &je (".Ldone_avx");
933
934 unshift(@Tx,pop(@Tx));
935
936 &vmovdqa(@X[2],"64($K_XX_XX)"); # pbswap mask
937 &vmovdqa(@Tx[1],"0($K_XX_XX)"); # K_00_19
938 &vmovdqu(@X[-4&7],"0($inp)"); # load input
939 &vmovdqu(@X[-3&7],"16($inp)");
940 &vmovdqu(@X[-2&7],"32($inp)");
941 &vmovdqu(@X[-1&7],"48($inp)");
942 &vpshufb(@X[-4&7],@X[-4&7],@X[2]); # byte swap
943 &add ($inp,64);
944
945 $Xi=0;
946}
947
948sub Xloop_avx()
949{ use integer;
950 my $body = shift;
951 my @insns = (&$body,&$body,&$body,&$body); # 32 instructions
952 my ($a,$b,$c,$d,$e);
953
954 eval(shift(@insns));
955 eval(shift(@insns));
956 &vpshufb(@X[($Xi-3)&7],@X[($Xi-3)&7],@X[2]);
957 eval(shift(@insns));
958 eval(shift(@insns));
959 &vpaddd (@X[$Xi&7],@X[($Xi-4)&7],@Tx[1]);
960 eval(shift(@insns));
961 eval(shift(@insns));
962 eval(shift(@insns));
963 eval(shift(@insns));
964 &vmovdqa(eval(16*$Xi)."(%rsp)",@X[$Xi&7]); # X[]+K xfer to IALU
965 eval(shift(@insns));
966 eval(shift(@insns));
967
968 foreach (@insns) { eval; }
969 $Xi++;
970}
971
972sub Xtail_avx()
973{ use integer;
974 my $body = shift;
975 my @insns = (&$body,&$body,&$body,&$body); # 32 instructions
976 my ($a,$b,$c,$d,$e);
977
978 foreach (@insns) { eval; }
979}
980
981$code.=<<___;
982.align 16
983.Loop_avx:
984___
985 &Xupdate_avx_16_31(\&body_00_19);
986 &Xupdate_avx_16_31(\&body_00_19);
987 &Xupdate_avx_16_31(\&body_00_19);
988 &Xupdate_avx_16_31(\&body_00_19);
989 &Xupdate_avx_32_79(\&body_00_19);
990 &Xupdate_avx_32_79(\&body_20_39);
991 &Xupdate_avx_32_79(\&body_20_39);
992 &Xupdate_avx_32_79(\&body_20_39);
993 &Xupdate_avx_32_79(\&body_20_39);
994 &Xupdate_avx_32_79(\&body_20_39);
995 &Xupdate_avx_32_79(\&body_40_59);
996 &Xupdate_avx_32_79(\&body_40_59);
997 &Xupdate_avx_32_79(\&body_40_59);
998 &Xupdate_avx_32_79(\&body_40_59);
999 &Xupdate_avx_32_79(\&body_40_59);
1000 &Xupdate_avx_32_79(\&body_20_39);
1001 &Xuplast_avx_80(\&body_20_39); # can jump to "done"
1002
1003 $saved_j=$j; @saved_V=@V;
1004 $saved_r=$r; @saved_rndkey=@rndkey;
1005
1006 &Xloop_avx(\&body_20_39);
1007 &Xloop_avx(\&body_20_39);
1008 &Xloop_avx(\&body_20_39);
1009
1010$code.=<<___;
1011 vmovups $iv,48($out,$in0) # write output
1012 lea 64($in0),$in0
1013
1014 add 0($ctx),$A # update context
1015 add 4($ctx),@T[0]
1016 add 8($ctx),$C
1017 add 12($ctx),$D
1018 mov $A,0($ctx)
1019 add 16($ctx),$E
1020 mov @T[0],4($ctx)
1021 mov @T[0],$B # magic seed
1022 mov $C,8($ctx)
1023 mov $D,12($ctx)
1024 mov $E,16($ctx)
1025 jmp .Loop_avx
1026
1027.align 16
1028.Ldone_avx:
1029___
1030 $jj=$j=$saved_j; @V=@saved_V;
1031 $r=$saved_r; @rndkey=@saved_rndkey;
1032
1033 &Xtail_avx(\&body_20_39);
1034 &Xtail_avx(\&body_20_39);
1035 &Xtail_avx(\&body_20_39);
1036
1037$code.=<<___;
1038 vmovups $iv,48($out,$in0) # write output
1039 mov 88(%rsp),$ivp # restore $ivp
1040
1041 add 0($ctx),$A # update context
1042 add 4($ctx),@T[0]
1043 add 8($ctx),$C
1044 mov $A,0($ctx)
1045 add 12($ctx),$D
1046 mov @T[0],4($ctx)
1047 add 16($ctx),$E
1048 mov $C,8($ctx)
1049 mov $D,12($ctx)
1050 mov $E,16($ctx)
1051 vmovups $iv,($ivp) # write IV
1052 vzeroall
1053___
1054$code.=<<___ if ($win64);
1055 movaps 96+0(%rsp),%xmm6
1056 movaps 96+16(%rsp),%xmm7
1057 movaps 96+32(%rsp),%xmm8
1058 movaps 96+48(%rsp),%xmm9
1059 movaps 96+64(%rsp),%xmm10
1060 movaps 96+80(%rsp),%xmm11
1061 movaps 96+96(%rsp),%xmm12
1062 movaps 96+112(%rsp),%xmm13
1063 movaps 96+128(%rsp),%xmm14
1064 movaps 96+144(%rsp),%xmm15
1065___
1066$code.=<<___;
1067 lea `104+($win64?10*16:0)`(%rsp),%rsi
1068 mov 0(%rsi),%r15
1069 mov 8(%rsi),%r14
1070 mov 16(%rsi),%r13
1071 mov 24(%rsi),%r12
1072 mov 32(%rsi),%rbp
1073 mov 40(%rsi),%rbx
1074 lea 48(%rsi),%rsp
1075.Lepilogue_avx:
1076 ret
1077.size aesni_cbc_sha1_enc_avx,.-aesni_cbc_sha1_enc_avx
1078___
1079}
1080$code.=<<___;
1081.section .rodata
1082.align 64
1083K_XX_XX:
1084.long 0x5a827999,0x5a827999,0x5a827999,0x5a827999 # K_00_19
1085.long 0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1 # K_20_39
1086.long 0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc # K_40_59
1087.long 0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6 # K_60_79
1088.long 0x00010203,0x04050607,0x08090a0b,0x0c0d0e0f # pbswap mask
1089.align 64
1090.text
1091___
1092
1093# EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
1094# CONTEXT *context,DISPATCHER_CONTEXT *disp)
1095if ($win64) {
1096$rec="%rcx";
1097$frame="%rdx";
1098$context="%r8";
1099$disp="%r9";
1100
1101$code.=<<___;
1102.extern __imp_RtlVirtualUnwind
1103.type ssse3_handler,\@abi-omnipotent
1104.align 16
1105ssse3_handler:
1106 _CET_ENDBR
1107 push %rsi
1108 push %rdi
1109 push %rbx
1110 push %rbp
1111 push %r12
1112 push %r13
1113 push %r14
1114 push %r15
1115 pushfq
1116 sub \$64,%rsp
1117
1118 mov 120($context),%rax # pull context->Rax
1119 mov 248($context),%rbx # pull context->Rip
1120
1121 mov 8($disp),%rsi # disp->ImageBase
1122 mov 56($disp),%r11 # disp->HandlerData
1123
1124 mov 0(%r11),%r10d # HandlerData[0]
1125 lea (%rsi,%r10),%r10 # prologue label
1126 cmp %r10,%rbx # context->Rip<prologue label
1127 jb .Lcommon_seh_tail
1128
1129 mov 152($context),%rax # pull context->Rsp
1130
1131 mov 4(%r11),%r10d # HandlerData[1]
1132 lea (%rsi,%r10),%r10 # epilogue label
1133 cmp %r10,%rbx # context->Rip>=epilogue label
1134 jae .Lcommon_seh_tail
1135
1136 lea 96(%rax),%rsi
1137 lea 512($context),%rdi # &context.Xmm6
1138 mov \$20,%ecx
1139 .long 0xa548f3fc # cld; rep movsq
1140 lea `104+10*16`(%rax),%rax # adjust stack pointer
1141
1142 mov 0(%rax),%r15
1143 mov 8(%rax),%r14
1144 mov 16(%rax),%r13
1145 mov 24(%rax),%r12
1146 mov 32(%rax),%rbp
1147 mov 40(%rax),%rbx
1148 lea 48(%rax),%rax
1149 mov %rbx,144($context) # restore context->Rbx
1150 mov %rbp,160($context) # restore context->Rbp
1151 mov %r12,216($context) # restore context->R12
1152 mov %r13,224($context) # restore context->R13
1153 mov %r14,232($context) # restore context->R14
1154 mov %r15,240($context) # restore context->R15
1155
1156.Lcommon_seh_tail:
1157 mov 8(%rax),%rdi
1158 mov 16(%rax),%rsi
1159 mov %rax,152($context) # restore context->Rsp
1160 mov %rsi,168($context) # restore context->Rsi
1161 mov %rdi,176($context) # restore context->Rdi
1162
1163 mov 40($disp),%rdi # disp->ContextRecord
1164 mov $context,%rsi # context
1165 mov \$154,%ecx # sizeof(CONTEXT)
1166 .long 0xa548f3fc # cld; rep movsq
1167
1168 mov $disp,%rsi
1169 xor %rcx,%rcx # arg1, UNW_FLAG_NHANDLER
1170 mov 8(%rsi),%rdx # arg2, disp->ImageBase
1171 mov 0(%rsi),%r8 # arg3, disp->ControlPc
1172 mov 16(%rsi),%r9 # arg4, disp->FunctionEntry
1173 mov 40(%rsi),%r10 # disp->ContextRecord
1174 lea 56(%rsi),%r11 # &disp->HandlerData
1175 lea 24(%rsi),%r12 # &disp->EstablisherFrame
1176 mov %r10,32(%rsp) # arg5
1177 mov %r11,40(%rsp) # arg6
1178 mov %r12,48(%rsp) # arg7
1179 mov %rcx,56(%rsp) # arg8, (NULL)
1180 call *__imp_RtlVirtualUnwind(%rip)
1181
1182 mov \$1,%eax # ExceptionContinueSearch
1183 add \$64,%rsp
1184 popfq
1185 pop %r15
1186 pop %r14
1187 pop %r13
1188 pop %r12
1189 pop %rbp
1190 pop %rbx
1191 pop %rdi
1192 pop %rsi
1193 ret
1194.size ssse3_handler,.-ssse3_handler
1195
1196.section .pdata
1197.align 4
1198 .rva .LSEH_begin_aesni_cbc_sha1_enc_ssse3
1199 .rva .LSEH_end_aesni_cbc_sha1_enc_ssse3
1200 .rva .LSEH_info_aesni_cbc_sha1_enc_ssse3
1201___
1202$code.=<<___ if ($avx);
1203 .rva .LSEH_begin_aesni_cbc_sha1_enc_avx
1204 .rva .LSEH_end_aesni_cbc_sha1_enc_avx
1205 .rva .LSEH_info_aesni_cbc_sha1_enc_avx
1206___
1207$code.=<<___;
1208.section .xdata
1209.align 8
1210.LSEH_info_aesni_cbc_sha1_enc_ssse3:
1211 .byte 9,0,0,0
1212 .rva ssse3_handler
1213 .rva .Lprologue_ssse3,.Lepilogue_ssse3 # HandlerData[]
1214___
1215$code.=<<___ if ($avx);
1216.LSEH_info_aesni_cbc_sha1_enc_avx:
1217 .byte 9,0,0,0
1218 .rva ssse3_handler
1219 .rva .Lprologue_avx,.Lepilogue_avx # HandlerData[]
1220___
1221}
1222
1223####################################################################
1224sub rex {
1225 local *opcode=shift;
1226 my ($dst,$src)=@_;
1227 my $rex=0;
1228
1229 $rex|=0x04 if($dst>=8);
1230 $rex|=0x01 if($src>=8);
1231 push @opcode,$rex|0x40 if($rex);
1232}
1233
1234$code =~ s/\`([^\`]*)\`/eval($1)/gem;
1235
1236print $code;
1237close STDOUT;