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]+)\./) {
72 $rp="%rdi"; # BN_ULONG *rp,
73 $ap="%rsi"; # const BN_ULONG *ap,
74 $bp="%rdx"; # const BN_ULONG *bp,
75 $np="%rcx"; # const BN_ULONG *np,
76 $n0="%r8"; # const BN_ULONG *n0,
77 $num="%r9"; # int num);
89 .extern OPENSSL_ia32cap_P
92 .type bn_mul_mont
,\
@function,6
100 $code.=<<___
if ($addx);
101 mov OPENSSL_ia32cap_P
+8(%rip),%r11d
123 lea
(%rsp,%r10,8),%rsp # tp=alloca(8*(num+2))
124 and \
$-1024,%rsp # minimize TLB usage
126 mov
%r11,8(%rsp,$num,8) # tp[num+1]=%rsp
128 mov
$bp,%r12 # reassign $bp
132 mov
($n0),$n0 # pull n0[0] value
133 mov
($bp),$m0 # m0=bp[0]
140 mulq
$m0 # ap[0]*bp[0]
144 imulq
$lo0,$m1 # "tp[0]"*n0
148 add
%rax,$lo0 # discarded
161 add
$hi0,$hi1 # np[j]*m1+ap[j]*bp[0]
164 mov
$hi1,-16(%rsp,$j,8) # tp[j-1]
168 mulq
$m0 # ap[j]*bp[0]
180 mov
($ap),%rax # ap[0]
182 add
$hi0,$hi1 # np[j]*m1+ap[j]*bp[0]
184 mov
$hi1,-16(%rsp,$j,8) # tp[j-1]
191 mov
$hi1,-8(%rsp,$num,8)
192 mov
%rdx,(%rsp,$num,8) # store upmost overflow bit
198 mov
($bp,$i,8),$m0 # m0=bp[i]
202 mulq
$m0 # ap[0]*bp[i]
203 add
%rax,$lo0 # ap[0]*bp[i]+tp[0]
207 imulq
$lo0,$m1 # tp[0]*n0
211 add
%rax,$lo0 # discarded
214 mov
8(%rsp),$lo0 # tp[1]
225 add
$lo0,$hi1 # np[j]*m1+ap[j]*bp[i]+tp[j]
228 mov
$hi1,-16(%rsp,$j,8) # tp[j-1]
232 mulq
$m0 # ap[j]*bp[i]
236 add
$hi0,$lo0 # ap[j]*bp[i]+tp[j]
246 mov
($ap),%rax # ap[0]
248 add
$lo0,$hi1 # np[j]*m1+ap[j]*bp[i]+tp[j]
251 mov
$hi1,-16(%rsp,$j,8) # tp[j-1]
257 add
$lo0,$hi1 # pull upmost overflow bit
259 mov
$hi1,-8(%rsp,$num,8)
260 mov
%rdx,(%rsp,$num,8) # store upmost overflow bit
266 xor $i,$i # i=0 and clear CF!
267 mov
(%rsp),%rax # tp[0]
268 lea
(%rsp),$ap # borrow ap for tp
272 .Lsub
: sbb
($np,$i,8),%rax
273 mov
%rax,($rp,$i,8) # rp[i]=tp[i]-np[i]
274 mov
8($ap,$i,8),%rax # tp[i+1]
276 dec
$j # doesnn't affect CF!
279 sbb \
$0,%rax # handle upmost overflow bit
286 or $np,$ap # ap=borrow?tp:rp
288 .Lcopy
: # copy or in-place refresh
290 mov
$i,(%rsp,$i,8) # zap temporary vector
291 mov
%rax,($rp,$i,8) # rp[i]=tp[i]
296 mov
8(%rsp,$num,8),%rsi # restore %rsp
307 .size bn_mul_mont
,.-bn_mul_mont
310 my @A=("%r10","%r11");
311 my @N=("%r13","%rdi");
313 .type bn_mul4x_mont
,\
@function,6
318 $code.=<<___
if ($addx);
335 lea
(%rsp,%r10,8),%rsp # tp=alloca(8*(num+4))
336 and \
$-1024,%rsp # minimize TLB usage
338 mov
%r11,8(%rsp,$num,8) # tp[num+1]=%rsp
340 mov
$rp,16(%rsp,$num,8) # tp[num+2]=$rp
341 mov
%rdx,%r12 # reassign $bp
345 mov
($n0),$n0 # pull n0[0] value
346 mov
($bp),$m0 # m0=bp[0]
353 mulq
$m0 # ap[0]*bp[0]
357 imulq
$A[0],$m1 # "tp[0]"*n0
361 add
%rax,$A[0] # discarded
384 mulq
$m0 # ap[j]*bp[0]
386 mov
-16($np,$j,8),%rax
392 mov
-8($ap,$j,8),%rax
394 add
$A[0],$N[0] # np[j]*m1+ap[j]*bp[0]
396 mov
$N[0],-24(%rsp,$j,8) # tp[j-1]
399 mulq
$m0 # ap[j]*bp[0]
401 mov
-8($np,$j,8),%rax
409 add
$A[1],$N[1] # np[j]*m1+ap[j]*bp[0]
411 mov
$N[1],-16(%rsp,$j,8) # tp[j-1]
414 mulq
$m0 # ap[j]*bp[0]
424 add
$A[0],$N[0] # np[j]*m1+ap[j]*bp[0]
426 mov
$N[0],-8(%rsp,$j,8) # tp[j-1]
429 mulq
$m0 # ap[j]*bp[0]
438 mov
-16($ap,$j,8),%rax
440 add
$A[1],$N[1] # np[j]*m1+ap[j]*bp[0]
442 mov
$N[1],-32(%rsp,$j,8) # tp[j-1]
447 mulq
$m0 # ap[j]*bp[0]
449 mov
-16($np,$j,8),%rax
455 mov
-8($ap,$j,8),%rax
457 add
$A[0],$N[0] # np[j]*m1+ap[j]*bp[0]
459 mov
$N[0],-24(%rsp,$j,8) # tp[j-1]
462 mulq
$m0 # ap[j]*bp[0]
464 mov
-8($np,$j,8),%rax
470 mov
($ap),%rax # ap[0]
472 add
$A[1],$N[1] # np[j]*m1+ap[j]*bp[0]
474 mov
$N[1],-16(%rsp,$j,8) # tp[j-1]
480 mov
$N[0],-8(%rsp,$j,8)
481 mov
$N[1],(%rsp,$j,8) # store upmost overflow bit
486 mov
($bp,$i,8),$m0 # m0=bp[i]
490 mulq
$m0 # ap[0]*bp[i]
491 add
%rax,$A[0] # ap[0]*bp[i]+tp[0]
495 imulq
$A[0],$m1 # tp[0]*n0
499 add
%rax,$A[0] # "$N[0]", discarded
504 mulq
$m0 # ap[j]*bp[i]
508 add
8(%rsp),$A[1] # +tp[1]
516 add
$A[1],$N[1] # np[j]*m1+ap[j]*bp[i]+tp[j]
519 mov
$N[1],(%rsp) # tp[j-1]
524 mulq
$m0 # ap[j]*bp[i]
526 mov
-16($np,$j,8),%rax
528 add
-16(%rsp,$j,8),$A[0] # ap[j]*bp[i]+tp[j]
534 mov
-8($ap,$j,8),%rax
538 mov
$N[0],-24(%rsp,$j,8) # tp[j-1]
541 mulq
$m0 # ap[j]*bp[i]
543 mov
-8($np,$j,8),%rax
545 add
-8(%rsp,$j,8),$A[1]
555 mov
$N[1],-16(%rsp,$j,8) # tp[j-1]
558 mulq
$m0 # ap[j]*bp[i]
562 add
(%rsp,$j,8),$A[0] # ap[j]*bp[i]+tp[j]
572 mov
$N[0],-8(%rsp,$j,8) # tp[j-1]
575 mulq
$m0 # ap[j]*bp[i]
579 add
8(%rsp,$j,8),$A[1]
586 mov
-16($ap,$j,8),%rax
590 mov
$N[1],-32(%rsp,$j,8) # tp[j-1]
595 mulq
$m0 # ap[j]*bp[i]
597 mov
-16($np,$j,8),%rax
599 add
-16(%rsp,$j,8),$A[0] # ap[j]*bp[i]+tp[j]
605 mov
-8($ap,$j,8),%rax
609 mov
$N[0],-24(%rsp,$j,8) # tp[j-1]
612 mulq
$m0 # ap[j]*bp[i]
614 mov
-8($np,$j,8),%rax
616 add
-8(%rsp,$j,8),$A[1]
623 mov
($ap),%rax # ap[0]
627 mov
$N[1],-16(%rsp,$j,8) # tp[j-1]
633 add
(%rsp,$num,8),$N[0] # pull upmost overflow bit
635 mov
$N[0],-8(%rsp,$j,8)
636 mov
$N[1],(%rsp,$j,8) # store upmost overflow bit
642 my @ri=("%rax","%rdx",$m0,$m1);
644 mov
16(%rsp,$num,8),$rp # restore $rp
645 mov
0(%rsp),@ri[0] # tp[0]
647 mov
8(%rsp),@ri[1] # tp[1]
648 shr \
$2,$num # num/=4
649 lea
(%rsp),$ap # borrow ap for tp
650 xor $i,$i # i=0 and clear CF!
653 mov
16($ap),@ri[2] # tp[2]
654 mov
24($ap),@ri[3] # tp[3]
656 lea
-1($num),$j # j=num/4-1
660 mov
@ri[0],0($rp,$i,8) # rp[i]=tp[i]-np[i]
661 mov
@ri[1],8($rp,$i,8) # rp[i]=tp[i]-np[i]
662 sbb
16($np,$i,8),@ri[2]
663 mov
32($ap,$i,8),@ri[0] # tp[i+1]
664 mov
40($ap,$i,8),@ri[1]
665 sbb
24($np,$i,8),@ri[3]
666 mov
@ri[2],16($rp,$i,8) # rp[i]=tp[i]-np[i]
667 mov
@ri[3],24($rp,$i,8) # rp[i]=tp[i]-np[i]
668 sbb
32($np,$i,8),@ri[0]
669 mov
48($ap,$i,8),@ri[2]
670 mov
56($ap,$i,8),@ri[3]
671 sbb
40($np,$i,8),@ri[1]
673 dec
$j # doesnn't affect CF!
676 mov
@ri[0],0($rp,$i,8) # rp[i]=tp[i]-np[i]
677 mov
32($ap,$i,8),@ri[0] # load overflow bit
678 sbb
16($np,$i,8),@ri[2]
679 mov
@ri[1],8($rp,$i,8) # rp[i]=tp[i]-np[i]
680 sbb
24($np,$i,8),@ri[3]
681 mov
@ri[2],16($rp,$i,8) # rp[i]=tp[i]-np[i]
683 sbb \
$0,@ri[0] # handle upmost overflow bit
684 mov
@ri[3],24($rp,$i,8) # rp[i]=tp[i]-np[i]
691 or $np,$ap # ap=borrow?tp:rp
698 .Lcopy4x
: # copy or in-place refresh
699 movdqu
16($ap,$i),%xmm2
700 movdqu
32($ap,$i),%xmm1
701 movdqa
%xmm0,16(%rsp,$i)
702 movdqu
%xmm2,16($rp,$i)
703 movdqa
%xmm0,32(%rsp,$i)
704 movdqu
%xmm1,32($rp,$i)
710 movdqu
16($ap,$i),%xmm2
711 movdqa
%xmm0,16(%rsp,$i)
712 movdqu
%xmm2,16($rp,$i)
716 mov
8(%rsp,$num,8),%rsi # restore %rsp
727 .size bn_mul4x_mont
,.-bn_mul4x_mont
731 ######################################################################
732 # void bn_sqr8x_mont(
733 my $rptr="%rdi"; # const BN_ULONG *rptr,
734 my $aptr="%rsi"; # const BN_ULONG *aptr,
735 my $bptr="%rdx"; # not used
736 my $nptr="%rcx"; # const BN_ULONG *nptr,
737 my $n0 ="%r8"; # const BN_ULONG *n0);
738 my $num ="%r9"; # int num, has to be divisible by 8
740 my ($i,$j,$tptr)=("%rbp","%rcx",$rptr);
741 my @A0=("%r10","%r11");
742 my @A1=("%r12","%r13");
743 my ($a0,$a1,$ai)=("%r14","%r15","%rbx");
745 $code.=<<___
if ($addx);
746 .extern bn_sqrx8x_internal
# see x86_64-mont5 module
749 .extern bn_sqr8x_internal
# see x86_64-mont5 module
751 .type bn_sqr8x_mont
,\
@function,6
764 shl \
$3,${num
}d
# convert $num to bytes
765 shl \
$3+2,%r10 # 4*$num
768 ##############################################################
769 # ensure that stack frame doesn't alias with $aptr modulo
770 # 4096. this is done to allow memory disambiguation logic
773 lea
-64(%rsp,$num,4),%r11
779 sub %r11,%rsp # align with $aptr
780 lea
-64(%rsp,$num,4),%rsp # alloca(frame+4*$num)
785 lea
4096-64(,$num,4),%r10 # 4096-frame-4*$num
786 lea
-64(%rsp,$num,4),%rsp # alloca(frame+4*$num)
796 lea
64(%rsp,$num,2),%r11 # copy of modulus
798 mov
%rax, 40(%rsp) # save original %rsp
802 movq
%r11, %xmm2 # save pointer to modulus copy
804 mov OPENSSL_ia32cap_P
+8(%rip),%eax
809 movq
8*0($nptr),%xmm0
810 movq
8*1($nptr),%xmm1
811 movq
8*2($nptr),%xmm3
812 movq
8*3($nptr),%xmm4
814 movdqa
%xmm0,16*0(%r11)
815 movdqa
%xmm1,16*1(%r11)
816 movdqa
%xmm3,16*2(%r11)
817 movdqa
%xmm4,16*3(%r11)
823 movq
$rptr,%xmm1 # save $rptr
824 movq
%r10, %xmm3 # -$num
826 $code.=<<___
if ($addx);
831 call bn_sqrx8x_internal
# see x86_64-mont5 module
835 lea
64(%rsp,$num,2),%rdx
837 mov
40(%rsp),%rsi # restore %rsp
844 call bn_sqr8x_internal
# see x86_64-mont5 module
848 lea
64(%rsp,$num,2),%rdx
850 mov
40(%rsp),%rsi # restore %rsp
855 movdqa
%xmm0,16*0(%rax) # wipe t
856 movdqa
%xmm0,16*1(%rax)
857 movdqa
%xmm0,16*2(%rax)
858 movdqa
%xmm0,16*3(%rax)
860 movdqa
%xmm0,16*0(%rdx) # wipe n
861 movdqa
%xmm0,16*1(%rdx)
862 movdqa
%xmm0,16*2(%rdx)
863 movdqa
%xmm0,16*3(%rdx)
878 .size bn_sqr8x_mont
,.-bn_sqr8x_mont
883 my $bp="%rdx"; # original value
886 .type bn_mulx4x_mont
,\
@function,6
898 shl \
$3,${num
}d
# convert $num to bytes
901 sub $num,%r10 # -$num
903 lea
-72(%rsp,%r10),%rsp # alloca(frame+$num+8)
906 ##############################################################
909 # +8 off-loaded &b[i]
918 mov
$num,0(%rsp) # save $num
920 mov
%r10,16(%rsp) # end of b[num]
922 mov
$n0, 24(%rsp) # save *n0
923 mov
$rp, 32(%rsp) # save $rp
924 mov
%rax,40(%rsp) # save original %rsp
925 mov
$num,48(%rsp) # inner counter
931 my ($aptr, $bptr, $nptr, $tptr, $mi, $bi, $zero, $num)=
932 ("%rsi","%rdi","%rcx","%rbx","%r8","%r9","%rbp","%rax");
936 mov
($bp),%rdx # b[0], $bp==%rdx actually
937 lea
64+32(%rsp),$tptr
940 mulx
0*8($aptr),$mi,%rax # a[0]*b[0]
941 mulx
1*8($aptr),%r11,%r14 # a[1]*b[0]
943 mov
$bptr,8(%rsp) # off-load &b[i]
944 mulx
2*8($aptr),%r12,%r13 # ...
948 mov
$mi,$bptr # borrow $bptr
949 imulq
24(%rsp),$mi # "t[0]"*n0
950 xor $zero,$zero # cf=0, of=0
952 mulx
3*8($aptr),%rax,%r14
956 adcx
$zero,%r14 # cf=0
958 mulx
0*8($nptr),%rax,%r10
959 adcx
%rax,$bptr # discarded
961 mulx
1*8($nptr),%rax,%r11
964 .byte
0xc4,0x62,0xfb,0xf6,0xa1,0x10,0x00,0x00,0x00 # mulx 2*8($nptr),%rax,%r12
965 mov
48(%rsp),$bptr # counter value
969 mulx
3*8($nptr),%rax,%r15
973 adox
$zero,%r15 # of=0
981 adcx
$zero,%r15 # cf=0, modulo-scheduled
982 mulx
0*8($aptr),%r10,%rax # a[4]*b[0]
984 mulx
1*8($aptr),%r11,%r14 # a[5]*b[0]
986 mulx
2*8($aptr),%r12,%rax # ...
988 mulx
3*8($aptr),%r13,%r14
992 adcx
$zero,%r14 # cf=0
997 mulx
0*8($nptr),%rax,%r15
1000 mulx
1*8($nptr),%rax,%r15
1003 mulx
2*8($nptr),%rax,%r15
1004 mov
%r10,-5*8($tptr)
1006 mov
%r11,-4*8($tptr)
1008 mulx
3*8($nptr),%rax,%r15
1010 mov
%r12,-3*8($tptr)
1013 lea
4*8($nptr),$nptr
1014 mov
%r13,-2*8($tptr)
1016 dec
$bptr # of=0, pass cf
1019 mov
0(%rsp),$num # load num
1020 mov
8(%rsp),$bptr # re-load &b[i]
1021 adc
$zero,%r15 # modulo-scheduled
1023 sbb
%r15,%r15 # top-most carry
1024 mov
%r14,-1*8($tptr)
1029 mov
($bptr),%rdx # b[i]
1030 lea
8($bptr),$bptr # b++
1031 sub $num,$aptr # rewind $aptr
1032 mov
%r15,($tptr) # save top-most carry
1033 lea
64+4*8(%rsp),$tptr
1034 sub $num,$nptr # rewind $nptr
1036 mulx
0*8($aptr),$mi,%r11 # a[0]*b[i]
1037 xor %ebp,%ebp # xor $zero,$zero # cf=0, of=0
1039 mulx
1*8($aptr),%r14,%r12 # a[1]*b[i]
1040 adox
-4*8($tptr),$mi
1042 mulx
2*8($aptr),%r15,%r13 # ...
1043 adox
-3*8($tptr),%r11
1048 mov
$bptr,8(%rsp) # off-load &b[i]
1051 imulq
24(%rsp),$mi # "t[0]"*n0
1052 xor %ebp,%ebp # xor $zero,$zero # cf=0, of=0
1054 mulx
3*8($aptr),%rax,%r14
1056 adox
-2*8($tptr),%r12
1058 adox
-1*8($tptr),%r13
1060 lea
4*8($aptr),$aptr
1063 mulx
0*8($nptr),%rax,%r10
1064 adcx
%rax,%r15 # discarded
1066 mulx
1*8($nptr),%rax,%r11
1069 mulx
2*8($nptr),%rax,%r12
1070 mov
%r10,-4*8($tptr)
1073 mulx
3*8($nptr),%rax,%r15
1075 mov
%r11,-3*8($tptr)
1076 lea
4*8($nptr),$nptr
1078 adox
$zero,%r15 # of=0
1079 mov
48(%rsp),$bptr # counter value
1080 mov
%r12,-2*8($tptr)
1086 mulx
0*8($aptr),%r10,%rax # a[4]*b[i]
1087 adcx
$zero,%r15 # cf=0, modulo-scheduled
1089 mulx
1*8($aptr),%r11,%r14 # a[5]*b[i]
1090 adcx
0*8($tptr),%r10
1092 mulx
2*8($aptr),%r12,%rax # ...
1093 adcx
1*8($tptr),%r11
1095 mulx
3*8($aptr),%r13,%r14
1097 adcx
2*8($tptr),%r12
1099 adcx
3*8($tptr),%r13
1100 adox
$zero,%r14 # of=0
1101 lea
4*8($aptr),$aptr
1102 lea
4*8($tptr),$tptr
1103 adcx
$zero,%r14 # cf=0
1106 mulx
0*8($nptr),%rax,%r15
1109 mulx
1*8($nptr),%rax,%r15
1112 mulx
2*8($nptr),%rax,%r15
1113 mov
%r10,-5*8($tptr)
1116 mulx
3*8($nptr),%rax,%r15
1118 mov
%r11,-4*8($tptr)
1119 mov
%r12,-3*8($tptr)
1122 lea
4*8($nptr),$nptr
1123 mov
%r13,-2*8($tptr)
1125 dec
$bptr # of=0, pass cf
1128 mov
0(%rsp),$num # load num
1129 mov
8(%rsp),$bptr # re-load &b[i]
1130 adc
$zero,%r15 # modulo-scheduled
1131 sub 0*8($tptr),$zero # pull top-most carry
1134 sbb
%r15,%r15 # top-most carry
1135 mov
%r14,-1*8($tptr)
1140 sub %r14,$mi # compare top-most words
1146 mov
32(%rsp),$rptr # restore rp
1150 mov
0*8($nptr,$num),%r8
1151 mov
1*8($nptr,$num),%r9
1153 jmp
.Lmulx4x_sub_entry
1157 mov
0*8($nptr,$num),%r8
1158 mov
1*8($nptr,$num),%r9
1161 mov
2*8($nptr,$num),%r10
1164 mov
3*8($nptr,$num),%r11
1171 neg
%rdx # mov %rdx,%cf
1174 movdqa
%xmm0,($tptr)
1177 movdqa
%xmm0,16($tptr)
1178 lea
4*8($tptr),$tptr
1179 sbb
%rdx,%rdx # mov %cf,%rdx
1185 lea
4*8($rptr),$rptr
1190 mov
40(%rsp),%rsi # restore %rsp
1201 .size bn_mulx4x_mont
,.-bn_mulx4x_mont
1205 .asciz
"Montgomery Multiplication for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
1209 # EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
1210 # CONTEXT *context,DISPATCHER_CONTEXT *disp)
1218 .extern __imp_RtlVirtualUnwind
1219 .type mul_handler
,\
@abi-omnipotent
1233 mov
120($context),%rax # pull context->Rax
1234 mov
248($context),%rbx # pull context->Rip
1236 mov
8($disp),%rsi # disp->ImageBase
1237 mov
56($disp),%r11 # disp->HandlerData
1239 mov
0(%r11),%r10d # HandlerData[0]
1240 lea
(%rsi,%r10),%r10 # end of prologue label
1241 cmp %r10,%rbx # context->Rip<end of prologue label
1242 jb
.Lcommon_seh_tail
1244 mov
152($context),%rax # pull context->Rsp
1246 mov
4(%r11),%r10d # HandlerData[1]
1247 lea
(%rsi,%r10),%r10 # epilogue label
1248 cmp %r10,%rbx # context->Rip>=epilogue label
1249 jae
.Lcommon_seh_tail
1251 mov
192($context),%r10 # pull $num
1252 mov
8(%rax,%r10,8),%rax # pull saved stack pointer
1261 mov
%rbx,144($context) # restore context->Rbx
1262 mov
%rbp,160($context) # restore context->Rbp
1263 mov
%r12,216($context) # restore context->R12
1264 mov
%r13,224($context) # restore context->R13
1265 mov
%r14,232($context) # restore context->R14
1266 mov
%r15,240($context) # restore context->R15
1268 jmp
.Lcommon_seh_tail
1269 .size mul_handler
,.-mul_handler
1271 .type sqr_handler
,\
@abi-omnipotent
1285 mov
120($context),%rax # pull context->Rax
1286 mov
248($context),%rbx # pull context->Rip
1288 mov
8($disp),%rsi # disp->ImageBase
1289 mov
56($disp),%r11 # disp->HandlerData
1291 mov
0(%r11),%r10d # HandlerData[0]
1292 lea
(%rsi,%r10),%r10 # end of prologue label
1293 cmp %r10,%rbx # context->Rip<.Lsqr_body
1294 jb
.Lcommon_seh_tail
1296 mov
152($context),%rax # pull context->Rsp
1298 mov
4(%r11),%r10d # HandlerData[1]
1299 lea
(%rsi,%r10),%r10 # epilogue label
1300 cmp %r10,%rbx # context->Rip>=.Lsqr_epilogue
1301 jae
.Lcommon_seh_tail
1303 mov
40(%rax),%rax # pull saved stack pointer
1311 mov
%rbx,144($context) # restore context->Rbx
1312 mov
%rbp,160($context) # restore context->Rbp
1313 mov
%r12,216($context) # restore context->R12
1314 mov
%r13,224($context) # restore context->R13
1315 mov
%r14,232($context) # restore context->R14
1316 mov
%r15,240($context) # restore context->R15
1321 mov
%rax,152($context) # restore context->Rsp
1322 mov
%rsi,168($context) # restore context->Rsi
1323 mov
%rdi,176($context) # restore context->Rdi
1325 mov
40($disp),%rdi # disp->ContextRecord
1326 mov
$context,%rsi # context
1327 mov \
$154,%ecx # sizeof(CONTEXT)
1328 .long
0xa548f3fc # cld; rep movsq
1331 xor %rcx,%rcx # arg1, UNW_FLAG_NHANDLER
1332 mov
8(%rsi),%rdx # arg2, disp->ImageBase
1333 mov
0(%rsi),%r8 # arg3, disp->ControlPc
1334 mov
16(%rsi),%r9 # arg4, disp->FunctionEntry
1335 mov
40(%rsi),%r10 # disp->ContextRecord
1336 lea
56(%rsi),%r11 # &disp->HandlerData
1337 lea
24(%rsi),%r12 # &disp->EstablisherFrame
1338 mov
%r10,32(%rsp) # arg5
1339 mov
%r11,40(%rsp) # arg6
1340 mov
%r12,48(%rsp) # arg7
1341 mov
%rcx,56(%rsp) # arg8, (NULL)
1342 call
*__imp_RtlVirtualUnwind
(%rip)
1344 mov \
$1,%eax # ExceptionContinueSearch
1356 .size sqr_handler
,.-sqr_handler
1360 .rva
.LSEH_begin_bn_mul_mont
1361 .rva
.LSEH_end_bn_mul_mont
1362 .rva
.LSEH_info_bn_mul_mont
1364 .rva
.LSEH_begin_bn_mul4x_mont
1365 .rva
.LSEH_end_bn_mul4x_mont
1366 .rva
.LSEH_info_bn_mul4x_mont
1368 .rva
.LSEH_begin_bn_sqr8x_mont
1369 .rva
.LSEH_end_bn_sqr8x_mont
1370 .rva
.LSEH_info_bn_sqr8x_mont
1372 $code.=<<___
if ($addx);
1373 .rva
.LSEH_begin_bn_mulx4x_mont
1374 .rva
.LSEH_end_bn_mulx4x_mont
1375 .rva
.LSEH_info_bn_mulx4x_mont
1380 .LSEH_info_bn_mul_mont
:
1383 .rva
.Lmul_body
,.Lmul_epilogue
# HandlerData[]
1384 .LSEH_info_bn_mul4x_mont
:
1387 .rva
.Lmul4x_body
,.Lmul4x_epilogue
# HandlerData[]
1388 .LSEH_info_bn_sqr8x_mont
:
1391 .rva
.Lsqr8x_body
,.Lsqr8x_epilogue
# HandlerData[]
1393 $code.=<<___
if ($addx);
1394 .LSEH_info_bn_mulx4x_mont
:
1397 .rva
.Lmulx4x_body
,.Lmulx4x_epilogue
# HandlerData[]