2 # Copyright 2014-2016 The OpenSSL Project Authors. All Rights Reserved.
3 # Copyright (c) 2014, Intel Corporation. All Rights Reserved.
4 # Copyright (c) 2015 CloudFlare, Inc.
6 # Licensed under the OpenSSL license (the "License"). You may not use
7 # this file except in compliance with the License. You can obtain a copy
8 # in the file LICENSE in the source distribution or at
9 # https://www.openssl.org/source/license.html
11 # Originally written by Shay Gueron (1, 2), and Vlad Krasnov (1, 3)
12 # (1) Intel Corporation, Israel Development Center, Haifa, Israel
13 # (2) University of Haifa, Israel
14 # (3) CloudFlare, Inc.
17 # S.Gueron and V.Krasnov, "Fast Prime Field Elliptic Curve Cryptography with
20 # Further optimization by <appro@openssl.org>:
22 # this/original with/without -DECP_NISTZ256_ASM(*)
23 # Opteron +15-49% +150-195%
24 # Bulldozer +18-45% +175-240%
25 # P4 +24-46% +100-150%
26 # Westmere +18-34% +87-160%
27 # Sandy Bridge +14-35% +120-185%
28 # Ivy Bridge +11-35% +125-180%
29 # Haswell +10-37% +160-200%
30 # Broadwell +24-58% +210-270%
31 # Atom +20-50% +180-240%
32 # VIA Nano +50-160% +480-480%
34 # (*) "without -DECP_NISTZ256_ASM" refers to build with
35 # "enable-ec_nistp_64_gcc_128";
37 # Ranges denote minimum and maximum improvement coefficients depending
38 # on benchmark. In "this/original" column lower coefficient is for
39 # ECDSA sign, while in "with/without" - for ECDH key agreement, and
40 # higher - for ECDSA sign, relatively fastest server-side operation.
41 # Keep in mind that +100% means 2x improvement.
45 if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
47 $win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
49 $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
50 ( $xlate="${dir}x86_64-xlate.pl" and -f $xlate ) or
51 ( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
52 die "can't locate x86_64-xlate.pl";
54 open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\"";
57 if (`$ENV{CC} -Wa,-v -c -o /dev/null -x assembler /dev/null 2>&1`
58 =~ /GNU assembler version ([2-9]\.[0-9]+)/) {
59 $avx = ($1>=2.19) + ($1>=2.22);
63 if (!$addx && $win64 && ($flavour =~ /nasm/ || $ENV{ASM} =~ /nasm/) &&
64 `nasm -v 2>&1` =~ /NASM version ([2-9]\.[0-9]+)/) {
65 $avx = ($1>=2.09) + ($1>=2.10);
69 if (!$addx && $win64 && ($flavour =~ /masm/ || $ENV{ASM} =~ /ml64/) &&
70 `ml64 2>&1` =~ /Version ([0-9]+)\./) {
71 $avx = ($1>=10) + ($1>=11);
75 if (!$addx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|.*based on LLVM) ([3-9])\.([0-9]+)/) {
76 my $ver = $2 + $3/100.0; # 3.1->3.01, 3.10->3.10
77 $avx = ($ver>=3.0) + ($ver>=3.01);
83 .extern OPENSSL_ia32cap_P
88 .quad 0xffffffffffffffff, 0x00000000ffffffff, 0x0000000000000000, 0xffffffff00000001
90 # 2^512 mod P precomputed for NIST P256 polynomial
92 .quad 0x0000000000000003, 0xfffffffbffffffff, 0xfffffffffffffffe, 0x00000004fffffffd
101 .quad 0x0000000000000001, 0xffffffff00000000, 0xffffffffffffffff, 0x00000000fffffffe
103 # Constants for computations modulo ord(p256)
105 .quad 0xf3b9cac2fc632551, 0xbce6faada7179e84, 0xffffffffffffffff, 0xffffffff00000000
107 .quad 0xccd1c8aaee00bc4f
111 ################################################################################
112 # void ecp_nistz256_mul_by_2(uint64_t res[4], uint64_t a[4]);
114 my ($a0,$a1,$a2,$a3)=map("%r$_",(8..11));
115 my ($t0,$t1,$t2,$t3,$t4)=("%rax","%rdx","%rcx","%r12","%r13");
116 my ($r_ptr,$a_ptr,$b_ptr)=("%rdi","%rsi","%rdx");
120 .globl ecp_nistz256_mul_by_2
121 .type ecp_nistz256_mul_by_2,\@function,2
123 ecp_nistz256_mul_by_2:
134 add $a0, $a0 # a0:a3+a0:a3
138 lea .Lpoly(%rip), $a_ptr
167 .cfi_adjust_cfa_offset -16
171 .size ecp_nistz256_mul_by_2,.-ecp_nistz256_mul_by_2
173 ################################################################################
174 # void ecp_nistz256_div_by_2(uint64_t res[4], uint64_t a[4]);
175 .globl ecp_nistz256_div_by_2
176 .type ecp_nistz256_div_by_2,\@function,2
178 ecp_nistz256_div_by_2:
191 lea .Lpoly(%rip), $a_ptr
202 xor $a_ptr, $a_ptr # borrow $a_ptr
211 mov $a1, $t0 # a0:a3>>1
237 .cfi_adjust_cfa_offset -16
241 .size ecp_nistz256_div_by_2,.-ecp_nistz256_div_by_2
243 ################################################################################
244 # void ecp_nistz256_mul_by_3(uint64_t res[4], uint64_t a[4]);
245 .globl ecp_nistz256_mul_by_3
246 .type ecp_nistz256_mul_by_3,\@function,2
248 ecp_nistz256_mul_by_3:
259 add $a0, $a0 # a0:a3+a0:a3
271 sbb .Lpoly+8*1(%rip), $a1
274 sbb .Lpoly+8*3(%rip), $a3
283 add 8*0($a_ptr), $a0 # a0:a3+=a_ptr[0:3]
293 sbb .Lpoly+8*1(%rip), $a1
296 sbb .Lpoly+8*3(%rip), $a3
313 .cfi_adjust_cfa_offset -16
317 .size ecp_nistz256_mul_by_3,.-ecp_nistz256_mul_by_3
319 ################################################################################
320 # void ecp_nistz256_add(uint64_t res[4], uint64_t a[4], uint64_t b[4]);
321 .globl ecp_nistz256_add
322 .type ecp_nistz256_add,\@function,3
337 lea .Lpoly(%rip), $a_ptr
369 .cfi_adjust_cfa_offset -16
373 .size ecp_nistz256_add,.-ecp_nistz256_add
375 ################################################################################
376 # void ecp_nistz256_sub(uint64_t res[4], uint64_t a[4], uint64_t b[4]);
377 .globl ecp_nistz256_sub
378 .type ecp_nistz256_sub,\@function,3
393 lea .Lpoly(%rip), $a_ptr
425 .cfi_adjust_cfa_offset -16
429 .size ecp_nistz256_sub,.-ecp_nistz256_sub
431 ################################################################################
432 # void ecp_nistz256_neg(uint64_t res[4], uint64_t a[4]);
433 .globl ecp_nistz256_neg
434 .type ecp_nistz256_neg,\@function,2
455 lea .Lpoly(%rip), $a_ptr
481 .cfi_adjust_cfa_offset -16
485 .size ecp_nistz256_neg,.-ecp_nistz256_neg
489 my ($r_ptr,$a_ptr,$b_org,$b_ptr)=("%rdi","%rsi","%rdx","%rbx");
490 my ($acc0,$acc1,$acc2,$acc3,$acc4,$acc5,$acc6,$acc7)=map("%r$_",(8..15));
491 my ($t0,$t1,$t2,$t3,$t4)=("%rcx","%rbp","%rbx","%rdx","%rax");
492 my ($poly1,$poly3)=($acc6,$acc7);
495 ################################################################################
496 # void ecp_nistz256_ord_mul_mont(
501 .globl ecp_nistz256_ord_mul_mont
502 .type ecp_nistz256_ord_mul_mont,\@function,3
504 ecp_nistz256_ord_mul_mont:
506 $code.=<<___ if ($addx);
508 and OPENSSL_ia32cap_P+8(%rip), %ecx
510 je .Lecp_nistz256_ord_mul_montx
520 mov 8*0($b_org), %rax
522 lea .Lord(%rip), %r14
523 mov .LordK(%rip), %r15
525 ################################# * b[0]
553 ################################# First reduction step
556 add %rax, $acc5 # guaranteed to be zero
562 sbb \$0, $acc0 # can't borrow
571 adc \$0, $acc0 # can't overflow
576 mov 8*1($b_ptr), %rax
577 sbb %rdx, $t1 # can't borrow
583 ################################# * b[1]
619 ################################# Second reduction step
622 add %rax, $t0 # guaranteed to be zero
627 sbb \$0, $acc1 # can't borrow
636 adc \$0, $acc1 # can't overflow
641 mov 8*2($b_ptr), %rax
642 sbb %rdx, $t1 # can't borrow
648 ################################## * b[2]
684 ################################# Third reduction step
687 add %rax, $t0 # guaranteed to be zero
692 sbb \$0, $acc2 # can't borrow
701 adc \$0, $acc2 # can't overflow
706 mov 8*3($b_ptr), %rax
707 sbb %rdx, $t1 # can't borrow
713 ################################# * b[3]
749 ################################# Last reduction step
752 add %rax, $t0 # guaranteed to be zero
757 sbb \$0, $acc3 # can't borrow
766 adc \$0, $acc3 # can't overflow
771 sbb %rdx, $t1 # can't borrow
777 ################################# Subtract ord
793 mov $acc4, 8*0($r_ptr)
794 mov $acc5, 8*1($r_ptr)
795 mov $acc0, 8*2($r_ptr)
796 mov $acc1, 8*3($r_ptr)
805 .size ecp_nistz256_ord_mul_mont,.-ecp_nistz256_ord_mul_mont
807 ################################################################################
808 # void ecp_nistz256_ord_sqr_mont(
813 .globl ecp_nistz256_ord_sqr_mont
814 .type ecp_nistz256_ord_sqr_mont,\@function,3
816 ecp_nistz256_ord_sqr_mont:
818 $code.=<<___ if ($addx);
820 and OPENSSL_ia32cap_P+8(%rip), %ecx
822 je .Lecp_nistz256_ord_sqr_montx
832 mov 8*0($a_ptr), $acc0
833 mov 8*1($a_ptr), %rax
834 mov 8*2($a_ptr), $acc6
835 mov 8*3($a_ptr), $acc7
836 lea .Lord(%rip), $a_ptr # pointer to modulus
842 ################################# a[1:] * a[0]
843 mov %rax, $t1 # put aside a[1]
844 mul $acc0 # a[1] * a[0]
846 movq $t1, %xmm1 # offload a[1]
850 mul $acc0 # a[2] * a[0]
853 movq $acc6, %xmm2 # offload a[2]
857 mul $acc0 # a[3] * a[0]
860 movq $acc7, %xmm3 # offload a[3]
864 ################################# a[3] * a[2]
865 mul $acc6 # a[3] * a[2]
870 ################################# a[2:] * a[1]
871 mul $t1 # a[2] * a[1]
877 mul $t1 # a[3] * a[1]
883 adc \$0, $acc6 # can't overflow
885 ################################# *2
896 ################################# Missing products
897 mul %rax # a[0] * a[0]
902 mul %rax # a[1] * a[1]
909 mul %rax # a[2] * a[2]
917 imulq 8*4($a_ptr), $acc0 # *= .LordK
919 mul %rax # a[3] * a[3]
922 mov 8*0($a_ptr), %rax # modulus[0]
923 adc %rdx, $acc7 # can't overflow
925 ################################# First reduction step
928 add %rax, $t0 # guaranteed to be zero
929 mov 8*1($a_ptr), %rax # modulus[1]
933 sbb \$0, $t1 # can't borrow
942 adc \$0, $t1 # can't overflow
945 imulq 8*4($a_ptr), $acc1 # *= .LordK
950 mov 8*0($a_ptr), %rax
951 sbb %rdx, $acc0 # can't borrow
954 adc \$0, $acc0 # can't overflow
956 ################################# Second reduction step
959 add %rax, $t0 # guaranteed to be zero
960 mov 8*1($a_ptr), %rax
964 sbb \$0, $t1 # can't borrow
973 adc \$0, $t1 # can't overflow
976 imulq 8*4($a_ptr), $acc2 # *= .LordK
981 mov 8*0($a_ptr), %rax
982 sbb %rdx, $acc1 # can't borrow
985 adc \$0, $acc1 # can't overflow
987 ################################# Third reduction step
990 add %rax, $t0 # guaranteed to be zero
991 mov 8*1($a_ptr), %rax
995 sbb \$0, $t1 # can't borrow
1004 adc \$0, $t1 # can't overflow
1007 imulq 8*4($a_ptr), $acc3 # *= .LordK
1012 mov 8*0($a_ptr), %rax
1013 sbb %rdx, $acc2 # can't borrow
1016 adc \$0, $acc2 # can't overflow
1018 ################################# Last reduction step
1021 add %rax, $t0 # guaranteed to be zero
1022 mov 8*1($a_ptr), %rax
1026 sbb \$0, $t1 # can't borrow
1035 adc \$0, $t1 # can't overflow
1040 sbb %rdx, $acc3 # can't borrow
1043 adc \$0, $acc3 # can't overflow
1045 ################################# Add bits [511:256] of the sqr result
1055 ################################# Compare to modulus
1056 sub 8*0($a_ptr), $acc0
1058 sbb 8*1($a_ptr), $acc1
1059 sbb 8*2($a_ptr), $acc2
1061 sbb 8*3($a_ptr), $acc3
1072 mov $acc0, 8*0($r_ptr)
1073 mov %rax, 8*1($r_ptr)
1075 mov $acc6, 8*2($r_ptr)
1077 mov $acc7, 8*3($r_ptr)
1087 .size ecp_nistz256_ord_sqr_mont,.-ecp_nistz256_ord_sqr_mont
1090 $code.=<<___ if ($addx);
1091 ################################################################################
1092 .type ecp_nistz256_ord_mul_montx,\@function,3
1094 ecp_nistz256_ord_mul_montx:
1095 .Lecp_nistz256_ord_mul_montx:
1104 mov 8*0($b_org), %rdx
1105 mov 8*0($a_ptr), $acc1
1106 mov 8*1($a_ptr), $acc2
1107 mov 8*2($a_ptr), $acc3
1108 mov 8*3($a_ptr), $acc4
1109 lea -128($a_ptr), $a_ptr # control u-op density
1110 lea .Lord-128(%rip), %r14
1111 mov .LordK(%rip), %r15
1113 ################################# Multiply by b[0]
1114 mulx $acc1, $acc0, $acc1
1115 mulx $acc2, $t0, $acc2
1116 mulx $acc3, $t1, $acc3
1118 mulx $acc4, $t0, $acc4
1120 mulx %r15, %rdx, %rax
1125 ################################# reduction
1126 xor $acc5, $acc5 # $acc5=0, cf=0, of=0
1127 mulx 8*0+128(%r14), $t0, $t1
1128 adcx $t0, $acc0 # guaranteed to be zero
1131 mulx 8*1+128(%r14), $t0, $t1
1135 mulx 8*2+128(%r14), $t0, $t1
1139 mulx 8*3+128(%r14), $t0, $t1
1140 mov 8*1($b_ptr), %rdx
1145 adc \$0, $acc5 # cf=0, of=0
1147 ################################# Multiply by b[1]
1148 mulx 8*0+128($a_ptr), $t0, $t1
1152 mulx 8*1+128($a_ptr), $t0, $t1
1156 mulx 8*2+128($a_ptr), $t0, $t1
1160 mulx 8*3+128($a_ptr), $t0, $t1
1162 mulx %r15, %rdx, %rax
1168 adc \$0, $acc0 # cf=0, of=0
1170 ################################# reduction
1171 mulx 8*0+128(%r14), $t0, $t1
1172 adcx $t0, $acc1 # guaranteed to be zero
1175 mulx 8*1+128(%r14), $t0, $t1
1179 mulx 8*2+128(%r14), $t0, $t1
1183 mulx 8*3+128(%r14), $t0, $t1
1184 mov 8*2($b_ptr), %rdx
1189 adc \$0, $acc0 # cf=0, of=0
1191 ################################# Multiply by b[2]
1192 mulx 8*0+128($a_ptr), $t0, $t1
1196 mulx 8*1+128($a_ptr), $t0, $t1
1200 mulx 8*2+128($a_ptr), $t0, $t1
1204 mulx 8*3+128($a_ptr), $t0, $t1
1206 mulx %r15, %rdx, %rax
1212 adc \$0, $acc1 # cf=0, of=0
1214 ################################# reduction
1215 mulx 8*0+128(%r14), $t0, $t1
1216 adcx $t0, $acc2 # guaranteed to be zero
1219 mulx 8*1+128(%r14), $t0, $t1
1223 mulx 8*2+128(%r14), $t0, $t1
1227 mulx 8*3+128(%r14), $t0, $t1
1228 mov 8*3($b_ptr), %rdx
1233 adc \$0, $acc1 # cf=0, of=0
1235 ################################# Multiply by b[3]
1236 mulx 8*0+128($a_ptr), $t0, $t1
1240 mulx 8*1+128($a_ptr), $t0, $t1
1244 mulx 8*2+128($a_ptr), $t0, $t1
1248 mulx 8*3+128($a_ptr), $t0, $t1
1250 mulx %r15, %rdx, %rax
1256 adc \$0, $acc2 # cf=0, of=0
1258 ################################# reduction
1259 mulx 8*0+128(%r14), $t0, $t1
1260 adcx $t0, $acc3 # guranteed to be zero
1263 mulx 8*1+128(%r14), $t0, $t1
1267 mulx 8*2+128(%r14), $t0, $t1
1271 mulx 8*3+128(%r14), $t0, $t1
1281 #################################
1282 # Branch-less conditional subtraction of P
1284 sub 8*0(%r14), $acc4
1285 sbb 8*1(%r14), $acc5
1286 sbb 8*2(%r14), $acc0
1288 sbb 8*3(%r14), $acc1
1296 mov $acc4, 8*0($r_ptr)
1297 mov $acc5, 8*1($r_ptr)
1298 mov $acc0, 8*2($r_ptr)
1299 mov $acc1, 8*3($r_ptr)
1308 .size ecp_nistz256_ord_mul_montx,.-ecp_nistz256_ord_mul_montx
1310 .type ecp_nistz256_ord_sqr_montx,\@function,3
1312 ecp_nistz256_ord_sqr_montx:
1313 .Lecp_nistz256_ord_sqr_montx:
1322 mov 8*0($a_ptr), %rdx
1323 mov 8*1($a_ptr), $acc6
1324 mov 8*2($a_ptr), $acc7
1325 mov 8*3($a_ptr), $acc0
1326 lea .Lord(%rip), $a_ptr
1331 mulx $acc6, $acc1, $acc2 # a[0]*a[1]
1332 mulx $acc7, $t0, $acc3 # a[0]*a[2]
1333 mov %rdx, %rax # offload a[0]
1334 movq $acc6, %xmm1 # offload a[1]
1335 mulx $acc0, $t1, $acc4 # a[0]*a[3]
1338 movq $acc7, %xmm2 # offload a[2]
1341 xor $acc5, $acc5 # $acc5=0,cf=0,of=0
1342 #################################
1343 mulx $acc7, $t0, $t1 # a[1]*a[2]
1347 mulx $acc0, $t0, $t1 # a[1]*a[3]
1352 #################################
1353 mulx $acc0, $t0, $acc6 # a[2]*a[3]
1355 movq $acc0, %xmm3 # offload a[3]
1356 xor $acc7, $acc7 # $acc7=0,cf=0,of=0
1357 adcx $acc1, $acc1 # acc1:6<<1
1360 adox $acc7, $acc6 # of=0
1362 ################################# a[i]*a[i]
1363 mulx %rdx, $acc0, $t1
1384 ################################# reduction
1386 mulx 8*4($a_ptr), %rdx, $t0
1388 xor %rax, %rax # cf=0, of=0
1389 mulx 8*0($a_ptr), $t0, $t1
1390 adcx $t0, $acc0 # guaranteed to be zero
1392 mulx 8*1($a_ptr), $t0, $t1
1395 mulx 8*2($a_ptr), $t0, $t1
1398 mulx 8*3($a_ptr), $t0, $t1
1400 adox $t1, $acc0 # of=0
1401 adcx %rax, $acc0 # cf=0
1403 #################################
1405 mulx 8*4($a_ptr), %rdx, $t0
1407 mulx 8*0($a_ptr), $t0, $t1
1408 adox $t0, $acc1 # guaranteed to be zero
1410 mulx 8*1($a_ptr), $t0, $t1
1413 mulx 8*2($a_ptr), $t0, $t1
1416 mulx 8*3($a_ptr), $t0, $t1
1418 adcx $t1, $acc1 # cf=0
1419 adox %rax, $acc1 # of=0
1421 #################################
1423 mulx 8*4($a_ptr), %rdx, $t0
1425 mulx 8*0($a_ptr), $t0, $t1
1426 adcx $t0, $acc2 # guaranteed to be zero
1428 mulx 8*1($a_ptr), $t0, $t1
1431 mulx 8*2($a_ptr), $t0, $t1
1434 mulx 8*3($a_ptr), $t0, $t1
1436 adox $t1, $acc2 # of=0
1437 adcx %rax, $acc2 # cf=0
1439 #################################
1441 mulx 8*4($a_ptr), %rdx, $t0
1443 mulx 8*0($a_ptr), $t0, $t1
1444 adox $t0, $acc3 # guaranteed to be zero
1446 mulx 8*1($a_ptr), $t0, $t1
1449 mulx 8*2($a_ptr), $t0, $t1
1452 mulx 8*3($a_ptr), $t0, $t1
1457 ################################# accumulate upper half
1458 add $acc0, $acc4 # add $acc4, $acc0
1466 ################################# compare to modulus
1467 sub 8*0($a_ptr), $acc4
1469 sbb 8*1($a_ptr), $acc1
1470 sbb 8*2($a_ptr), $acc2
1472 sbb 8*3($a_ptr), $acc3
1483 mov %rdx, 8*0($r_ptr)
1484 mov $acc6, 8*1($r_ptr)
1486 mov $acc7, 8*2($r_ptr)
1488 mov $acc0, 8*3($r_ptr)
1499 .size ecp_nistz256_ord_sqr_montx,.-ecp_nistz256_ord_sqr_montx
1503 ################################################################################
1504 # void ecp_nistz256_to_mont(
1507 .globl ecp_nistz256_to_mont
1508 .type ecp_nistz256_to_mont,\@function,2
1510 ecp_nistz256_to_mont:
1512 $code.=<<___ if ($addx);
1514 and OPENSSL_ia32cap_P+8(%rip), %ecx
1517 lea .LRR(%rip), $b_org
1519 .size ecp_nistz256_to_mont,.-ecp_nistz256_to_mont
1521 ################################################################################
1522 # void ecp_nistz256_mul_mont(
1527 .globl ecp_nistz256_mul_mont
1528 .type ecp_nistz256_mul_mont,\@function,3
1530 ecp_nistz256_mul_mont:
1533 $code.=<<___ if ($addx);
1535 and OPENSSL_ia32cap_P+8(%rip), %ecx
1553 $code.=<<___ if ($addx);
1559 mov 8*0($b_org), %rax
1560 mov 8*0($a_ptr), $acc1
1561 mov 8*1($a_ptr), $acc2
1562 mov 8*2($a_ptr), $acc3
1563 mov 8*3($a_ptr), $acc4
1565 call __ecp_nistz256_mul_montq
1567 $code.=<<___ if ($addx);
1573 mov 8*0($b_org), %rdx
1574 mov 8*0($a_ptr), $acc1
1575 mov 8*1($a_ptr), $acc2
1576 mov 8*2($a_ptr), $acc3
1577 mov 8*3($a_ptr), $acc4
1578 lea -128($a_ptr), $a_ptr # control u-op density
1580 call __ecp_nistz256_mul_montx
1597 .cfi_adjust_cfa_offset -48
1601 .size ecp_nistz256_mul_mont,.-ecp_nistz256_mul_mont
1603 .type __ecp_nistz256_mul_montq,\@abi-omnipotent
1605 __ecp_nistz256_mul_montq:
1606 ########################################################################
1607 # Multiply a by b[0]
1610 mov .Lpoly+8*1(%rip),$poly1
1616 mov .Lpoly+8*3(%rip),$poly3
1635 ########################################################################
1636 # First reduction step
1637 # Basically now we want to multiply acc[0] by p256,
1638 # and add the result to the acc.
1639 # Due to the special form of p256 we do some optimizations
1641 # acc[0] x p256[0..1] = acc[0] x 2^96 - acc[0]
1642 # then we add acc[0] and get acc[0] x 2^96
1648 add $acc0, $acc1 # +=acc[0]<<96
1651 mov 8*1($b_ptr), %rax
1656 ########################################################################
1689 ########################################################################
1690 # Second reduction step
1698 mov 8*2($b_ptr), %rax
1703 ########################################################################
1736 ########################################################################
1737 # Third reduction step
1745 mov 8*3($b_ptr), %rax
1750 ########################################################################
1783 ########################################################################
1784 # Final reduction step
1797 ########################################################################
1798 # Branch-less conditional subtraction of P
1799 sub \$-1, $acc4 # .Lpoly[0]
1801 sbb $poly1, $acc5 # .Lpoly[1]
1802 sbb \$0, $acc0 # .Lpoly[2]
1804 sbb $poly3, $acc1 # .Lpoly[3]
1809 mov $acc4, 8*0($r_ptr)
1811 mov $acc5, 8*1($r_ptr)
1813 mov $acc0, 8*2($r_ptr)
1814 mov $acc1, 8*3($r_ptr)
1817 .size __ecp_nistz256_mul_montq,.-__ecp_nistz256_mul_montq
1819 ################################################################################
1820 # void ecp_nistz256_sqr_mont(
1824 # we optimize the square according to S.Gueron and V.Krasnov,
1825 # "Speeding up Big-Number Squaring"
1826 .globl ecp_nistz256_sqr_mont
1827 .type ecp_nistz256_sqr_mont,\@function,2
1829 ecp_nistz256_sqr_mont:
1832 $code.=<<___ if ($addx);
1834 and OPENSSL_ia32cap_P+8(%rip), %ecx
1851 $code.=<<___ if ($addx);
1856 mov 8*0($a_ptr), %rax
1857 mov 8*1($a_ptr), $acc6
1858 mov 8*2($a_ptr), $acc7
1859 mov 8*3($a_ptr), $acc0
1861 call __ecp_nistz256_sqr_montq
1863 $code.=<<___ if ($addx);
1868 mov 8*0($a_ptr), %rdx
1869 mov 8*1($a_ptr), $acc6
1870 mov 8*2($a_ptr), $acc7
1871 mov 8*3($a_ptr), $acc0
1872 lea -128($a_ptr), $a_ptr # control u-op density
1874 call __ecp_nistz256_sqr_montx
1891 .cfi_adjust_cfa_offset -48
1895 .size ecp_nistz256_sqr_mont,.-ecp_nistz256_sqr_mont
1897 .type __ecp_nistz256_sqr_montq,\@abi-omnipotent
1899 __ecp_nistz256_sqr_montq:
1901 mulq $acc6 # a[1]*a[0]
1906 mulq $acc5 # a[0]*a[2]
1912 mulq $acc5 # a[0]*a[3]
1918 #################################
1919 mulq $acc6 # a[1]*a[2]
1925 mulq $acc6 # a[1]*a[3]
1933 #################################
1934 mulq $acc7 # a[2]*a[3]
1937 mov 8*0($a_ptr), %rax
1941 add $acc1, $acc1 # acc1:6<<1
1951 mov 8*1($a_ptr), %rax
1957 mov 8*2($a_ptr), %rax
1964 mov 8*3($a_ptr), %rax
1974 mov .Lpoly+8*1(%rip), $a_ptr
1975 mov .Lpoly+8*3(%rip), $t1
1977 ##########################################
1984 add $acc0, $acc1 # +=acc[0]<<96
1990 ##########################################
2003 ##########################################
2016 ###########################################
2029 ############################################
2030 # Add the rest of the acc
2039 sub \$-1, $acc4 # .Lpoly[0]
2041 sbb $a_ptr, $acc5 # .Lpoly[1]
2042 sbb \$0, $acc6 # .Lpoly[2]
2044 sbb $t1, $acc7 # .Lpoly[3]
2049 mov $acc4, 8*0($r_ptr)
2051 mov $acc5, 8*1($r_ptr)
2053 mov $acc6, 8*2($r_ptr)
2054 mov $acc7, 8*3($r_ptr)
2057 .size __ecp_nistz256_sqr_montq,.-__ecp_nistz256_sqr_montq
2062 .type __ecp_nistz256_mul_montx,\@abi-omnipotent
2064 __ecp_nistz256_mul_montx:
2065 ########################################################################
2067 mulx $acc1, $acc0, $acc1
2068 mulx $acc2, $t0, $acc2
2070 xor $acc5, $acc5 # cf=0
2071 mulx $acc3, $t1, $acc3
2072 mov .Lpoly+8*3(%rip), $poly3
2074 mulx $acc4, $t0, $acc4
2077 shlx $poly1,$acc0,$t1
2079 shrx $poly1,$acc0,$t0
2082 ########################################################################
2083 # First reduction step
2087 mulx $poly3, $t0, $t1
2088 mov 8*1($b_ptr), %rdx
2092 xor $acc0, $acc0 # $acc0=0,cf=0,of=0
2094 ########################################################################
2096 mulx 8*0+128($a_ptr), $t0, $t1
2100 mulx 8*1+128($a_ptr), $t0, $t1
2104 mulx 8*2+128($a_ptr), $t0, $t1
2108 mulx 8*3+128($a_ptr), $t0, $t1
2111 shlx $poly1, $acc1, $t0
2113 shrx $poly1, $acc1, $t1
2119 ########################################################################
2120 # Second reduction step
2124 mulx $poly3, $t0, $t1
2125 mov 8*2($b_ptr), %rdx
2129 xor $acc1 ,$acc1 # $acc1=0,cf=0,of=0
2131 ########################################################################
2133 mulx 8*0+128($a_ptr), $t0, $t1
2137 mulx 8*1+128($a_ptr), $t0, $t1
2141 mulx 8*2+128($a_ptr), $t0, $t1
2145 mulx 8*3+128($a_ptr), $t0, $t1
2148 shlx $poly1, $acc2, $t0
2150 shrx $poly1, $acc2, $t1
2156 ########################################################################
2157 # Third reduction step
2161 mulx $poly3, $t0, $t1
2162 mov 8*3($b_ptr), %rdx
2166 xor $acc2, $acc2 # $acc2=0,cf=0,of=0
2168 ########################################################################
2170 mulx 8*0+128($a_ptr), $t0, $t1
2174 mulx 8*1+128($a_ptr), $t0, $t1
2178 mulx 8*2+128($a_ptr), $t0, $t1
2182 mulx 8*3+128($a_ptr), $t0, $t1
2185 shlx $poly1, $acc3, $t0
2187 shrx $poly1, $acc3, $t1
2193 ########################################################################
2194 # Fourth reduction step
2198 mulx $poly3, $t0, $t1
2200 mov .Lpoly+8*1(%rip), $poly1
2206 ########################################################################
2207 # Branch-less conditional subtraction of P
2210 sbb \$-1, $acc4 # .Lpoly[0]
2211 sbb $poly1, $acc5 # .Lpoly[1]
2212 sbb \$0, $acc0 # .Lpoly[2]
2214 sbb $poly3, $acc1 # .Lpoly[3]
2219 mov $acc4, 8*0($r_ptr)
2221 mov $acc5, 8*1($r_ptr)
2223 mov $acc0, 8*2($r_ptr)
2224 mov $acc1, 8*3($r_ptr)
2227 .size __ecp_nistz256_mul_montx,.-__ecp_nistz256_mul_montx
2229 .type __ecp_nistz256_sqr_montx,\@abi-omnipotent
2231 __ecp_nistz256_sqr_montx:
2232 mulx $acc6, $acc1, $acc2 # a[0]*a[1]
2233 mulx $acc7, $t0, $acc3 # a[0]*a[2]
2236 mulx $acc0, $t1, $acc4 # a[0]*a[3]
2240 xor $acc5, $acc5 # $acc5=0,cf=0,of=0
2242 #################################
2243 mulx $acc7, $t0, $t1 # a[1]*a[2]
2247 mulx $acc0, $t0, $t1 # a[1]*a[3]
2253 #################################
2254 mulx $acc0, $t0, $acc6 # a[2]*a[3]
2255 mov 8*0+128($a_ptr), %rdx
2256 xor $acc7, $acc7 # $acc7=0,cf=0,of=0
2257 adcx $acc1, $acc1 # acc1:6<<1
2260 adox $acc7, $acc6 # of=0
2262 mulx %rdx, $acc0, $t1
2263 mov 8*1+128($a_ptr), %rdx
2268 mov 8*2+128($a_ptr), %rdx
2274 mov 8*3+128($a_ptr), %rdx
2282 mov .Lpoly+8*3(%rip), %rdx
2284 shlx $a_ptr, $acc0, $t0
2286 shrx $a_ptr, $acc0, $t4
2293 mulx $acc0, $t0, $acc0
2295 shlx $a_ptr, $acc1, $t0
2297 shrx $a_ptr, $acc1, $t4
2303 mulx $acc1, $t0, $acc1
2305 shlx $a_ptr, $acc2, $t0
2307 shrx $a_ptr, $acc2, $t4
2313 mulx $acc2, $t0, $acc2
2315 shlx $a_ptr, $acc3, $t0
2317 shrx $a_ptr, $acc3, $t4
2323 mulx $acc3, $t0, $acc3
2328 add $acc0, $acc4 # accumulate upper half
2329 mov .Lpoly+8*1(%rip), $a_ptr
2337 sub \$-1, $acc4 # .Lpoly[0]
2339 sbb $a_ptr, $acc5 # .Lpoly[1]
2340 sbb \$0, $acc6 # .Lpoly[2]
2342 sbb $t1, $acc7 # .Lpoly[3]
2347 mov $acc4, 8*0($r_ptr)
2349 mov $acc5, 8*1($r_ptr)
2351 mov $acc6, 8*2($r_ptr)
2352 mov $acc7, 8*3($r_ptr)
2355 .size __ecp_nistz256_sqr_montx,.-__ecp_nistz256_sqr_montx
2360 my ($r_ptr,$in_ptr)=("%rdi","%rsi");
2361 my ($acc0,$acc1,$acc2,$acc3)=map("%r$_",(8..11));
2362 my ($t0,$t1,$t2)=("%rcx","%r12","%r13");
2365 ################################################################################
2366 # void ecp_nistz256_from_mont(
2369 # This one performs Montgomery multiplication by 1, so we only need the reduction
2371 .globl ecp_nistz256_from_mont
2372 .type ecp_nistz256_from_mont,\@function,2
2374 ecp_nistz256_from_mont:
2382 mov 8*0($in_ptr), %rax
2383 mov .Lpoly+8*3(%rip), $t2
2384 mov 8*1($in_ptr), $acc1
2385 mov 8*2($in_ptr), $acc2
2386 mov 8*3($in_ptr), $acc3
2388 mov .Lpoly+8*1(%rip), $t1
2390 #########################################
2402 #########################################
2415 ##########################################
2428 ###########################################
2442 ###########################################
2443 # Branch-less conditional subtraction
2453 cmovnz $in_ptr, $acc1
2454 mov $acc0, 8*0($r_ptr)
2456 mov $acc1, 8*1($r_ptr)
2458 mov $acc2, 8*2($r_ptr)
2459 mov $acc3, 8*3($r_ptr)
2466 .cfi_adjust_cfa_offset -16
2470 .size ecp_nistz256_from_mont,.-ecp_nistz256_from_mont
2474 my ($val,$in_t,$index)=$win64?("%rcx","%rdx","%r8d"):("%rdi","%rsi","%edx");
2475 my ($ONE,$INDEX,$Ra,$Rb,$Rc,$Rd,$Re,$Rf)=map("%xmm$_",(0..7));
2476 my ($M0,$T0a,$T0b,$T0c,$T0d,$T0e,$T0f,$TMP0)=map("%xmm$_",(8..15));
2477 my ($M1,$T2a,$T2b,$TMP2,$M2,$T2a,$T2b,$TMP2)=map("%xmm$_",(8..15));
2480 ################################################################################
2481 # void ecp_nistz256_scatter_w5(uint64_t *val, uint64_t *in_t, int index);
2482 .globl ecp_nistz256_scatter_w5
2483 .type ecp_nistz256_scatter_w5,\@abi-omnipotent
2485 ecp_nistz256_scatter_w5:
2486 lea -3($index,$index,2), $index
2487 movdqa 0x00($in_t), %xmm0
2489 movdqa 0x10($in_t), %xmm1
2490 movdqa 0x20($in_t), %xmm2
2491 movdqa 0x30($in_t), %xmm3
2492 movdqa 0x40($in_t), %xmm4
2493 movdqa 0x50($in_t), %xmm5
2494 movdqa %xmm0, 0x00($val,$index)
2495 movdqa %xmm1, 0x10($val,$index)
2496 movdqa %xmm2, 0x20($val,$index)
2497 movdqa %xmm3, 0x30($val,$index)
2498 movdqa %xmm4, 0x40($val,$index)
2499 movdqa %xmm5, 0x50($val,$index)
2502 .size ecp_nistz256_scatter_w5,.-ecp_nistz256_scatter_w5
2504 ################################################################################
2505 # void ecp_nistz256_gather_w5(uint64_t *val, uint64_t *in_t, int index);
2506 .globl ecp_nistz256_gather_w5
2507 .type ecp_nistz256_gather_w5,\@abi-omnipotent
2509 ecp_nistz256_gather_w5:
2511 $code.=<<___ if ($avx>1);
2512 mov OPENSSL_ia32cap_P+8(%rip), %eax
2514 jnz .Lavx2_gather_w5
2516 $code.=<<___ if ($win64);
2517 lea -0x88(%rsp), %rax
2518 .LSEH_begin_ecp_nistz256_gather_w5:
2519 .byte 0x48,0x8d,0x60,0xe0 #lea -0x20(%rax), %rsp
2520 .byte 0x0f,0x29,0x70,0xe0 #movaps %xmm6, -0x20(%rax)
2521 .byte 0x0f,0x29,0x78,0xf0 #movaps %xmm7, -0x10(%rax)
2522 .byte 0x44,0x0f,0x29,0x00 #movaps %xmm8, 0(%rax)
2523 .byte 0x44,0x0f,0x29,0x48,0x10 #movaps %xmm9, 0x10(%rax)
2524 .byte 0x44,0x0f,0x29,0x50,0x20 #movaps %xmm10, 0x20(%rax)
2525 .byte 0x44,0x0f,0x29,0x58,0x30 #movaps %xmm11, 0x30(%rax)
2526 .byte 0x44,0x0f,0x29,0x60,0x40 #movaps %xmm12, 0x40(%rax)
2527 .byte 0x44,0x0f,0x29,0x68,0x50 #movaps %xmm13, 0x50(%rax)
2528 .byte 0x44,0x0f,0x29,0x70,0x60 #movaps %xmm14, 0x60(%rax)
2529 .byte 0x44,0x0f,0x29,0x78,0x70 #movaps %xmm15, 0x70(%rax)
2532 movdqa .LOne(%rip), $ONE
2543 pshufd \$0, $INDEX, $INDEX
2546 .Lselect_loop_sse_w5:
2550 pcmpeqd $INDEX, $TMP0
2552 movdqa 16*0($in_t), $T0a
2553 movdqa 16*1($in_t), $T0b
2554 movdqa 16*2($in_t), $T0c
2555 movdqa 16*3($in_t), $T0d
2556 movdqa 16*4($in_t), $T0e
2557 movdqa 16*5($in_t), $T0f
2558 lea 16*6($in_t), $in_t
2574 jnz .Lselect_loop_sse_w5
2576 movdqu $Ra, 16*0($val)
2577 movdqu $Rb, 16*1($val)
2578 movdqu $Rc, 16*2($val)
2579 movdqu $Rd, 16*3($val)
2580 movdqu $Re, 16*4($val)
2581 movdqu $Rf, 16*5($val)
2583 $code.=<<___ if ($win64);
2584 movaps (%rsp), %xmm6
2585 movaps 0x10(%rsp), %xmm7
2586 movaps 0x20(%rsp), %xmm8
2587 movaps 0x30(%rsp), %xmm9
2588 movaps 0x40(%rsp), %xmm10
2589 movaps 0x50(%rsp), %xmm11
2590 movaps 0x60(%rsp), %xmm12
2591 movaps 0x70(%rsp), %xmm13
2592 movaps 0x80(%rsp), %xmm14
2593 movaps 0x90(%rsp), %xmm15
2594 lea 0xa8(%rsp), %rsp
2598 .LSEH_end_ecp_nistz256_gather_w5:
2599 .size ecp_nistz256_gather_w5,.-ecp_nistz256_gather_w5
2601 ################################################################################
2602 # void ecp_nistz256_scatter_w7(uint64_t *val, uint64_t *in_t, int index);
2603 .globl ecp_nistz256_scatter_w7
2604 .type ecp_nistz256_scatter_w7,\@abi-omnipotent
2606 ecp_nistz256_scatter_w7:
2607 movdqu 0x00($in_t), %xmm0
2609 movdqu 0x10($in_t), %xmm1
2610 movdqu 0x20($in_t), %xmm2
2611 movdqu 0x30($in_t), %xmm3
2612 movdqa %xmm0, 0x00($val,$index)
2613 movdqa %xmm1, 0x10($val,$index)
2614 movdqa %xmm2, 0x20($val,$index)
2615 movdqa %xmm3, 0x30($val,$index)
2618 .size ecp_nistz256_scatter_w7,.-ecp_nistz256_scatter_w7
2620 ################################################################################
2621 # void ecp_nistz256_gather_w7(uint64_t *val, uint64_t *in_t, int index);
2622 .globl ecp_nistz256_gather_w7
2623 .type ecp_nistz256_gather_w7,\@abi-omnipotent
2625 ecp_nistz256_gather_w7:
2627 $code.=<<___ if ($avx>1);
2628 mov OPENSSL_ia32cap_P+8(%rip), %eax
2630 jnz .Lavx2_gather_w7
2632 $code.=<<___ if ($win64);
2633 lea -0x88(%rsp), %rax
2634 .LSEH_begin_ecp_nistz256_gather_w7:
2635 .byte 0x48,0x8d,0x60,0xe0 #lea -0x20(%rax), %rsp
2636 .byte 0x0f,0x29,0x70,0xe0 #movaps %xmm6, -0x20(%rax)
2637 .byte 0x0f,0x29,0x78,0xf0 #movaps %xmm7, -0x10(%rax)
2638 .byte 0x44,0x0f,0x29,0x00 #movaps %xmm8, 0(%rax)
2639 .byte 0x44,0x0f,0x29,0x48,0x10 #movaps %xmm9, 0x10(%rax)
2640 .byte 0x44,0x0f,0x29,0x50,0x20 #movaps %xmm10, 0x20(%rax)
2641 .byte 0x44,0x0f,0x29,0x58,0x30 #movaps %xmm11, 0x30(%rax)
2642 .byte 0x44,0x0f,0x29,0x60,0x40 #movaps %xmm12, 0x40(%rax)
2643 .byte 0x44,0x0f,0x29,0x68,0x50 #movaps %xmm13, 0x50(%rax)
2644 .byte 0x44,0x0f,0x29,0x70,0x60 #movaps %xmm14, 0x60(%rax)
2645 .byte 0x44,0x0f,0x29,0x78,0x70 #movaps %xmm15, 0x70(%rax)
2648 movdqa .LOne(%rip), $M0
2657 pshufd \$0, $INDEX, $INDEX
2660 .Lselect_loop_sse_w7:
2663 movdqa 16*0($in_t), $T0a
2664 movdqa 16*1($in_t), $T0b
2665 pcmpeqd $INDEX, $TMP0
2666 movdqa 16*2($in_t), $T0c
2667 movdqa 16*3($in_t), $T0d
2668 lea 16*4($in_t), $in_t
2677 prefetcht0 255($in_t)
2681 jnz .Lselect_loop_sse_w7
2683 movdqu $Ra, 16*0($val)
2684 movdqu $Rb, 16*1($val)
2685 movdqu $Rc, 16*2($val)
2686 movdqu $Rd, 16*3($val)
2688 $code.=<<___ if ($win64);
2689 movaps (%rsp), %xmm6
2690 movaps 0x10(%rsp), %xmm7
2691 movaps 0x20(%rsp), %xmm8
2692 movaps 0x30(%rsp), %xmm9
2693 movaps 0x40(%rsp), %xmm10
2694 movaps 0x50(%rsp), %xmm11
2695 movaps 0x60(%rsp), %xmm12
2696 movaps 0x70(%rsp), %xmm13
2697 movaps 0x80(%rsp), %xmm14
2698 movaps 0x90(%rsp), %xmm15
2699 lea 0xa8(%rsp), %rsp
2703 .LSEH_end_ecp_nistz256_gather_w7:
2704 .size ecp_nistz256_gather_w7,.-ecp_nistz256_gather_w7
2708 my ($val,$in_t,$index)=$win64?("%rcx","%rdx","%r8d"):("%rdi","%rsi","%edx");
2709 my ($TWO,$INDEX,$Ra,$Rb,$Rc)=map("%ymm$_",(0..4));
2710 my ($M0,$T0a,$T0b,$T0c,$TMP0)=map("%ymm$_",(5..9));
2711 my ($M1,$T1a,$T1b,$T1c,$TMP1)=map("%ymm$_",(10..14));
2714 ################################################################################
2715 # void ecp_nistz256_avx2_gather_w5(uint64_t *val, uint64_t *in_t, int index);
2716 .type ecp_nistz256_avx2_gather_w5,\@abi-omnipotent
2718 ecp_nistz256_avx2_gather_w5:
2722 $code.=<<___ if ($win64);
2723 lea -0x88(%rsp), %rax
2725 .LSEH_begin_ecp_nistz256_avx2_gather_w5:
2726 .byte 0x48,0x8d,0x60,0xe0 # lea -0x20(%rax), %rsp
2727 .byte 0xc5,0xf8,0x29,0x70,0xe0 # vmovaps %xmm6, -0x20(%rax)
2728 .byte 0xc5,0xf8,0x29,0x78,0xf0 # vmovaps %xmm7, -0x10(%rax)
2729 .byte 0xc5,0x78,0x29,0x40,0x00 # vmovaps %xmm8, 8(%rax)
2730 .byte 0xc5,0x78,0x29,0x48,0x10 # vmovaps %xmm9, 0x10(%rax)
2731 .byte 0xc5,0x78,0x29,0x50,0x20 # vmovaps %xmm10, 0x20(%rax)
2732 .byte 0xc5,0x78,0x29,0x58,0x30 # vmovaps %xmm11, 0x30(%rax)
2733 .byte 0xc5,0x78,0x29,0x60,0x40 # vmovaps %xmm12, 0x40(%rax)
2734 .byte 0xc5,0x78,0x29,0x68,0x50 # vmovaps %xmm13, 0x50(%rax)
2735 .byte 0xc5,0x78,0x29,0x70,0x60 # vmovaps %xmm14, 0x60(%rax)
2736 .byte 0xc5,0x78,0x29,0x78,0x70 # vmovaps %xmm15, 0x70(%rax)
2739 vmovdqa .LTwo(%rip), $TWO
2745 vmovdqa .LOne(%rip), $M0
2746 vmovdqa .LTwo(%rip), $M1
2749 vpermd $INDEX, $Ra, $INDEX
2752 .Lselect_loop_avx2_w5:
2754 vmovdqa 32*0($in_t), $T0a
2755 vmovdqa 32*1($in_t), $T0b
2756 vmovdqa 32*2($in_t), $T0c
2758 vmovdqa 32*3($in_t), $T1a
2759 vmovdqa 32*4($in_t), $T1b
2760 vmovdqa 32*5($in_t), $T1c
2762 vpcmpeqd $INDEX, $M0, $TMP0
2763 vpcmpeqd $INDEX, $M1, $TMP1
2765 vpaddd $TWO, $M0, $M0
2766 vpaddd $TWO, $M1, $M1
2767 lea 32*6($in_t), $in_t
2769 vpand $TMP0, $T0a, $T0a
2770 vpand $TMP0, $T0b, $T0b
2771 vpand $TMP0, $T0c, $T0c
2772 vpand $TMP1, $T1a, $T1a
2773 vpand $TMP1, $T1b, $T1b
2774 vpand $TMP1, $T1c, $T1c
2776 vpxor $T0a, $Ra, $Ra
2777 vpxor $T0b, $Rb, $Rb
2778 vpxor $T0c, $Rc, $Rc
2779 vpxor $T1a, $Ra, $Ra
2780 vpxor $T1b, $Rb, $Rb
2781 vpxor $T1c, $Rc, $Rc
2784 jnz .Lselect_loop_avx2_w5
2786 vmovdqu $Ra, 32*0($val)
2787 vmovdqu $Rb, 32*1($val)
2788 vmovdqu $Rc, 32*2($val)
2791 $code.=<<___ if ($win64);
2792 movaps (%rsp), %xmm6
2793 movaps 0x10(%rsp), %xmm7
2794 movaps 0x20(%rsp), %xmm8
2795 movaps 0x30(%rsp), %xmm9
2796 movaps 0x40(%rsp), %xmm10
2797 movaps 0x50(%rsp), %xmm11
2798 movaps 0x60(%rsp), %xmm12
2799 movaps 0x70(%rsp), %xmm13
2800 movaps 0x80(%rsp), %xmm14
2801 movaps 0x90(%rsp), %xmm15
2806 .LSEH_end_ecp_nistz256_avx2_gather_w5:
2807 .size ecp_nistz256_avx2_gather_w5,.-ecp_nistz256_avx2_gather_w5
2811 my ($val,$in_t,$index)=$win64?("%rcx","%rdx","%r8d"):("%rdi","%rsi","%edx");
2812 my ($THREE,$INDEX,$Ra,$Rb)=map("%ymm$_",(0..3));
2813 my ($M0,$T0a,$T0b,$TMP0)=map("%ymm$_",(4..7));
2814 my ($M1,$T1a,$T1b,$TMP1)=map("%ymm$_",(8..11));
2815 my ($M2,$T2a,$T2b,$TMP2)=map("%ymm$_",(12..15));
2819 ################################################################################
2820 # void ecp_nistz256_avx2_gather_w7(uint64_t *val, uint64_t *in_t, int index);
2821 .globl ecp_nistz256_avx2_gather_w7
2822 .type ecp_nistz256_avx2_gather_w7,\@abi-omnipotent
2824 ecp_nistz256_avx2_gather_w7:
2828 $code.=<<___ if ($win64);
2830 lea -0x88(%rsp), %rax
2831 .LSEH_begin_ecp_nistz256_avx2_gather_w7:
2832 .byte 0x48,0x8d,0x60,0xe0 # lea -0x20(%rax), %rsp
2833 .byte 0xc5,0xf8,0x29,0x70,0xe0 # vmovaps %xmm6, -0x20(%rax)
2834 .byte 0xc5,0xf8,0x29,0x78,0xf0 # vmovaps %xmm7, -0x10(%rax)
2835 .byte 0xc5,0x78,0x29,0x40,0x00 # vmovaps %xmm8, 8(%rax)
2836 .byte 0xc5,0x78,0x29,0x48,0x10 # vmovaps %xmm9, 0x10(%rax)
2837 .byte 0xc5,0x78,0x29,0x50,0x20 # vmovaps %xmm10, 0x20(%rax)
2838 .byte 0xc5,0x78,0x29,0x58,0x30 # vmovaps %xmm11, 0x30(%rax)
2839 .byte 0xc5,0x78,0x29,0x60,0x40 # vmovaps %xmm12, 0x40(%rax)
2840 .byte 0xc5,0x78,0x29,0x68,0x50 # vmovaps %xmm13, 0x50(%rax)
2841 .byte 0xc5,0x78,0x29,0x70,0x60 # vmovaps %xmm14, 0x60(%rax)
2842 .byte 0xc5,0x78,0x29,0x78,0x70 # vmovaps %xmm15, 0x70(%rax)
2845 vmovdqa .LThree(%rip), $THREE
2850 vmovdqa .LOne(%rip), $M0
2851 vmovdqa .LTwo(%rip), $M1
2852 vmovdqa .LThree(%rip), $M2
2855 vpermd $INDEX, $Ra, $INDEX
2856 # Skip index = 0, because it is implicitly the point at infinity
2859 .Lselect_loop_avx2_w7:
2861 vmovdqa 32*0($in_t), $T0a
2862 vmovdqa 32*1($in_t), $T0b
2864 vmovdqa 32*2($in_t), $T1a
2865 vmovdqa 32*3($in_t), $T1b
2867 vmovdqa 32*4($in_t), $T2a
2868 vmovdqa 32*5($in_t), $T2b
2870 vpcmpeqd $INDEX, $M0, $TMP0
2871 vpcmpeqd $INDEX, $M1, $TMP1
2872 vpcmpeqd $INDEX, $M2, $TMP2
2874 vpaddd $THREE, $M0, $M0
2875 vpaddd $THREE, $M1, $M1
2876 vpaddd $THREE, $M2, $M2
2877 lea 32*6($in_t), $in_t
2879 vpand $TMP0, $T0a, $T0a
2880 vpand $TMP0, $T0b, $T0b
2881 vpand $TMP1, $T1a, $T1a
2882 vpand $TMP1, $T1b, $T1b
2883 vpand $TMP2, $T2a, $T2a
2884 vpand $TMP2, $T2b, $T2b
2886 vpxor $T0a, $Ra, $Ra
2887 vpxor $T0b, $Rb, $Rb
2888 vpxor $T1a, $Ra, $Ra
2889 vpxor $T1b, $Rb, $Rb
2890 vpxor $T2a, $Ra, $Ra
2891 vpxor $T2b, $Rb, $Rb
2894 jnz .Lselect_loop_avx2_w7
2897 vmovdqa 32*0($in_t), $T0a
2898 vmovdqa 32*1($in_t), $T0b
2900 vpcmpeqd $INDEX, $M0, $TMP0
2902 vpand $TMP0, $T0a, $T0a
2903 vpand $TMP0, $T0b, $T0b
2905 vpxor $T0a, $Ra, $Ra
2906 vpxor $T0b, $Rb, $Rb
2908 vmovdqu $Ra, 32*0($val)
2909 vmovdqu $Rb, 32*1($val)
2912 $code.=<<___ if ($win64);
2913 movaps (%rsp), %xmm6
2914 movaps 0x10(%rsp), %xmm7
2915 movaps 0x20(%rsp), %xmm8
2916 movaps 0x30(%rsp), %xmm9
2917 movaps 0x40(%rsp), %xmm10
2918 movaps 0x50(%rsp), %xmm11
2919 movaps 0x60(%rsp), %xmm12
2920 movaps 0x70(%rsp), %xmm13
2921 movaps 0x80(%rsp), %xmm14
2922 movaps 0x90(%rsp), %xmm15
2927 .LSEH_end_ecp_nistz256_avx2_gather_w7:
2928 .size ecp_nistz256_avx2_gather_w7,.-ecp_nistz256_avx2_gather_w7
2932 .globl ecp_nistz256_avx2_gather_w7
2933 .type ecp_nistz256_avx2_gather_w7,\@function,3
2935 ecp_nistz256_avx2_gather_w7:
2936 .byte 0x0f,0x0b # ud2
2938 .size ecp_nistz256_avx2_gather_w7,.-ecp_nistz256_avx2_gather_w7
2942 ########################################################################
2943 # This block implements higher level point_double, point_add and
2944 # point_add_affine. The key to performance in this case is to allow
2945 # out-of-order execution logic to overlap computations from next step
2946 # with tail processing from current step. By using tailored calling
2947 # sequence we minimize inter-step overhead to give processor better
2948 # shot at overlapping operations...
2950 # You will notice that input data is copied to stack. Trouble is that
2951 # there are no registers to spare for holding original pointers and
2952 # reloading them, pointers, would create undesired dependencies on
2953 # effective addresses calculation paths. In other words it's too done
2954 # to favour out-of-order execution logic.
2955 # <appro@openssl.org>
2957 my ($r_ptr,$a_ptr,$b_org,$b_ptr)=("%rdi","%rsi","%rdx","%rbx");
2958 my ($acc0,$acc1,$acc2,$acc3,$acc4,$acc5,$acc6,$acc7)=map("%r$_",(8..15));
2959 my ($t0,$t1,$t2,$t3,$t4)=("%rax","%rbp","%rcx",$acc4,$acc4);
2960 my ($poly1,$poly3)=($acc6,$acc7);
2962 sub load_for_mul () {
2963 my ($a,$b,$src0) = @_;
2964 my $bias = $src0 eq "%rax" ? 0 : -128;
2970 lea $bias+$a, $a_ptr
2975 sub load_for_sqr () {
2977 my $bias = $src0 eq "%rax" ? 0 : -128;
2981 lea $bias+$a, $a_ptr
2987 ########################################################################
2988 # operate in 4-5-0-1 "name space" that matches multiplication output
2990 my ($a0,$a1,$a2,$a3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
2993 .type __ecp_nistz256_add_toq,\@abi-omnipotent
2995 __ecp_nistz256_add_toq:
2997 add 8*0($b_ptr), $a0
2998 adc 8*1($b_ptr), $a1
3000 adc 8*2($b_ptr), $a2
3001 adc 8*3($b_ptr), $a3
3015 mov $a0, 8*0($r_ptr)
3017 mov $a1, 8*1($r_ptr)
3019 mov $a2, 8*2($r_ptr)
3020 mov $a3, 8*3($r_ptr)
3023 .size __ecp_nistz256_add_toq,.-__ecp_nistz256_add_toq
3025 .type __ecp_nistz256_sub_fromq,\@abi-omnipotent
3027 __ecp_nistz256_sub_fromq:
3028 sub 8*0($b_ptr), $a0
3029 sbb 8*1($b_ptr), $a1
3031 sbb 8*2($b_ptr), $a2
3032 sbb 8*3($b_ptr), $a3
3046 mov $a0, 8*0($r_ptr)
3048 mov $a1, 8*1($r_ptr)
3050 mov $a2, 8*2($r_ptr)
3051 mov $a3, 8*3($r_ptr)
3054 .size __ecp_nistz256_sub_fromq,.-__ecp_nistz256_sub_fromq
3056 .type __ecp_nistz256_subq,\@abi-omnipotent
3058 __ecp_nistz256_subq:
3081 .size __ecp_nistz256_subq,.-__ecp_nistz256_subq
3083 .type __ecp_nistz256_mul_by_2q,\@abi-omnipotent
3085 __ecp_nistz256_mul_by_2q:
3087 add $a0, $a0 # a0:a3+a0:a3
3105 mov $a0, 8*0($r_ptr)
3107 mov $a1, 8*1($r_ptr)
3109 mov $a2, 8*2($r_ptr)
3110 mov $a3, 8*3($r_ptr)
3113 .size __ecp_nistz256_mul_by_2q,.-__ecp_nistz256_mul_by_2q
3118 my ($src0,$sfx,$bias);
3119 my ($S,$M,$Zsqr,$in_x,$tmp0)=map(32*$_,(0..4));
3127 .globl ecp_nistz256_point_double
3128 .type ecp_nistz256_point_double,\@function,2
3130 ecp_nistz256_point_double:
3133 $code.=<<___ if ($addx);
3135 and OPENSSL_ia32cap_P+8(%rip), %ecx
3145 .type ecp_nistz256_point_doublex,\@function,2
3147 ecp_nistz256_point_doublex:
3166 .cfi_adjust_cfa_offset 32*5+8
3167 .Lpoint_double${x}_body:
3169 .Lpoint_double_shortcut$x:
3170 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$a_ptr.x
3171 mov $a_ptr, $b_ptr # backup copy
3172 movdqu 0x10($a_ptr), %xmm1
3173 mov 0x20+8*0($a_ptr), $acc4 # load in_y in "5-4-0-1" order
3174 mov 0x20+8*1($a_ptr), $acc5
3175 mov 0x20+8*2($a_ptr), $acc0
3176 mov 0x20+8*3($a_ptr), $acc1
3177 mov .Lpoly+8*1(%rip), $poly1
3178 mov .Lpoly+8*3(%rip), $poly3
3179 movdqa %xmm0, $in_x(%rsp)
3180 movdqa %xmm1, $in_x+0x10(%rsp)
3181 lea 0x20($r_ptr), $acc2
3182 lea 0x40($r_ptr), $acc3
3187 lea $S(%rsp), $r_ptr
3188 call __ecp_nistz256_mul_by_2$x # p256_mul_by_2(S, in_y);
3190 mov 0x40+8*0($a_ptr), $src0
3191 mov 0x40+8*1($a_ptr), $acc6
3192 mov 0x40+8*2($a_ptr), $acc7
3193 mov 0x40+8*3($a_ptr), $acc0
3194 lea 0x40-$bias($a_ptr), $a_ptr
3195 lea $Zsqr(%rsp), $r_ptr
3196 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Zsqr, in_z);
3198 `&load_for_sqr("$S(%rsp)", "$src0")`
3199 lea $S(%rsp), $r_ptr
3200 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(S, S);
3202 mov 0x20($b_ptr), $src0 # $b_ptr is still valid
3203 mov 0x40+8*0($b_ptr), $acc1
3204 mov 0x40+8*1($b_ptr), $acc2
3205 mov 0x40+8*2($b_ptr), $acc3
3206 mov 0x40+8*3($b_ptr), $acc4
3207 lea 0x40-$bias($b_ptr), $a_ptr
3208 lea 0x20($b_ptr), $b_ptr
3210 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, in_z, in_y);
3211 call __ecp_nistz256_mul_by_2$x # p256_mul_by_2(res_z, res_z);
3213 mov $in_x+8*0(%rsp), $acc4 # "5-4-0-1" order
3214 mov $in_x+8*1(%rsp), $acc5
3215 lea $Zsqr(%rsp), $b_ptr
3216 mov $in_x+8*2(%rsp), $acc0
3217 mov $in_x+8*3(%rsp), $acc1
3218 lea $M(%rsp), $r_ptr
3219 call __ecp_nistz256_add_to$x # p256_add(M, in_x, Zsqr);
3221 mov $in_x+8*0(%rsp), $acc4 # "5-4-0-1" order
3222 mov $in_x+8*1(%rsp), $acc5
3223 lea $Zsqr(%rsp), $b_ptr
3224 mov $in_x+8*2(%rsp), $acc0
3225 mov $in_x+8*3(%rsp), $acc1
3226 lea $Zsqr(%rsp), $r_ptr
3227 call __ecp_nistz256_sub_from$x # p256_sub(Zsqr, in_x, Zsqr);
3229 `&load_for_sqr("$S(%rsp)", "$src0")`
3231 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(res_y, S);
3234 ######## ecp_nistz256_div_by_2(res_y, res_y); ##########################
3235 # operate in 4-5-6-7 "name space" that matches squaring output
3237 my ($poly1,$poly3)=($a_ptr,$t1);
3238 my ($a0,$a1,$a2,$a3,$t3,$t4,$t1)=($acc4,$acc5,$acc6,$acc7,$acc0,$acc1,$acc2);
3251 xor $a_ptr, $a_ptr # borrow $a_ptr
3260 mov $a1, $t0 # a0:a3>>1
3271 mov $a0, 8*0($r_ptr)
3273 mov $a1, 8*1($r_ptr)
3277 mov $a2, 8*2($r_ptr)
3278 mov $a3, 8*3($r_ptr)
3282 `&load_for_mul("$M(%rsp)", "$Zsqr(%rsp)", "$src0")`
3283 lea $M(%rsp), $r_ptr
3284 call __ecp_nistz256_mul_mont$x # p256_mul_mont(M, M, Zsqr);
3286 lea $tmp0(%rsp), $r_ptr
3287 call __ecp_nistz256_mul_by_2$x
3289 lea $M(%rsp), $b_ptr
3290 lea $M(%rsp), $r_ptr
3291 call __ecp_nistz256_add_to$x # p256_mul_by_3(M, M);
3293 `&load_for_mul("$S(%rsp)", "$in_x(%rsp)", "$src0")`
3294 lea $S(%rsp), $r_ptr
3295 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S, S, in_x);
3297 lea $tmp0(%rsp), $r_ptr
3298 call __ecp_nistz256_mul_by_2$x # p256_mul_by_2(tmp0, S);
3300 `&load_for_sqr("$M(%rsp)", "$src0")`
3302 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(res_x, M);
3304 lea $tmp0(%rsp), $b_ptr
3305 mov $acc6, $acc0 # harmonize sqr output and sub input
3309 call __ecp_nistz256_sub_from$x # p256_sub(res_x, res_x, tmp0);
3311 mov $S+8*0(%rsp), $t0
3312 mov $S+8*1(%rsp), $t1
3313 mov $S+8*2(%rsp), $t2
3314 mov $S+8*3(%rsp), $acc2 # "4-5-0-1" order
3315 lea $S(%rsp), $r_ptr
3316 call __ecp_nistz256_sub$x # p256_sub(S, S, res_x);
3319 lea $M(%rsp), $b_ptr
3320 mov $acc4, $acc6 # harmonize sub output and mul input
3322 mov $acc4, $S+8*0(%rsp) # have to save:-(
3324 mov $acc5, $S+8*1(%rsp)
3326 mov $acc0, $S+8*2(%rsp)
3327 lea $S-$bias(%rsp), $a_ptr
3329 mov $acc1, $S+8*3(%rsp)
3331 lea $S(%rsp), $r_ptr
3332 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S, S, M);
3336 call __ecp_nistz256_sub_from$x # p256_sub(res_y, S, res_y);
3338 lea 32*5+56(%rsp), %rsi
3353 .cfi_def_cfa_register %rsp
3354 .Lpoint_double${x}_epilogue:
3357 .size ecp_nistz256_point_double$sfx,.-ecp_nistz256_point_double$sfx
3364 my ($src0,$sfx,$bias);
3365 my ($H,$Hsqr,$R,$Rsqr,$Hcub,
3367 $res_x,$res_y,$res_z,
3368 $in1_x,$in1_y,$in1_z,
3369 $in2_x,$in2_y,$in2_z)=map(32*$_,(0..17));
3370 my ($Z1sqr, $Z2sqr) = ($Hsqr, $Rsqr);
3378 .globl ecp_nistz256_point_add
3379 .type ecp_nistz256_point_add,\@function,3
3381 ecp_nistz256_point_add:
3384 $code.=<<___ if ($addx);
3386 and OPENSSL_ia32cap_P+8(%rip), %ecx
3396 .type ecp_nistz256_point_addx,\@function,3
3398 ecp_nistz256_point_addx:
3417 .cfi_adjust_cfa_offset 32*18+8
3418 .Lpoint_add${x}_body:
3420 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$a_ptr
3421 movdqu 0x10($a_ptr), %xmm1
3422 movdqu 0x20($a_ptr), %xmm2
3423 movdqu 0x30($a_ptr), %xmm3
3424 movdqu 0x40($a_ptr), %xmm4
3425 movdqu 0x50($a_ptr), %xmm5
3426 mov $a_ptr, $b_ptr # reassign
3427 mov $b_org, $a_ptr # reassign
3428 movdqa %xmm0, $in1_x(%rsp)
3429 movdqa %xmm1, $in1_x+0x10(%rsp)
3430 movdqa %xmm2, $in1_y(%rsp)
3431 movdqa %xmm3, $in1_y+0x10(%rsp)
3432 movdqa %xmm4, $in1_z(%rsp)
3433 movdqa %xmm5, $in1_z+0x10(%rsp)
3436 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$b_ptr
3437 pshufd \$0xb1, %xmm5, %xmm3
3438 movdqu 0x10($a_ptr), %xmm1
3439 movdqu 0x20($a_ptr), %xmm2
3441 movdqu 0x30($a_ptr), %xmm3
3442 mov 0x40+8*0($a_ptr), $src0 # load original in2_z
3443 mov 0x40+8*1($a_ptr), $acc6
3444 mov 0x40+8*2($a_ptr), $acc7
3445 mov 0x40+8*3($a_ptr), $acc0
3446 movdqa %xmm0, $in2_x(%rsp)
3447 pshufd \$0x1e, %xmm5, %xmm4
3448 movdqa %xmm1, $in2_x+0x10(%rsp)
3449 movdqu 0x40($a_ptr),%xmm0 # in2_z again
3450 movdqu 0x50($a_ptr),%xmm1
3451 movdqa %xmm2, $in2_y(%rsp)
3452 movdqa %xmm3, $in2_y+0x10(%rsp)
3456 movq $r_ptr, %xmm0 # save $r_ptr
3458 lea 0x40-$bias($a_ptr), $a_ptr # $a_ptr is still valid
3459 mov $src0, $in2_z+8*0(%rsp) # make in2_z copy
3460 mov $acc6, $in2_z+8*1(%rsp)
3461 mov $acc7, $in2_z+8*2(%rsp)
3462 mov $acc0, $in2_z+8*3(%rsp)
3463 lea $Z2sqr(%rsp), $r_ptr # Z2^2
3464 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Z2sqr, in2_z);
3466 pcmpeqd %xmm4, %xmm5
3467 pshufd \$0xb1, %xmm1, %xmm4
3469 pshufd \$0, %xmm5, %xmm5 # in1infty
3470 pshufd \$0x1e, %xmm4, %xmm3
3473 pcmpeqd %xmm3, %xmm4
3474 pshufd \$0, %xmm4, %xmm4 # in2infty
3475 mov 0x40+8*0($b_ptr), $src0 # load original in1_z
3476 mov 0x40+8*1($b_ptr), $acc6
3477 mov 0x40+8*2($b_ptr), $acc7
3478 mov 0x40+8*3($b_ptr), $acc0
3481 lea 0x40-$bias($b_ptr), $a_ptr
3482 lea $Z1sqr(%rsp), $r_ptr # Z1^2
3483 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Z1sqr, in1_z);
3485 `&load_for_mul("$Z2sqr(%rsp)", "$in2_z(%rsp)", "$src0")`
3486 lea $S1(%rsp), $r_ptr # S1 = Z2^3
3487 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S1, Z2sqr, in2_z);
3489 `&load_for_mul("$Z1sqr(%rsp)", "$in1_z(%rsp)", "$src0")`
3490 lea $S2(%rsp), $r_ptr # S2 = Z1^3
3491 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, Z1sqr, in1_z);
3493 `&load_for_mul("$S1(%rsp)", "$in1_y(%rsp)", "$src0")`
3494 lea $S1(%rsp), $r_ptr # S1 = Y1*Z2^3
3495 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S1, S1, in1_y);
3497 `&load_for_mul("$S2(%rsp)", "$in2_y(%rsp)", "$src0")`
3498 lea $S2(%rsp), $r_ptr # S2 = Y2*Z1^3
3499 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, S2, in2_y);
3501 lea $S1(%rsp), $b_ptr
3502 lea $R(%rsp), $r_ptr # R = S2 - S1
3503 call __ecp_nistz256_sub_from$x # p256_sub(R, S2, S1);
3505 or $acc5, $acc4 # see if result is zero
3509 por %xmm5, %xmm2 # in1infty || in2infty
3512 `&load_for_mul("$Z2sqr(%rsp)", "$in1_x(%rsp)", "$src0")`
3513 lea $U1(%rsp), $r_ptr # U1 = X1*Z2^2
3514 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U1, in1_x, Z2sqr);
3516 `&load_for_mul("$Z1sqr(%rsp)", "$in2_x(%rsp)", "$src0")`
3517 lea $U2(%rsp), $r_ptr # U2 = X2*Z1^2
3518 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, in2_x, Z1sqr);
3520 lea $U1(%rsp), $b_ptr
3521 lea $H(%rsp), $r_ptr # H = U2 - U1
3522 call __ecp_nistz256_sub_from$x # p256_sub(H, U2, U1);
3524 or $acc5, $acc4 # see if result is zero
3528 .byte 0x3e # predict taken
3529 jnz .Ladd_proceed$x # is_equal(U1,U2)?
3533 jnz .Ladd_proceed$x # (in1infty || in2infty)?
3535 jz .Ladd_double$x # is_equal(S1,S2)?
3537 movq %xmm0, $r_ptr # restore $r_ptr
3539 movdqu %xmm0, 0x00($r_ptr)
3540 movdqu %xmm0, 0x10($r_ptr)
3541 movdqu %xmm0, 0x20($r_ptr)
3542 movdqu %xmm0, 0x30($r_ptr)
3543 movdqu %xmm0, 0x40($r_ptr)
3544 movdqu %xmm0, 0x50($r_ptr)
3549 movq %xmm1, $a_ptr # restore $a_ptr
3550 movq %xmm0, $r_ptr # restore $r_ptr
3551 add \$`32*(18-5)`, %rsp # difference in frame sizes
3552 jmp .Lpoint_double_shortcut$x
3556 `&load_for_sqr("$R(%rsp)", "$src0")`
3557 lea $Rsqr(%rsp), $r_ptr # R^2
3558 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Rsqr, R);
3560 `&load_for_mul("$H(%rsp)", "$in1_z(%rsp)", "$src0")`
3561 lea $res_z(%rsp), $r_ptr # Z3 = H*Z1*Z2
3562 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, H, in1_z);
3564 `&load_for_sqr("$H(%rsp)", "$src0")`
3565 lea $Hsqr(%rsp), $r_ptr # H^2
3566 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Hsqr, H);
3568 `&load_for_mul("$res_z(%rsp)", "$in2_z(%rsp)", "$src0")`
3569 lea $res_z(%rsp), $r_ptr # Z3 = H*Z1*Z2
3570 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, res_z, in2_z);
3572 `&load_for_mul("$Hsqr(%rsp)", "$H(%rsp)", "$src0")`
3573 lea $Hcub(%rsp), $r_ptr # H^3
3574 call __ecp_nistz256_mul_mont$x # p256_mul_mont(Hcub, Hsqr, H);
3576 `&load_for_mul("$Hsqr(%rsp)", "$U1(%rsp)", "$src0")`
3577 lea $U2(%rsp), $r_ptr # U1*H^2
3578 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, U1, Hsqr);
3581 #######################################################################
3582 # operate in 4-5-0-1 "name space" that matches multiplication output
3584 my ($acc0,$acc1,$acc2,$acc3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
3585 my ($poly1, $poly3)=($acc6,$acc7);
3588 #lea $U2(%rsp), $a_ptr
3589 #lea $Hsqr(%rsp), $r_ptr # 2*U1*H^2
3590 #call __ecp_nistz256_mul_by_2 # ecp_nistz256_mul_by_2(Hsqr, U2);
3593 add $acc0, $acc0 # a0:a3+a0:a3
3594 lea $Rsqr(%rsp), $a_ptr
3611 mov 8*0($a_ptr), $t0
3613 mov 8*1($a_ptr), $t1
3615 mov 8*2($a_ptr), $t2
3617 mov 8*3($a_ptr), $t3
3619 call __ecp_nistz256_sub$x # p256_sub(res_x, Rsqr, Hsqr);
3621 lea $Hcub(%rsp), $b_ptr
3622 lea $res_x(%rsp), $r_ptr
3623 call __ecp_nistz256_sub_from$x # p256_sub(res_x, res_x, Hcub);
3625 mov $U2+8*0(%rsp), $t0
3626 mov $U2+8*1(%rsp), $t1
3627 mov $U2+8*2(%rsp), $t2
3628 mov $U2+8*3(%rsp), $t3
3629 lea $res_y(%rsp), $r_ptr
3631 call __ecp_nistz256_sub$x # p256_sub(res_y, U2, res_x);
3633 mov $acc0, 8*0($r_ptr) # save the result, as
3634 mov $acc1, 8*1($r_ptr) # __ecp_nistz256_sub doesn't
3635 mov $acc2, 8*2($r_ptr)
3636 mov $acc3, 8*3($r_ptr)
3640 `&load_for_mul("$S1(%rsp)", "$Hcub(%rsp)", "$src0")`
3641 lea $S2(%rsp), $r_ptr
3642 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, S1, Hcub);
3644 `&load_for_mul("$R(%rsp)", "$res_y(%rsp)", "$src0")`
3645 lea $res_y(%rsp), $r_ptr
3646 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_y, R, res_y);
3648 lea $S2(%rsp), $b_ptr
3649 lea $res_y(%rsp), $r_ptr
3650 call __ecp_nistz256_sub_from$x # p256_sub(res_y, res_y, S2);
3652 movq %xmm0, $r_ptr # restore $r_ptr
3654 movdqa %xmm5, %xmm0 # copy_conditional(res_z, in2_z, in1infty);
3656 pandn $res_z(%rsp), %xmm0
3658 pandn $res_z+0x10(%rsp), %xmm1
3660 pand $in2_z(%rsp), %xmm2
3661 pand $in2_z+0x10(%rsp), %xmm3
3665 movdqa %xmm4, %xmm0 # copy_conditional(res_z, in1_z, in2infty);
3671 pand $in1_z(%rsp), %xmm2
3672 pand $in1_z+0x10(%rsp), %xmm3
3675 movdqu %xmm2, 0x40($r_ptr)
3676 movdqu %xmm3, 0x50($r_ptr)
3678 movdqa %xmm5, %xmm0 # copy_conditional(res_x, in2_x, in1infty);
3680 pandn $res_x(%rsp), %xmm0
3682 pandn $res_x+0x10(%rsp), %xmm1
3684 pand $in2_x(%rsp), %xmm2
3685 pand $in2_x+0x10(%rsp), %xmm3
3689 movdqa %xmm4, %xmm0 # copy_conditional(res_x, in1_x, in2infty);
3695 pand $in1_x(%rsp), %xmm2
3696 pand $in1_x+0x10(%rsp), %xmm3
3699 movdqu %xmm2, 0x00($r_ptr)
3700 movdqu %xmm3, 0x10($r_ptr)
3702 movdqa %xmm5, %xmm0 # copy_conditional(res_y, in2_y, in1infty);
3704 pandn $res_y(%rsp), %xmm0
3706 pandn $res_y+0x10(%rsp), %xmm1
3708 pand $in2_y(%rsp), %xmm2
3709 pand $in2_y+0x10(%rsp), %xmm3
3713 movdqa %xmm4, %xmm0 # copy_conditional(res_y, in1_y, in2infty);
3719 pand $in1_y(%rsp), %xmm2
3720 pand $in1_y+0x10(%rsp), %xmm3
3723 movdqu %xmm2, 0x20($r_ptr)
3724 movdqu %xmm3, 0x30($r_ptr)
3727 lea 32*18+56(%rsp), %rsi
3742 .cfi_def_cfa_register %rsp
3743 .Lpoint_add${x}_epilogue:
3746 .size ecp_nistz256_point_add$sfx,.-ecp_nistz256_point_add$sfx
3751 sub gen_add_affine () {
3753 my ($src0,$sfx,$bias);
3754 my ($U2,$S2,$H,$R,$Hsqr,$Hcub,$Rsqr,
3755 $res_x,$res_y,$res_z,
3756 $in1_x,$in1_y,$in1_z,
3757 $in2_x,$in2_y)=map(32*$_,(0..14));
3766 .globl ecp_nistz256_point_add_affine
3767 .type ecp_nistz256_point_add_affine,\@function,3
3769 ecp_nistz256_point_add_affine:
3772 $code.=<<___ if ($addx);
3774 and OPENSSL_ia32cap_P+8(%rip), %ecx
3776 je .Lpoint_add_affinex
3784 .type ecp_nistz256_point_add_affinex,\@function,3
3786 ecp_nistz256_point_add_affinex:
3788 .Lpoint_add_affinex:
3805 .cfi_adjust_cfa_offset 32*15+8
3806 .Ladd_affine${x}_body:
3808 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$a_ptr
3809 mov $b_org, $b_ptr # reassign
3810 movdqu 0x10($a_ptr), %xmm1
3811 movdqu 0x20($a_ptr), %xmm2
3812 movdqu 0x30($a_ptr), %xmm3
3813 movdqu 0x40($a_ptr), %xmm4
3814 movdqu 0x50($a_ptr), %xmm5
3815 mov 0x40+8*0($a_ptr), $src0 # load original in1_z
3816 mov 0x40+8*1($a_ptr), $acc6
3817 mov 0x40+8*2($a_ptr), $acc7
3818 mov 0x40+8*3($a_ptr), $acc0
3819 movdqa %xmm0, $in1_x(%rsp)
3820 movdqa %xmm1, $in1_x+0x10(%rsp)
3821 movdqa %xmm2, $in1_y(%rsp)
3822 movdqa %xmm3, $in1_y+0x10(%rsp)
3823 movdqa %xmm4, $in1_z(%rsp)
3824 movdqa %xmm5, $in1_z+0x10(%rsp)
3827 movdqu 0x00($b_ptr), %xmm0 # copy *(P256_POINT_AFFINE *)$b_ptr
3828 pshufd \$0xb1, %xmm5, %xmm3
3829 movdqu 0x10($b_ptr), %xmm1
3830 movdqu 0x20($b_ptr), %xmm2
3832 movdqu 0x30($b_ptr), %xmm3
3833 movdqa %xmm0, $in2_x(%rsp)
3834 pshufd \$0x1e, %xmm5, %xmm4
3835 movdqa %xmm1, $in2_x+0x10(%rsp)
3837 movq $r_ptr, %xmm0 # save $r_ptr
3838 movdqa %xmm2, $in2_y(%rsp)
3839 movdqa %xmm3, $in2_y+0x10(%rsp)
3845 lea 0x40-$bias($a_ptr), $a_ptr # $a_ptr is still valid
3846 lea $Z1sqr(%rsp), $r_ptr # Z1^2
3847 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Z1sqr, in1_z);
3849 pcmpeqd %xmm4, %xmm5
3850 pshufd \$0xb1, %xmm3, %xmm4
3851 mov 0x00($b_ptr), $src0 # $b_ptr is still valid
3852 #lea 0x00($b_ptr), $b_ptr
3853 mov $acc4, $acc1 # harmonize sqr output and mul input
3855 pshufd \$0, %xmm5, %xmm5 # in1infty
3856 pshufd \$0x1e, %xmm4, %xmm3
3861 pcmpeqd %xmm3, %xmm4
3862 pshufd \$0, %xmm4, %xmm4 # in2infty
3864 lea $Z1sqr-$bias(%rsp), $a_ptr
3866 lea $U2(%rsp), $r_ptr # U2 = X2*Z1^2
3867 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, Z1sqr, in2_x);
3869 lea $in1_x(%rsp), $b_ptr
3870 lea $H(%rsp), $r_ptr # H = U2 - U1
3871 call __ecp_nistz256_sub_from$x # p256_sub(H, U2, in1_x);
3873 `&load_for_mul("$Z1sqr(%rsp)", "$in1_z(%rsp)", "$src0")`
3874 lea $S2(%rsp), $r_ptr # S2 = Z1^3
3875 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, Z1sqr, in1_z);
3877 `&load_for_mul("$H(%rsp)", "$in1_z(%rsp)", "$src0")`
3878 lea $res_z(%rsp), $r_ptr # Z3 = H*Z1*Z2
3879 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, H, in1_z);
3881 `&load_for_mul("$S2(%rsp)", "$in2_y(%rsp)", "$src0")`
3882 lea $S2(%rsp), $r_ptr # S2 = Y2*Z1^3
3883 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, S2, in2_y);
3885 lea $in1_y(%rsp), $b_ptr
3886 lea $R(%rsp), $r_ptr # R = S2 - S1
3887 call __ecp_nistz256_sub_from$x # p256_sub(R, S2, in1_y);
3889 `&load_for_sqr("$H(%rsp)", "$src0")`
3890 lea $Hsqr(%rsp), $r_ptr # H^2
3891 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Hsqr, H);
3893 `&load_for_sqr("$R(%rsp)", "$src0")`
3894 lea $Rsqr(%rsp), $r_ptr # R^2
3895 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Rsqr, R);
3897 `&load_for_mul("$H(%rsp)", "$Hsqr(%rsp)", "$src0")`
3898 lea $Hcub(%rsp), $r_ptr # H^3
3899 call __ecp_nistz256_mul_mont$x # p256_mul_mont(Hcub, Hsqr, H);
3901 `&load_for_mul("$Hsqr(%rsp)", "$in1_x(%rsp)", "$src0")`
3902 lea $U2(%rsp), $r_ptr # U1*H^2
3903 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, in1_x, Hsqr);
3906 #######################################################################
3907 # operate in 4-5-0-1 "name space" that matches multiplication output
3909 my ($acc0,$acc1,$acc2,$acc3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
3910 my ($poly1, $poly3)=($acc6,$acc7);
3913 #lea $U2(%rsp), $a_ptr
3914 #lea $Hsqr(%rsp), $r_ptr # 2*U1*H^2
3915 #call __ecp_nistz256_mul_by_2 # ecp_nistz256_mul_by_2(Hsqr, U2);
3918 add $acc0, $acc0 # a0:a3+a0:a3
3919 lea $Rsqr(%rsp), $a_ptr
3936 mov 8*0($a_ptr), $t0
3938 mov 8*1($a_ptr), $t1
3940 mov 8*2($a_ptr), $t2
3942 mov 8*3($a_ptr), $t3
3944 call __ecp_nistz256_sub$x # p256_sub(res_x, Rsqr, Hsqr);
3946 lea $Hcub(%rsp), $b_ptr
3947 lea $res_x(%rsp), $r_ptr
3948 call __ecp_nistz256_sub_from$x # p256_sub(res_x, res_x, Hcub);
3950 mov $U2+8*0(%rsp), $t0
3951 mov $U2+8*1(%rsp), $t1
3952 mov $U2+8*2(%rsp), $t2
3953 mov $U2+8*3(%rsp), $t3
3954 lea $H(%rsp), $r_ptr
3956 call __ecp_nistz256_sub$x # p256_sub(H, U2, res_x);
3958 mov $acc0, 8*0($r_ptr) # save the result, as
3959 mov $acc1, 8*1($r_ptr) # __ecp_nistz256_sub doesn't
3960 mov $acc2, 8*2($r_ptr)
3961 mov $acc3, 8*3($r_ptr)
3965 `&load_for_mul("$Hcub(%rsp)", "$in1_y(%rsp)", "$src0")`
3966 lea $S2(%rsp), $r_ptr
3967 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, Hcub, in1_y);
3969 `&load_for_mul("$H(%rsp)", "$R(%rsp)", "$src0")`
3970 lea $H(%rsp), $r_ptr
3971 call __ecp_nistz256_mul_mont$x # p256_mul_mont(H, H, R);
3973 lea $S2(%rsp), $b_ptr
3974 lea $res_y(%rsp), $r_ptr
3975 call __ecp_nistz256_sub_from$x # p256_sub(res_y, H, S2);
3977 movq %xmm0, $r_ptr # restore $r_ptr
3979 movdqa %xmm5, %xmm0 # copy_conditional(res_z, ONE, in1infty);
3981 pandn $res_z(%rsp), %xmm0
3983 pandn $res_z+0x10(%rsp), %xmm1
3985 pand .LONE_mont(%rip), %xmm2
3986 pand .LONE_mont+0x10(%rip), %xmm3
3990 movdqa %xmm4, %xmm0 # copy_conditional(res_z, in1_z, in2infty);
3996 pand $in1_z(%rsp), %xmm2
3997 pand $in1_z+0x10(%rsp), %xmm3
4000 movdqu %xmm2, 0x40($r_ptr)
4001 movdqu %xmm3, 0x50($r_ptr)
4003 movdqa %xmm5, %xmm0 # copy_conditional(res_x, in2_x, in1infty);
4005 pandn $res_x(%rsp), %xmm0
4007 pandn $res_x+0x10(%rsp), %xmm1
4009 pand $in2_x(%rsp), %xmm2
4010 pand $in2_x+0x10(%rsp), %xmm3
4014 movdqa %xmm4, %xmm0 # copy_conditional(res_x, in1_x, in2infty);
4020 pand $in1_x(%rsp), %xmm2
4021 pand $in1_x+0x10(%rsp), %xmm3
4024 movdqu %xmm2, 0x00($r_ptr)
4025 movdqu %xmm3, 0x10($r_ptr)
4027 movdqa %xmm5, %xmm0 # copy_conditional(res_y, in2_y, in1infty);
4029 pandn $res_y(%rsp), %xmm0
4031 pandn $res_y+0x10(%rsp), %xmm1
4033 pand $in2_y(%rsp), %xmm2
4034 pand $in2_y+0x10(%rsp), %xmm3
4038 movdqa %xmm4, %xmm0 # copy_conditional(res_y, in1_y, in2infty);
4044 pand $in1_y(%rsp), %xmm2
4045 pand $in1_y+0x10(%rsp), %xmm3
4048 movdqu %xmm2, 0x20($r_ptr)
4049 movdqu %xmm3, 0x30($r_ptr)
4051 lea 32*15+56(%rsp), %rsi
4066 .cfi_def_cfa_register %rsp
4067 .Ladd_affine${x}_epilogue:
4070 .size ecp_nistz256_point_add_affine$sfx,.-ecp_nistz256_point_add_affine$sfx
4073 &gen_add_affine("q");
4075 ########################################################################
4079 ########################################################################
4080 # operate in 4-5-0-1 "name space" that matches multiplication output
4082 my ($a0,$a1,$a2,$a3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
4085 .type __ecp_nistz256_add_tox,\@abi-omnipotent
4087 __ecp_nistz256_add_tox:
4089 adc 8*0($b_ptr), $a0
4090 adc 8*1($b_ptr), $a1
4092 adc 8*2($b_ptr), $a2
4093 adc 8*3($b_ptr), $a3
4108 mov $a0, 8*0($r_ptr)
4110 mov $a1, 8*1($r_ptr)
4112 mov $a2, 8*2($r_ptr)
4113 mov $a3, 8*3($r_ptr)
4116 .size __ecp_nistz256_add_tox,.-__ecp_nistz256_add_tox
4118 .type __ecp_nistz256_sub_fromx,\@abi-omnipotent
4120 __ecp_nistz256_sub_fromx:
4122 sbb 8*0($b_ptr), $a0
4123 sbb 8*1($b_ptr), $a1
4125 sbb 8*2($b_ptr), $a2
4126 sbb 8*3($b_ptr), $a3
4141 mov $a0, 8*0($r_ptr)
4143 mov $a1, 8*1($r_ptr)
4145 mov $a2, 8*2($r_ptr)
4146 mov $a3, 8*3($r_ptr)
4149 .size __ecp_nistz256_sub_fromx,.-__ecp_nistz256_sub_fromx
4151 .type __ecp_nistz256_subx,\@abi-omnipotent
4153 __ecp_nistz256_subx:
4178 .size __ecp_nistz256_subx,.-__ecp_nistz256_subx
4180 .type __ecp_nistz256_mul_by_2x,\@abi-omnipotent
4182 __ecp_nistz256_mul_by_2x:
4184 adc $a0, $a0 # a0:a3+a0:a3
4203 mov $a0, 8*0($r_ptr)
4205 mov $a1, 8*1($r_ptr)
4207 mov $a2, 8*2($r_ptr)
4208 mov $a3, 8*3($r_ptr)
4211 .size __ecp_nistz256_mul_by_2x,.-__ecp_nistz256_mul_by_2x
4216 &gen_add_affine("x");
4220 # EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
4221 # CONTEXT *context,DISPATCHER_CONTEXT *disp)
4229 .extern __imp_RtlVirtualUnwind
4231 .type short_handler,\@abi-omnipotent
4245 mov 120($context),%rax # pull context->Rax
4246 mov 248($context),%rbx # pull context->Rip
4248 mov 8($disp),%rsi # disp->ImageBase
4249 mov 56($disp),%r11 # disp->HandlerData
4251 mov 0(%r11),%r10d # HandlerData[0]
4252 lea (%rsi,%r10),%r10 # end of prologue label
4253 cmp %r10,%rbx # context->Rip<end of prologue label
4254 jb .Lcommon_seh_tail
4256 mov 152($context),%rax # pull context->Rsp
4258 mov 4(%r11),%r10d # HandlerData[1]
4259 lea (%rsi,%r10),%r10 # epilogue label
4260 cmp %r10,%rbx # context->Rip>=epilogue label
4261 jae .Lcommon_seh_tail
4267 mov %r12,216($context) # restore context->R12
4268 mov %r13,224($context) # restore context->R13
4270 jmp .Lcommon_seh_tail
4271 .size short_handler,.-short_handler
4273 .type full_handler,\@abi-omnipotent
4287 mov 120($context),%rax # pull context->Rax
4288 mov 248($context),%rbx # pull context->Rip
4290 mov 8($disp),%rsi # disp->ImageBase
4291 mov 56($disp),%r11 # disp->HandlerData
4293 mov 0(%r11),%r10d # HandlerData[0]
4294 lea (%rsi,%r10),%r10 # end of prologue label
4295 cmp %r10,%rbx # context->Rip<end of prologue label
4296 jb .Lcommon_seh_tail
4298 mov 152($context),%rax # pull context->Rsp
4300 mov 4(%r11),%r10d # HandlerData[1]
4301 lea (%rsi,%r10),%r10 # epilogue label
4302 cmp %r10,%rbx # context->Rip>=epilogue label
4303 jae .Lcommon_seh_tail
4305 mov 8(%r11),%r10d # HandlerData[2]
4306 lea (%rax,%r10),%rax
4314 mov %rbx,144($context) # restore context->Rbx
4315 mov %rbp,160($context) # restore context->Rbp
4316 mov %r12,216($context) # restore context->R12
4317 mov %r13,224($context) # restore context->R13
4318 mov %r14,232($context) # restore context->R14
4319 mov %r15,240($context) # restore context->R15
4324 mov %rax,152($context) # restore context->Rsp
4325 mov %rsi,168($context) # restore context->Rsi
4326 mov %rdi,176($context) # restore context->Rdi
4328 mov 40($disp),%rdi # disp->ContextRecord
4329 mov $context,%rsi # context
4330 mov \$154,%ecx # sizeof(CONTEXT)
4331 .long 0xa548f3fc # cld; rep movsq
4334 xor %rcx,%rcx # arg1, UNW_FLAG_NHANDLER
4335 mov 8(%rsi),%rdx # arg2, disp->ImageBase
4336 mov 0(%rsi),%r8 # arg3, disp->ControlPc
4337 mov 16(%rsi),%r9 # arg4, disp->FunctionEntry
4338 mov 40(%rsi),%r10 # disp->ContextRecord
4339 lea 56(%rsi),%r11 # &disp->HandlerData
4340 lea 24(%rsi),%r12 # &disp->EstablisherFrame
4341 mov %r10,32(%rsp) # arg5
4342 mov %r11,40(%rsp) # arg6
4343 mov %r12,48(%rsp) # arg7
4344 mov %rcx,56(%rsp) # arg8, (NULL)
4345 call *__imp_RtlVirtualUnwind(%rip)
4347 mov \$1,%eax # ExceptionContinueSearch
4359 .size full_handler,.-full_handler
4363 .rva .LSEH_begin_ecp_nistz256_mul_by_2
4364 .rva .LSEH_end_ecp_nistz256_mul_by_2
4365 .rva .LSEH_info_ecp_nistz256_mul_by_2
4367 .rva .LSEH_begin_ecp_nistz256_div_by_2
4368 .rva .LSEH_end_ecp_nistz256_div_by_2
4369 .rva .LSEH_info_ecp_nistz256_div_by_2
4371 .rva .LSEH_begin_ecp_nistz256_mul_by_3
4372 .rva .LSEH_end_ecp_nistz256_mul_by_3
4373 .rva .LSEH_info_ecp_nistz256_mul_by_3
4375 .rva .LSEH_begin_ecp_nistz256_add
4376 .rva .LSEH_end_ecp_nistz256_add
4377 .rva .LSEH_info_ecp_nistz256_add
4379 .rva .LSEH_begin_ecp_nistz256_sub
4380 .rva .LSEH_end_ecp_nistz256_sub
4381 .rva .LSEH_info_ecp_nistz256_sub
4383 .rva .LSEH_begin_ecp_nistz256_neg
4384 .rva .LSEH_end_ecp_nistz256_neg
4385 .rva .LSEH_info_ecp_nistz256_neg
4387 .rva .LSEH_begin_ecp_nistz256_to_mont
4388 .rva .LSEH_end_ecp_nistz256_to_mont
4389 .rva .LSEH_info_ecp_nistz256_to_mont
4391 .rva .LSEH_begin_ecp_nistz256_mul_mont
4392 .rva .LSEH_end_ecp_nistz256_mul_mont
4393 .rva .LSEH_info_ecp_nistz256_mul_mont
4395 .rva .LSEH_begin_ecp_nistz256_sqr_mont
4396 .rva .LSEH_end_ecp_nistz256_sqr_mont
4397 .rva .LSEH_info_ecp_nistz256_sqr_mont
4399 .rva .LSEH_begin_ecp_nistz256_from_mont
4400 .rva .LSEH_end_ecp_nistz256_from_mont
4401 .rva .LSEH_info_ecp_nistz256_from_mont
4403 .rva .LSEH_begin_ecp_nistz256_gather_w5
4404 .rva .LSEH_end_ecp_nistz256_gather_w5
4405 .rva .LSEH_info_ecp_nistz256_gather_wX
4407 .rva .LSEH_begin_ecp_nistz256_gather_w7
4408 .rva .LSEH_end_ecp_nistz256_gather_w7
4409 .rva .LSEH_info_ecp_nistz256_gather_wX
4411 $code.=<<___ if ($avx>1);
4412 .rva .LSEH_begin_ecp_nistz256_avx2_gather_w5
4413 .rva .LSEH_end_ecp_nistz256_avx2_gather_w5
4414 .rva .LSEH_info_ecp_nistz256_avx2_gather_wX
4416 .rva .LSEH_begin_ecp_nistz256_avx2_gather_w7
4417 .rva .LSEH_end_ecp_nistz256_avx2_gather_w7
4418 .rva .LSEH_info_ecp_nistz256_avx2_gather_wX
4421 .rva .LSEH_begin_ecp_nistz256_point_double
4422 .rva .LSEH_end_ecp_nistz256_point_double
4423 .rva .LSEH_info_ecp_nistz256_point_double
4425 .rva .LSEH_begin_ecp_nistz256_point_add
4426 .rva .LSEH_end_ecp_nistz256_point_add
4427 .rva .LSEH_info_ecp_nistz256_point_add
4429 .rva .LSEH_begin_ecp_nistz256_point_add_affine
4430 .rva .LSEH_end_ecp_nistz256_point_add_affine
4431 .rva .LSEH_info_ecp_nistz256_point_add_affine
4433 $code.=<<___ if ($addx);
4434 .rva .LSEH_begin_ecp_nistz256_point_doublex
4435 .rva .LSEH_end_ecp_nistz256_point_doublex
4436 .rva .LSEH_info_ecp_nistz256_point_doublex
4438 .rva .LSEH_begin_ecp_nistz256_point_addx
4439 .rva .LSEH_end_ecp_nistz256_point_addx
4440 .rva .LSEH_info_ecp_nistz256_point_addx
4442 .rva .LSEH_begin_ecp_nistz256_point_add_affinex
4443 .rva .LSEH_end_ecp_nistz256_point_add_affinex
4444 .rva .LSEH_info_ecp_nistz256_point_add_affinex
4450 .LSEH_info_ecp_nistz256_mul_by_2:
4453 .rva .Lmul_by_2_body,.Lmul_by_2_epilogue # HandlerData[]
4454 .LSEH_info_ecp_nistz256_div_by_2:
4457 .rva .Ldiv_by_2_body,.Ldiv_by_2_epilogue # HandlerData[]
4458 .LSEH_info_ecp_nistz256_mul_by_3:
4461 .rva .Lmul_by_3_body,.Lmul_by_3_epilogue # HandlerData[]
4462 .LSEH_info_ecp_nistz256_add:
4465 .rva .Ladd_body,.Ladd_epilogue # HandlerData[]
4466 .LSEH_info_ecp_nistz256_sub:
4469 .rva .Lsub_body,.Lsub_epilogue # HandlerData[]
4470 .LSEH_info_ecp_nistz256_neg:
4473 .rva .Lneg_body,.Lneg_epilogue # HandlerData[]
4474 .LSEH_info_ecp_nistz256_to_mont:
4477 .rva .Lmul_body,.Lmul_epilogue # HandlerData[]
4479 .LSEH_info_ecp_nistz256_mul_mont:
4482 .rva .Lmul_body,.Lmul_epilogue # HandlerData[]
4484 .LSEH_info_ecp_nistz256_sqr_mont:
4487 .rva .Lsqr_body,.Lsqr_epilogue # HandlerData[]
4489 .LSEH_info_ecp_nistz256_from_mont:
4492 .rva .Lfrom_body,.Lfrom_epilogue # HandlerData[]
4493 .LSEH_info_ecp_nistz256_gather_wX:
4494 .byte 0x01,0x33,0x16,0x00
4495 .byte 0x33,0xf8,0x09,0x00 #movaps 0x90(rsp),xmm15
4496 .byte 0x2e,0xe8,0x08,0x00 #movaps 0x80(rsp),xmm14
4497 .byte 0x29,0xd8,0x07,0x00 #movaps 0x70(rsp),xmm13
4498 .byte 0x24,0xc8,0x06,0x00 #movaps 0x60(rsp),xmm12
4499 .byte 0x1f,0xb8,0x05,0x00 #movaps 0x50(rsp),xmm11
4500 .byte 0x1a,0xa8,0x04,0x00 #movaps 0x40(rsp),xmm10
4501 .byte 0x15,0x98,0x03,0x00 #movaps 0x30(rsp),xmm9
4502 .byte 0x10,0x88,0x02,0x00 #movaps 0x20(rsp),xmm8
4503 .byte 0x0c,0x78,0x01,0x00 #movaps 0x10(rsp),xmm7
4504 .byte 0x08,0x68,0x00,0x00 #movaps 0x00(rsp),xmm6
4505 .byte 0x04,0x01,0x15,0x00 #sub rsp,0xa8
4508 $code.=<<___ if ($avx>1);
4509 .LSEH_info_ecp_nistz256_avx2_gather_wX:
4510 .byte 0x01,0x36,0x17,0x0b
4511 .byte 0x36,0xf8,0x09,0x00 # vmovaps 0x90(rsp),xmm15
4512 .byte 0x31,0xe8,0x08,0x00 # vmovaps 0x80(rsp),xmm14
4513 .byte 0x2c,0xd8,0x07,0x00 # vmovaps 0x70(rsp),xmm13
4514 .byte 0x27,0xc8,0x06,0x00 # vmovaps 0x60(rsp),xmm12
4515 .byte 0x22,0xb8,0x05,0x00 # vmovaps 0x50(rsp),xmm11
4516 .byte 0x1d,0xa8,0x04,0x00 # vmovaps 0x40(rsp),xmm10
4517 .byte 0x18,0x98,0x03,0x00 # vmovaps 0x30(rsp),xmm9
4518 .byte 0x13,0x88,0x02,0x00 # vmovaps 0x20(rsp),xmm8
4519 .byte 0x0e,0x78,0x01,0x00 # vmovaps 0x10(rsp),xmm7
4520 .byte 0x09,0x68,0x00,0x00 # vmovaps 0x00(rsp),xmm6
4521 .byte 0x04,0x01,0x15,0x00 # sub rsp,0xa8
4522 .byte 0x00,0xb3,0x00,0x00 # set_frame r11
4526 .LSEH_info_ecp_nistz256_point_double:
4529 .rva .Lpoint_doubleq_body,.Lpoint_doubleq_epilogue # HandlerData[]
4531 .LSEH_info_ecp_nistz256_point_add:
4534 .rva .Lpoint_addq_body,.Lpoint_addq_epilogue # HandlerData[]
4536 .LSEH_info_ecp_nistz256_point_add_affine:
4539 .rva .Ladd_affineq_body,.Ladd_affineq_epilogue # HandlerData[]
4542 $code.=<<___ if ($addx);
4544 .LSEH_info_ecp_nistz256_point_doublex:
4547 .rva .Lpoint_doublex_body,.Lpoint_doublex_epilogue # HandlerData[]
4549 .LSEH_info_ecp_nistz256_point_addx:
4552 .rva .Lpoint_addx_body,.Lpoint_addx_epilogue # HandlerData[]
4554 .LSEH_info_ecp_nistz256_point_add_affinex:
4557 .rva .Ladd_affinex_body,.Ladd_affinex_epilogue # HandlerData[]
4562 ########################################################################
4563 # Convert ecp_nistz256_table.c to layout expected by ecp_nistz_gather_w7
4565 open TABLE,"<ecp_nistz256_table.c" or
4566 open TABLE,"<${dir}../ecp_nistz256_table.c" or
4567 die "failed to open ecp_nistz256_table.c:",$!;
4572 s/TOBN\(\s*(0x[0-9a-f]+),\s*(0x[0-9a-f]+)\s*\)/push @arr,hex($2),hex($1)/geo;
4576 die "insane number of elements" if ($#arr != 64*16*37-1);
4580 .globl ecp_nistz256_precomputed
4581 .type ecp_nistz256_precomputed,\@object
4583 ecp_nistz256_precomputed:
4585 while (@line=splice(@arr,0,16)) {
4586 print ".long\t",join(',',map { sprintf "0x%08x",$_} @line),"\n";
4589 .size ecp_nistz256_precomputed,.-ecp_nistz256_precomputed
4592 $code =~ s/\`([^\`]*)\`/eval $1/gem;