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 # ====================================================================
12 # Montgomery multiplication routine for x86_64. While it gives modest
13 # 9% improvement of rsa4096 sign on Opteron, rsa512 sign runs more
14 # than twice, >2x, as fast. Most common rsa1024 sign is improved by
15 # respectful 50%. It remains to be seen if loop unrolling and
16 # dedicated squaring routine can provide further improvement...
20 # Add dedicated squaring procedure. Performance improvement varies
21 # from platform to platform, but in average it's ~5%/15%/25%/33%
22 # for 512-/1024-/2048-/4096-bit RSA *sign* benchmarks respectively.
26 # Unroll and modulo-schedule inner loops in such manner that they
27 # are "fallen through" for input lengths of 8, which is critical for
28 # 1024-bit RSA *sign*. Average performance improvement in comparison
29 # to *initial* version of this module from 2005 is ~0%/30%/40%/45%
30 # for 512-/1024-/2048-/4096-bit RSA *sign* benchmarks respectively.
34 # Optimize reduction in squaring procedure and improve 1024+-bit RSA
35 # sign performance by 10-16% on Intel Sandy Bridge and later
36 # (virtually same on non-Intel processors).
40 # Add MULX/ADOX/ADCX code path.
44 if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
46 $win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
48 $0 =~ m/(.*[\/\\])[^\
/\\]+$/; $dir=$1;
49 ( $xlate="${dir}x86_64-xlate.pl" and -f
$xlate ) or
50 ( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f
$xlate) or
51 die "can't locate x86_64-xlate.pl";
53 open OUT
,"| \"$^X\" $xlate $flavour $output";
56 if (`$ENV{CC} -Wa,-v -c -o /dev/null -x assembler /dev/null 2>&1`
57 =~ /GNU assembler version ([2-9]\.[0-9]+)/) {
61 if (!$addx && $win64 && ($flavour =~ /nasm/ || $ENV{ASM
} =~ /nasm/) &&
62 `nasm -v 2>&1` =~ /NASM version ([2-9]\.[0-9]+)/) {
66 if (!$addx && $win64 && ($flavour =~ /masm/ || $ENV{ASM
} =~ /ml64/) &&
67 `ml64 2>&1` =~ /Version ([0-9]+)\./) {
71 if (!$addx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|.*based on LLVM) ([3-9])\.([0-9]+)/) {
72 my $ver = $2 + $3/100.0; # 3.1->3.01, 3.10->3.10
77 $rp="%rdi"; # BN_ULONG *rp,
78 $ap="%rsi"; # const BN_ULONG *ap,
79 $bp="%rdx"; # const BN_ULONG *bp,
80 $np="%rcx"; # const BN_ULONG *np,
81 $n0="%r8"; # const BN_ULONG *n0,
82 $num="%r9"; # int num);
94 .extern OPENSSL_ia32cap_P
97 .type bn_mul_mont
,\
@function,6
105 $code.=<<___
if ($addx);
106 mov OPENSSL_ia32cap_P
+8(%rip),%r11d
128 lea
(%rsp,%r10,8),%rsp # tp=alloca(8*(num+2))
129 and \
$-1024,%rsp # minimize TLB usage
131 mov
%r11,8(%rsp,$num,8) # tp[num+1]=%rsp
133 mov
$bp,%r12 # reassign $bp
137 mov
($n0),$n0 # pull n0[0] value
138 mov
($bp),$m0 # m0=bp[0]
145 mulq
$m0 # ap[0]*bp[0]
149 imulq
$lo0,$m1 # "tp[0]"*n0
153 add
%rax,$lo0 # discarded
166 add
$hi0,$hi1 # np[j]*m1+ap[j]*bp[0]
169 mov
$hi1,-16(%rsp,$j,8) # tp[j-1]
173 mulq
$m0 # ap[j]*bp[0]
185 mov
($ap),%rax # ap[0]
187 add
$hi0,$hi1 # np[j]*m1+ap[j]*bp[0]
189 mov
$hi1,-16(%rsp,$j,8) # tp[j-1]
196 mov
$hi1,-8(%rsp,$num,8)
197 mov
%rdx,(%rsp,$num,8) # store upmost overflow bit
203 mov
($bp,$i,8),$m0 # m0=bp[i]
207 mulq
$m0 # ap[0]*bp[i]
208 add
%rax,$lo0 # ap[0]*bp[i]+tp[0]
212 imulq
$lo0,$m1 # tp[0]*n0
216 add
%rax,$lo0 # discarded
219 mov
8(%rsp),$lo0 # tp[1]
230 add
$lo0,$hi1 # np[j]*m1+ap[j]*bp[i]+tp[j]
233 mov
$hi1,-16(%rsp,$j,8) # tp[j-1]
237 mulq
$m0 # ap[j]*bp[i]
241 add
$hi0,$lo0 # ap[j]*bp[i]+tp[j]
251 mov
($ap),%rax # ap[0]
253 add
$lo0,$hi1 # np[j]*m1+ap[j]*bp[i]+tp[j]
256 mov
$hi1,-16(%rsp,$j,8) # tp[j-1]
262 add
$lo0,$hi1 # pull upmost overflow bit
264 mov
$hi1,-8(%rsp,$num,8)
265 mov
%rdx,(%rsp,$num,8) # store upmost overflow bit
271 xor $i,$i # i=0 and clear CF!
272 mov
(%rsp),%rax # tp[0]
273 lea
(%rsp),$ap # borrow ap for tp
277 .Lsub
: sbb
($np,$i,8),%rax
278 mov
%rax,($rp,$i,8) # rp[i]=tp[i]-np[i]
279 mov
8($ap,$i,8),%rax # tp[i+1]
281 dec
$j # doesnn't affect CF!
284 sbb \
$0,%rax # handle upmost overflow bit
291 or $np,$ap # ap=borrow?tp:rp
293 .Lcopy
: # copy or in-place refresh
295 mov
$i,(%rsp,$i,8) # zap temporary vector
296 mov
%rax,($rp,$i,8) # rp[i]=tp[i]
301 mov
8(%rsp,$num,8),%rsi # restore %rsp
312 .size bn_mul_mont
,.-bn_mul_mont
315 my @A=("%r10","%r11");
316 my @N=("%r13","%rdi");
318 .type bn_mul4x_mont
,\
@function,6
323 $code.=<<___
if ($addx);
340 lea
(%rsp,%r10,8),%rsp # tp=alloca(8*(num+4))
341 and \
$-1024,%rsp # minimize TLB usage
343 mov
%r11,8(%rsp,$num,8) # tp[num+1]=%rsp
345 mov
$rp,16(%rsp,$num,8) # tp[num+2]=$rp
346 mov
%rdx,%r12 # reassign $bp
350 mov
($n0),$n0 # pull n0[0] value
351 mov
($bp),$m0 # m0=bp[0]
358 mulq
$m0 # ap[0]*bp[0]
362 imulq
$A[0],$m1 # "tp[0]"*n0
366 add
%rax,$A[0] # discarded
389 mulq
$m0 # ap[j]*bp[0]
391 mov
-16($np,$j,8),%rax
397 mov
-8($ap,$j,8),%rax
399 add
$A[0],$N[0] # np[j]*m1+ap[j]*bp[0]
401 mov
$N[0],-24(%rsp,$j,8) # tp[j-1]
404 mulq
$m0 # ap[j]*bp[0]
406 mov
-8($np,$j,8),%rax
414 add
$A[1],$N[1] # np[j]*m1+ap[j]*bp[0]
416 mov
$N[1],-16(%rsp,$j,8) # tp[j-1]
419 mulq
$m0 # ap[j]*bp[0]
429 add
$A[0],$N[0] # np[j]*m1+ap[j]*bp[0]
431 mov
$N[0],-8(%rsp,$j,8) # tp[j-1]
434 mulq
$m0 # ap[j]*bp[0]
443 mov
-16($ap,$j,8),%rax
445 add
$A[1],$N[1] # np[j]*m1+ap[j]*bp[0]
447 mov
$N[1],-32(%rsp,$j,8) # tp[j-1]
452 mulq
$m0 # ap[j]*bp[0]
454 mov
-16($np,$j,8),%rax
460 mov
-8($ap,$j,8),%rax
462 add
$A[0],$N[0] # np[j]*m1+ap[j]*bp[0]
464 mov
$N[0],-24(%rsp,$j,8) # tp[j-1]
467 mulq
$m0 # ap[j]*bp[0]
469 mov
-8($np,$j,8),%rax
475 mov
($ap),%rax # ap[0]
477 add
$A[1],$N[1] # np[j]*m1+ap[j]*bp[0]
479 mov
$N[1],-16(%rsp,$j,8) # tp[j-1]
485 mov
$N[0],-8(%rsp,$j,8)
486 mov
$N[1],(%rsp,$j,8) # store upmost overflow bit
491 mov
($bp,$i,8),$m0 # m0=bp[i]
495 mulq
$m0 # ap[0]*bp[i]
496 add
%rax,$A[0] # ap[0]*bp[i]+tp[0]
500 imulq
$A[0],$m1 # tp[0]*n0
504 add
%rax,$A[0] # "$N[0]", discarded
509 mulq
$m0 # ap[j]*bp[i]
513 add
8(%rsp),$A[1] # +tp[1]
521 add
$A[1],$N[1] # np[j]*m1+ap[j]*bp[i]+tp[j]
524 mov
$N[1],(%rsp) # tp[j-1]
529 mulq
$m0 # ap[j]*bp[i]
531 mov
-16($np,$j,8),%rax
533 add
-16(%rsp,$j,8),$A[0] # ap[j]*bp[i]+tp[j]
539 mov
-8($ap,$j,8),%rax
543 mov
$N[0],-24(%rsp,$j,8) # tp[j-1]
546 mulq
$m0 # ap[j]*bp[i]
548 mov
-8($np,$j,8),%rax
550 add
-8(%rsp,$j,8),$A[1]
560 mov
$N[1],-16(%rsp,$j,8) # tp[j-1]
563 mulq
$m0 # ap[j]*bp[i]
567 add
(%rsp,$j,8),$A[0] # ap[j]*bp[i]+tp[j]
577 mov
$N[0],-8(%rsp,$j,8) # tp[j-1]
580 mulq
$m0 # ap[j]*bp[i]
584 add
8(%rsp,$j,8),$A[1]
591 mov
-16($ap,$j,8),%rax
595 mov
$N[1],-32(%rsp,$j,8) # tp[j-1]
600 mulq
$m0 # ap[j]*bp[i]
602 mov
-16($np,$j,8),%rax
604 add
-16(%rsp,$j,8),$A[0] # ap[j]*bp[i]+tp[j]
610 mov
-8($ap,$j,8),%rax
614 mov
$N[0],-24(%rsp,$j,8) # tp[j-1]
617 mulq
$m0 # ap[j]*bp[i]
619 mov
-8($np,$j,8),%rax
621 add
-8(%rsp,$j,8),$A[1]
628 mov
($ap),%rax # ap[0]
632 mov
$N[1],-16(%rsp,$j,8) # tp[j-1]
638 add
(%rsp,$num,8),$N[0] # pull upmost overflow bit
640 mov
$N[0],-8(%rsp,$j,8)
641 mov
$N[1],(%rsp,$j,8) # store upmost overflow bit
647 my @ri=("%rax","%rdx",$m0,$m1);
649 mov
16(%rsp,$num,8),$rp # restore $rp
650 mov
0(%rsp),@ri[0] # tp[0]
652 mov
8(%rsp),@ri[1] # tp[1]
653 shr \
$2,$num # num/=4
654 lea
(%rsp),$ap # borrow ap for tp
655 xor $i,$i # i=0 and clear CF!
658 mov
16($ap),@ri[2] # tp[2]
659 mov
24($ap),@ri[3] # tp[3]
661 lea
-1($num),$j # j=num/4-1
665 mov
@ri[0],0($rp,$i,8) # rp[i]=tp[i]-np[i]
666 mov
@ri[1],8($rp,$i,8) # rp[i]=tp[i]-np[i]
667 sbb
16($np,$i,8),@ri[2]
668 mov
32($ap,$i,8),@ri[0] # tp[i+1]
669 mov
40($ap,$i,8),@ri[1]
670 sbb
24($np,$i,8),@ri[3]
671 mov
@ri[2],16($rp,$i,8) # rp[i]=tp[i]-np[i]
672 mov
@ri[3],24($rp,$i,8) # rp[i]=tp[i]-np[i]
673 sbb
32($np,$i,8),@ri[0]
674 mov
48($ap,$i,8),@ri[2]
675 mov
56($ap,$i,8),@ri[3]
676 sbb
40($np,$i,8),@ri[1]
678 dec
$j # doesnn't affect CF!
681 mov
@ri[0],0($rp,$i,8) # rp[i]=tp[i]-np[i]
682 mov
32($ap,$i,8),@ri[0] # load overflow bit
683 sbb
16($np,$i,8),@ri[2]
684 mov
@ri[1],8($rp,$i,8) # rp[i]=tp[i]-np[i]
685 sbb
24($np,$i,8),@ri[3]
686 mov
@ri[2],16($rp,$i,8) # rp[i]=tp[i]-np[i]
688 sbb \
$0,@ri[0] # handle upmost overflow bit
689 mov
@ri[3],24($rp,$i,8) # rp[i]=tp[i]-np[i]
696 or $np,$ap # ap=borrow?tp:rp
703 .Lcopy4x
: # copy or in-place refresh
704 movdqu
16($ap,$i),%xmm2
705 movdqu
32($ap,$i),%xmm1
706 movdqa
%xmm0,16(%rsp,$i)
707 movdqu
%xmm2,16($rp,$i)
708 movdqa
%xmm0,32(%rsp,$i)
709 movdqu
%xmm1,32($rp,$i)
715 movdqu
16($ap,$i),%xmm2
716 movdqa
%xmm0,16(%rsp,$i)
717 movdqu
%xmm2,16($rp,$i)
721 mov
8(%rsp,$num,8),%rsi # restore %rsp
732 .size bn_mul4x_mont
,.-bn_mul4x_mont
736 ######################################################################
737 # void bn_sqr8x_mont(
738 my $rptr="%rdi"; # const BN_ULONG *rptr,
739 my $aptr="%rsi"; # const BN_ULONG *aptr,
740 my $bptr="%rdx"; # not used
741 my $nptr="%rcx"; # const BN_ULONG *nptr,
742 my $n0 ="%r8"; # const BN_ULONG *n0);
743 my $num ="%r9"; # int num, has to be divisible by 8
745 my ($i,$j,$tptr)=("%rbp","%rcx",$rptr);
746 my @A0=("%r10","%r11");
747 my @A1=("%r12","%r13");
748 my ($a0,$a1,$ai)=("%r14","%r15","%rbx");
750 $code.=<<___
if ($addx);
751 .extern bn_sqrx8x_internal
# see x86_64-mont5 module
754 .extern bn_sqr8x_internal
# see x86_64-mont5 module
756 .type bn_sqr8x_mont
,\
@function,6
769 shl \
$3,${num
}d
# convert $num to bytes
770 shl \
$3+2,%r10 # 4*$num
773 ##############################################################
774 # ensure that stack frame doesn't alias with $aptr modulo
775 # 4096. this is done to allow memory disambiguation logic
778 lea
-64(%rsp,$num,4),%r11
784 sub %r11,%rsp # align with $aptr
785 lea
-64(%rsp,$num,4),%rsp # alloca(frame+4*$num)
790 lea
4096-64(,$num,4),%r10 # 4096-frame-4*$num
791 lea
-64(%rsp,$num,4),%rsp # alloca(frame+4*$num)
801 lea
64(%rsp,$num,2),%r11 # copy of modulus
803 mov
%rax, 40(%rsp) # save original %rsp
807 movq
%r11, %xmm2 # save pointer to modulus copy
809 mov OPENSSL_ia32cap_P
+8(%rip),%eax
814 movq
8*0($nptr),%xmm0
815 movq
8*1($nptr),%xmm1
816 movq
8*2($nptr),%xmm3
817 movq
8*3($nptr),%xmm4
819 movdqa
%xmm0,16*0(%r11)
820 movdqa
%xmm1,16*1(%r11)
821 movdqa
%xmm3,16*2(%r11)
822 movdqa
%xmm4,16*3(%r11)
828 movq
$rptr,%xmm1 # save $rptr
829 movq
%r10, %xmm3 # -$num
831 $code.=<<___
if ($addx);
836 call bn_sqrx8x_internal
# see x86_64-mont5 module
840 lea
64(%rsp,$num,2),%rdx
842 mov
40(%rsp),%rsi # restore %rsp
849 call bn_sqr8x_internal
# see x86_64-mont5 module
853 lea
64(%rsp,$num,2),%rdx
855 mov
40(%rsp),%rsi # restore %rsp
860 movdqa
%xmm0,16*0(%rax) # wipe t
861 movdqa
%xmm0,16*1(%rax)
862 movdqa
%xmm0,16*2(%rax)
863 movdqa
%xmm0,16*3(%rax)
865 movdqa
%xmm0,16*0(%rdx) # wipe n
866 movdqa
%xmm0,16*1(%rdx)
867 movdqa
%xmm0,16*2(%rdx)
868 movdqa
%xmm0,16*3(%rdx)
883 .size bn_sqr8x_mont
,.-bn_sqr8x_mont
888 my $bp="%rdx"; # original value
891 .type bn_mulx4x_mont
,\
@function,6
903 shl \
$3,${num
}d
# convert $num to bytes
906 sub $num,%r10 # -$num
908 lea
-72(%rsp,%r10),%rsp # alloca(frame+$num+8)
911 ##############################################################
914 # +8 off-loaded &b[i]
923 mov
$num,0(%rsp) # save $num
925 mov
%r10,16(%rsp) # end of b[num]
927 mov
$n0, 24(%rsp) # save *n0
928 mov
$rp, 32(%rsp) # save $rp
929 mov
%rax,40(%rsp) # save original %rsp
930 mov
$num,48(%rsp) # inner counter
936 my ($aptr, $bptr, $nptr, $tptr, $mi, $bi, $zero, $num)=
937 ("%rsi","%rdi","%rcx","%rbx","%r8","%r9","%rbp","%rax");
941 mov
($bp),%rdx # b[0], $bp==%rdx actually
942 lea
64+32(%rsp),$tptr
945 mulx
0*8($aptr),$mi,%rax # a[0]*b[0]
946 mulx
1*8($aptr),%r11,%r14 # a[1]*b[0]
948 mov
$bptr,8(%rsp) # off-load &b[i]
949 mulx
2*8($aptr),%r12,%r13 # ...
953 mov
$mi,$bptr # borrow $bptr
954 imulq
24(%rsp),$mi # "t[0]"*n0
955 xor $zero,$zero # cf=0, of=0
957 mulx
3*8($aptr),%rax,%r14
961 adcx
$zero,%r14 # cf=0
963 mulx
0*8($nptr),%rax,%r10
964 adcx
%rax,$bptr # discarded
966 mulx
1*8($nptr),%rax,%r11
969 .byte
0xc4,0x62,0xfb,0xf6,0xa1,0x10,0x00,0x00,0x00 # mulx 2*8($nptr),%rax,%r12
970 mov
48(%rsp),$bptr # counter value
974 mulx
3*8($nptr),%rax,%r15
978 adox
$zero,%r15 # of=0
986 adcx
$zero,%r15 # cf=0, modulo-scheduled
987 mulx
0*8($aptr),%r10,%rax # a[4]*b[0]
989 mulx
1*8($aptr),%r11,%r14 # a[5]*b[0]
991 mulx
2*8($aptr),%r12,%rax # ...
993 mulx
3*8($aptr),%r13,%r14
997 adcx
$zero,%r14 # cf=0
1002 mulx
0*8($nptr),%rax,%r15
1005 mulx
1*8($nptr),%rax,%r15
1008 mulx
2*8($nptr),%rax,%r15
1009 mov
%r10,-5*8($tptr)
1011 mov
%r11,-4*8($tptr)
1013 mulx
3*8($nptr),%rax,%r15
1015 mov
%r12,-3*8($tptr)
1018 lea
4*8($nptr),$nptr
1019 mov
%r13,-2*8($tptr)
1021 dec
$bptr # of=0, pass cf
1024 mov
0(%rsp),$num # load num
1025 mov
8(%rsp),$bptr # re-load &b[i]
1026 adc
$zero,%r15 # modulo-scheduled
1028 sbb
%r15,%r15 # top-most carry
1029 mov
%r14,-1*8($tptr)
1034 mov
($bptr),%rdx # b[i]
1035 lea
8($bptr),$bptr # b++
1036 sub $num,$aptr # rewind $aptr
1037 mov
%r15,($tptr) # save top-most carry
1038 lea
64+4*8(%rsp),$tptr
1039 sub $num,$nptr # rewind $nptr
1041 mulx
0*8($aptr),$mi,%r11 # a[0]*b[i]
1042 xor %ebp,%ebp # xor $zero,$zero # cf=0, of=0
1044 mulx
1*8($aptr),%r14,%r12 # a[1]*b[i]
1045 adox
-4*8($tptr),$mi
1047 mulx
2*8($aptr),%r15,%r13 # ...
1048 adox
-3*8($tptr),%r11
1053 mov
$bptr,8(%rsp) # off-load &b[i]
1056 imulq
24(%rsp),$mi # "t[0]"*n0
1057 xor %ebp,%ebp # xor $zero,$zero # cf=0, of=0
1059 mulx
3*8($aptr),%rax,%r14
1061 adox
-2*8($tptr),%r12
1063 adox
-1*8($tptr),%r13
1065 lea
4*8($aptr),$aptr
1068 mulx
0*8($nptr),%rax,%r10
1069 adcx
%rax,%r15 # discarded
1071 mulx
1*8($nptr),%rax,%r11
1074 mulx
2*8($nptr),%rax,%r12
1075 mov
%r10,-4*8($tptr)
1078 mulx
3*8($nptr),%rax,%r15
1080 mov
%r11,-3*8($tptr)
1081 lea
4*8($nptr),$nptr
1083 adox
$zero,%r15 # of=0
1084 mov
48(%rsp),$bptr # counter value
1085 mov
%r12,-2*8($tptr)
1091 mulx
0*8($aptr),%r10,%rax # a[4]*b[i]
1092 adcx
$zero,%r15 # cf=0, modulo-scheduled
1094 mulx
1*8($aptr),%r11,%r14 # a[5]*b[i]
1095 adcx
0*8($tptr),%r10
1097 mulx
2*8($aptr),%r12,%rax # ...
1098 adcx
1*8($tptr),%r11
1100 mulx
3*8($aptr),%r13,%r14
1102 adcx
2*8($tptr),%r12
1104 adcx
3*8($tptr),%r13
1105 adox
$zero,%r14 # of=0
1106 lea
4*8($aptr),$aptr
1107 lea
4*8($tptr),$tptr
1108 adcx
$zero,%r14 # cf=0
1111 mulx
0*8($nptr),%rax,%r15
1114 mulx
1*8($nptr),%rax,%r15
1117 mulx
2*8($nptr),%rax,%r15
1118 mov
%r10,-5*8($tptr)
1121 mulx
3*8($nptr),%rax,%r15
1123 mov
%r11,-4*8($tptr)
1124 mov
%r12,-3*8($tptr)
1127 lea
4*8($nptr),$nptr
1128 mov
%r13,-2*8($tptr)
1130 dec
$bptr # of=0, pass cf
1133 mov
0(%rsp),$num # load num
1134 mov
8(%rsp),$bptr # re-load &b[i]
1135 adc
$zero,%r15 # modulo-scheduled
1136 sub 0*8($tptr),$zero # pull top-most carry
1139 sbb
%r15,%r15 # top-most carry
1140 mov
%r14,-1*8($tptr)
1145 sub %r14,$mi # compare top-most words
1151 mov
32(%rsp),$rptr # restore rp
1155 mov
0*8($nptr,$num),%r8
1156 mov
1*8($nptr,$num),%r9
1158 jmp
.Lmulx4x_sub_entry
1162 mov
0*8($nptr,$num),%r8
1163 mov
1*8($nptr,$num),%r9
1166 mov
2*8($nptr,$num),%r10
1169 mov
3*8($nptr,$num),%r11
1176 neg
%rdx # mov %rdx,%cf
1179 movdqa
%xmm0,($tptr)
1182 movdqa
%xmm0,16($tptr)
1183 lea
4*8($tptr),$tptr
1184 sbb
%rdx,%rdx # mov %cf,%rdx
1190 lea
4*8($rptr),$rptr
1195 mov
40(%rsp),%rsi # restore %rsp
1206 .size bn_mulx4x_mont
,.-bn_mulx4x_mont
1210 .asciz
"Montgomery Multiplication for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
1214 # EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
1215 # CONTEXT *context,DISPATCHER_CONTEXT *disp)
1223 .extern __imp_RtlVirtualUnwind
1224 .type mul_handler
,\
@abi-omnipotent
1238 mov
120($context),%rax # pull context->Rax
1239 mov
248($context),%rbx # pull context->Rip
1241 mov
8($disp),%rsi # disp->ImageBase
1242 mov
56($disp),%r11 # disp->HandlerData
1244 mov
0(%r11),%r10d # HandlerData[0]
1245 lea
(%rsi,%r10),%r10 # end of prologue label
1246 cmp %r10,%rbx # context->Rip<end of prologue label
1247 jb
.Lcommon_seh_tail
1249 mov
152($context),%rax # pull context->Rsp
1251 mov
4(%r11),%r10d # HandlerData[1]
1252 lea
(%rsi,%r10),%r10 # epilogue label
1253 cmp %r10,%rbx # context->Rip>=epilogue label
1254 jae
.Lcommon_seh_tail
1256 mov
192($context),%r10 # pull $num
1257 mov
8(%rax,%r10,8),%rax # pull saved stack pointer
1266 mov
%rbx,144($context) # restore context->Rbx
1267 mov
%rbp,160($context) # restore context->Rbp
1268 mov
%r12,216($context) # restore context->R12
1269 mov
%r13,224($context) # restore context->R13
1270 mov
%r14,232($context) # restore context->R14
1271 mov
%r15,240($context) # restore context->R15
1273 jmp
.Lcommon_seh_tail
1274 .size mul_handler
,.-mul_handler
1276 .type sqr_handler
,\
@abi-omnipotent
1290 mov
120($context),%rax # pull context->Rax
1291 mov
248($context),%rbx # pull context->Rip
1293 mov
8($disp),%rsi # disp->ImageBase
1294 mov
56($disp),%r11 # disp->HandlerData
1296 mov
0(%r11),%r10d # HandlerData[0]
1297 lea
(%rsi,%r10),%r10 # end of prologue label
1298 cmp %r10,%rbx # context->Rip<.Lsqr_body
1299 jb
.Lcommon_seh_tail
1301 mov
152($context),%rax # pull context->Rsp
1303 mov
4(%r11),%r10d # HandlerData[1]
1304 lea
(%rsi,%r10),%r10 # epilogue label
1305 cmp %r10,%rbx # context->Rip>=.Lsqr_epilogue
1306 jae
.Lcommon_seh_tail
1308 mov
40(%rax),%rax # pull saved stack pointer
1316 mov
%rbx,144($context) # restore context->Rbx
1317 mov
%rbp,160($context) # restore context->Rbp
1318 mov
%r12,216($context) # restore context->R12
1319 mov
%r13,224($context) # restore context->R13
1320 mov
%r14,232($context) # restore context->R14
1321 mov
%r15,240($context) # restore context->R15
1326 mov
%rax,152($context) # restore context->Rsp
1327 mov
%rsi,168($context) # restore context->Rsi
1328 mov
%rdi,176($context) # restore context->Rdi
1330 mov
40($disp),%rdi # disp->ContextRecord
1331 mov
$context,%rsi # context
1332 mov \
$154,%ecx # sizeof(CONTEXT)
1333 .long
0xa548f3fc # cld; rep movsq
1336 xor %rcx,%rcx # arg1, UNW_FLAG_NHANDLER
1337 mov
8(%rsi),%rdx # arg2, disp->ImageBase
1338 mov
0(%rsi),%r8 # arg3, disp->ControlPc
1339 mov
16(%rsi),%r9 # arg4, disp->FunctionEntry
1340 mov
40(%rsi),%r10 # disp->ContextRecord
1341 lea
56(%rsi),%r11 # &disp->HandlerData
1342 lea
24(%rsi),%r12 # &disp->EstablisherFrame
1343 mov
%r10,32(%rsp) # arg5
1344 mov
%r11,40(%rsp) # arg6
1345 mov
%r12,48(%rsp) # arg7
1346 mov
%rcx,56(%rsp) # arg8, (NULL)
1347 call
*__imp_RtlVirtualUnwind
(%rip)
1349 mov \
$1,%eax # ExceptionContinueSearch
1361 .size sqr_handler
,.-sqr_handler
1365 .rva
.LSEH_begin_bn_mul_mont
1366 .rva
.LSEH_end_bn_mul_mont
1367 .rva
.LSEH_info_bn_mul_mont
1369 .rva
.LSEH_begin_bn_mul4x_mont
1370 .rva
.LSEH_end_bn_mul4x_mont
1371 .rva
.LSEH_info_bn_mul4x_mont
1373 .rva
.LSEH_begin_bn_sqr8x_mont
1374 .rva
.LSEH_end_bn_sqr8x_mont
1375 .rva
.LSEH_info_bn_sqr8x_mont
1377 $code.=<<___
if ($addx);
1378 .rva
.LSEH_begin_bn_mulx4x_mont
1379 .rva
.LSEH_end_bn_mulx4x_mont
1380 .rva
.LSEH_info_bn_mulx4x_mont
1385 .LSEH_info_bn_mul_mont
:
1388 .rva
.Lmul_body
,.Lmul_epilogue
# HandlerData[]
1389 .LSEH_info_bn_mul4x_mont
:
1392 .rva
.Lmul4x_body
,.Lmul4x_epilogue
# HandlerData[]
1393 .LSEH_info_bn_sqr8x_mont
:
1396 .rva
.Lsqr8x_body
,.Lsqr8x_epilogue
# HandlerData[]
1398 $code.=<<___
if ($addx);
1399 .LSEH_info_bn_mulx4x_mont
:
1402 .rva
.Lmulx4x_body
,.Lmulx4x_epilogue
# HandlerData[]