2 # Copyright 2014-2019 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:
507 $code.=<<___ if ($addx);
509 and OPENSSL_ia32cap_P+8(%rip), %ecx
511 je .Lecp_nistz256_ord_mul_montx
528 mov 8*0($b_org), %rax
530 lea .Lord(%rip), %r14
531 mov .LordK(%rip), %r15
533 ################################# * b[0]
561 ################################# First reduction step
564 add %rax, $acc5 # guaranteed to be zero
570 sbb \$0, $acc0 # can't borrow
579 adc \$0, $acc0 # can't overflow
584 mov 8*1($b_ptr), %rax
585 sbb %rdx, $t1 # can't borrow
591 ################################# * b[1]
627 ################################# Second reduction step
630 add %rax, $t0 # guaranteed to be zero
635 sbb \$0, $acc1 # can't borrow
644 adc \$0, $acc1 # can't overflow
649 mov 8*2($b_ptr), %rax
650 sbb %rdx, $t1 # can't borrow
656 ################################## * b[2]
692 ################################# Third reduction step
695 add %rax, $t0 # guaranteed to be zero
700 sbb \$0, $acc2 # can't borrow
709 adc \$0, $acc2 # can't overflow
714 mov 8*3($b_ptr), %rax
715 sbb %rdx, $t1 # can't borrow
721 ################################# * b[3]
757 ################################# Last reduction step
760 add %rax, $t0 # guaranteed to be zero
765 sbb \$0, $acc3 # can't borrow
774 adc \$0, $acc3 # can't overflow
779 sbb %rdx, $t1 # can't borrow
785 ################################# Subtract ord
801 mov $acc4, 8*0($r_ptr)
802 mov $acc5, 8*1($r_ptr)
803 mov $acc0, 8*2($r_ptr)
804 mov $acc1, 8*3($r_ptr)
819 .cfi_adjust_cfa_offset -48
823 .size ecp_nistz256_ord_mul_mont,.-ecp_nistz256_ord_mul_mont
825 ################################################################################
826 # void ecp_nistz256_ord_sqr_mont(
831 .globl ecp_nistz256_ord_sqr_mont
832 .type ecp_nistz256_ord_sqr_mont,\@function,3
834 ecp_nistz256_ord_sqr_mont:
837 $code.=<<___ if ($addx);
839 and OPENSSL_ia32cap_P+8(%rip), %ecx
841 je .Lecp_nistz256_ord_sqr_montx
858 mov 8*0($a_ptr), $acc0
859 mov 8*1($a_ptr), %rax
860 mov 8*2($a_ptr), $acc6
861 mov 8*3($a_ptr), $acc7
862 lea .Lord(%rip), $a_ptr # pointer to modulus
868 ################################# a[1:] * a[0]
869 mov %rax, $t1 # put aside a[1]
870 mul $acc0 # a[1] * a[0]
872 movq $t1, %xmm1 # offload a[1]
876 mul $acc0 # a[2] * a[0]
879 movq $acc6, %xmm2 # offload a[2]
883 mul $acc0 # a[3] * a[0]
886 movq $acc7, %xmm3 # offload a[3]
890 ################################# a[3] * a[2]
891 mul $acc6 # a[3] * a[2]
896 ################################# a[2:] * a[1]
897 mul $t1 # a[2] * a[1]
903 mul $t1 # a[3] * a[1]
909 adc \$0, $acc6 # can't overflow
911 ################################# *2
922 ################################# Missing products
923 mul %rax # a[0] * a[0]
928 mul %rax # a[1] * a[1]
935 mul %rax # a[2] * a[2]
943 imulq 8*4($a_ptr), $acc0 # *= .LordK
945 mul %rax # a[3] * a[3]
948 mov 8*0($a_ptr), %rax # modulus[0]
949 adc %rdx, $acc7 # can't overflow
951 ################################# First reduction step
954 add %rax, $t0 # guaranteed to be zero
955 mov 8*1($a_ptr), %rax # modulus[1]
959 sbb \$0, $t1 # can't borrow
968 adc \$0, $t1 # can't overflow
971 imulq 8*4($a_ptr), $acc1 # *= .LordK
976 mov 8*0($a_ptr), %rax
977 sbb %rdx, $acc0 # can't borrow
980 adc \$0, $acc0 # can't overflow
982 ################################# Second reduction step
985 add %rax, $t0 # guaranteed to be zero
986 mov 8*1($a_ptr), %rax
990 sbb \$0, $t1 # can't borrow
999 adc \$0, $t1 # can't overflow
1002 imulq 8*4($a_ptr), $acc2 # *= .LordK
1007 mov 8*0($a_ptr), %rax
1008 sbb %rdx, $acc1 # can't borrow
1011 adc \$0, $acc1 # can't overflow
1013 ################################# Third reduction step
1016 add %rax, $t0 # guaranteed to be zero
1017 mov 8*1($a_ptr), %rax
1021 sbb \$0, $t1 # can't borrow
1030 adc \$0, $t1 # can't overflow
1033 imulq 8*4($a_ptr), $acc3 # *= .LordK
1038 mov 8*0($a_ptr), %rax
1039 sbb %rdx, $acc2 # can't borrow
1042 adc \$0, $acc2 # can't overflow
1044 ################################# Last reduction step
1047 add %rax, $t0 # guaranteed to be zero
1048 mov 8*1($a_ptr), %rax
1052 sbb \$0, $t1 # can't borrow
1061 adc \$0, $t1 # can't overflow
1066 sbb %rdx, $acc3 # can't borrow
1069 adc \$0, $acc3 # can't overflow
1071 ################################# Add bits [511:256] of the sqr result
1081 ################################# Compare to modulus
1082 sub 8*0($a_ptr), $acc0
1084 sbb 8*1($a_ptr), $acc1
1085 sbb 8*2($a_ptr), $acc2
1087 sbb 8*3($a_ptr), $acc3
1098 mov $acc0, 8*0($r_ptr)
1099 mov %rax, 8*1($r_ptr)
1101 mov $acc6, 8*2($r_ptr)
1103 mov $acc7, 8*3($r_ptr)
1119 .cfi_adjust_cfa_offset -48
1123 .size ecp_nistz256_ord_sqr_mont,.-ecp_nistz256_ord_sqr_mont
1126 $code.=<<___ if ($addx);
1127 ################################################################################
1128 .type ecp_nistz256_ord_mul_montx,\@function,3
1130 ecp_nistz256_ord_mul_montx:
1132 .Lecp_nistz256_ord_mul_montx:
1148 mov 8*0($b_org), %rdx
1149 mov 8*0($a_ptr), $acc1
1150 mov 8*1($a_ptr), $acc2
1151 mov 8*2($a_ptr), $acc3
1152 mov 8*3($a_ptr), $acc4
1153 lea -128($a_ptr), $a_ptr # control u-op density
1154 lea .Lord-128(%rip), %r14
1155 mov .LordK(%rip), %r15
1157 ################################# Multiply by b[0]
1158 mulx $acc1, $acc0, $acc1
1159 mulx $acc2, $t0, $acc2
1160 mulx $acc3, $t1, $acc3
1162 mulx $acc4, $t0, $acc4
1164 mulx %r15, %rdx, %rax
1169 ################################# reduction
1170 xor $acc5, $acc5 # $acc5=0, cf=0, of=0
1171 mulx 8*0+128(%r14), $t0, $t1
1172 adcx $t0, $acc0 # 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*1($b_ptr), %rdx
1189 adc \$0, $acc5 # cf=0, of=0
1191 ################################# Multiply by b[1]
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, $acc0 # cf=0, of=0
1214 ################################# reduction
1215 mulx 8*0+128(%r14), $t0, $t1
1216 adcx $t0, $acc1 # 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*2($b_ptr), %rdx
1233 adc \$0, $acc0 # cf=0, of=0
1235 ################################# Multiply by b[2]
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, $acc1 # cf=0, of=0
1258 ################################# reduction
1259 mulx 8*0+128(%r14), $t0, $t1
1260 adcx $t0, $acc2 # guaranteed 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
1272 mov 8*3($b_ptr), %rdx
1277 adc \$0, $acc1 # cf=0, of=0
1279 ################################# Multiply by b[3]
1280 mulx 8*0+128($a_ptr), $t0, $t1
1284 mulx 8*1+128($a_ptr), $t0, $t1
1288 mulx 8*2+128($a_ptr), $t0, $t1
1292 mulx 8*3+128($a_ptr), $t0, $t1
1294 mulx %r15, %rdx, %rax
1300 adc \$0, $acc2 # cf=0, of=0
1302 ################################# reduction
1303 mulx 8*0+128(%r14), $t0, $t1
1304 adcx $t0, $acc3 # guaranteed to be zero
1307 mulx 8*1+128(%r14), $t0, $t1
1311 mulx 8*2+128(%r14), $t0, $t1
1315 mulx 8*3+128(%r14), $t0, $t1
1325 #################################
1326 # Branch-less conditional subtraction of P
1328 sub 8*0(%r14), $acc4
1329 sbb 8*1(%r14), $acc5
1330 sbb 8*2(%r14), $acc0
1332 sbb 8*3(%r14), $acc1
1340 mov $acc4, 8*0($r_ptr)
1341 mov $acc5, 8*1($r_ptr)
1342 mov $acc0, 8*2($r_ptr)
1343 mov $acc1, 8*3($r_ptr)
1358 .cfi_adjust_cfa_offset -48
1359 .Lord_mulx_epilogue:
1362 .size ecp_nistz256_ord_mul_montx,.-ecp_nistz256_ord_mul_montx
1364 .type ecp_nistz256_ord_sqr_montx,\@function,3
1366 ecp_nistz256_ord_sqr_montx:
1368 .Lecp_nistz256_ord_sqr_montx:
1384 mov 8*0($a_ptr), %rdx
1385 mov 8*1($a_ptr), $acc6
1386 mov 8*2($a_ptr), $acc7
1387 mov 8*3($a_ptr), $acc0
1388 lea .Lord(%rip), $a_ptr
1393 mulx $acc6, $acc1, $acc2 # a[0]*a[1]
1394 mulx $acc7, $t0, $acc3 # a[0]*a[2]
1395 mov %rdx, %rax # offload a[0]
1396 movq $acc6, %xmm1 # offload a[1]
1397 mulx $acc0, $t1, $acc4 # a[0]*a[3]
1400 movq $acc7, %xmm2 # offload a[2]
1403 xor $acc5, $acc5 # $acc5=0,cf=0,of=0
1404 #################################
1405 mulx $acc7, $t0, $t1 # a[1]*a[2]
1409 mulx $acc0, $t0, $t1 # a[1]*a[3]
1414 #################################
1415 mulx $acc0, $t0, $acc6 # a[2]*a[3]
1417 movq $acc0, %xmm3 # offload a[3]
1418 xor $acc7, $acc7 # $acc7=0,cf=0,of=0
1419 adcx $acc1, $acc1 # acc1:6<<1
1422 adox $acc7, $acc6 # of=0
1424 ################################# a[i]*a[i]
1425 mulx %rdx, $acc0, $t1
1446 ################################# reduction
1448 mulx 8*4($a_ptr), %rdx, $t0
1450 xor %rax, %rax # cf=0, of=0
1451 mulx 8*0($a_ptr), $t0, $t1
1452 adcx $t0, $acc0 # guaranteed to be zero
1454 mulx 8*1($a_ptr), $t0, $t1
1457 mulx 8*2($a_ptr), $t0, $t1
1460 mulx 8*3($a_ptr), $t0, $t1
1462 adox $t1, $acc0 # of=0
1463 adcx %rax, $acc0 # cf=0
1465 #################################
1467 mulx 8*4($a_ptr), %rdx, $t0
1469 mulx 8*0($a_ptr), $t0, $t1
1470 adox $t0, $acc1 # guaranteed to be zero
1472 mulx 8*1($a_ptr), $t0, $t1
1475 mulx 8*2($a_ptr), $t0, $t1
1478 mulx 8*3($a_ptr), $t0, $t1
1480 adcx $t1, $acc1 # cf=0
1481 adox %rax, $acc1 # of=0
1483 #################################
1485 mulx 8*4($a_ptr), %rdx, $t0
1487 mulx 8*0($a_ptr), $t0, $t1
1488 adcx $t0, $acc2 # guaranteed to be zero
1490 mulx 8*1($a_ptr), $t0, $t1
1493 mulx 8*2($a_ptr), $t0, $t1
1496 mulx 8*3($a_ptr), $t0, $t1
1498 adox $t1, $acc2 # of=0
1499 adcx %rax, $acc2 # cf=0
1501 #################################
1503 mulx 8*4($a_ptr), %rdx, $t0
1505 mulx 8*0($a_ptr), $t0, $t1
1506 adox $t0, $acc3 # guaranteed to be zero
1508 mulx 8*1($a_ptr), $t0, $t1
1511 mulx 8*2($a_ptr), $t0, $t1
1514 mulx 8*3($a_ptr), $t0, $t1
1519 ################################# accumulate upper half
1520 add $acc0, $acc4 # add $acc4, $acc0
1528 ################################# compare to modulus
1529 sub 8*0($a_ptr), $acc4
1531 sbb 8*1($a_ptr), $acc1
1532 sbb 8*2($a_ptr), $acc2
1534 sbb 8*3($a_ptr), $acc3
1545 mov %rdx, 8*0($r_ptr)
1546 mov $acc6, 8*1($r_ptr)
1548 mov $acc7, 8*2($r_ptr)
1550 mov $acc0, 8*3($r_ptr)
1566 .cfi_adjust_cfa_offset -48
1567 .Lord_sqrx_epilogue:
1570 .size ecp_nistz256_ord_sqr_montx,.-ecp_nistz256_ord_sqr_montx
1574 ################################################################################
1575 # void ecp_nistz256_to_mont(
1578 .globl ecp_nistz256_to_mont
1579 .type ecp_nistz256_to_mont,\@function,2
1581 ecp_nistz256_to_mont:
1583 $code.=<<___ if ($addx);
1585 and OPENSSL_ia32cap_P+8(%rip), %ecx
1588 lea .LRR(%rip), $b_org
1590 .size ecp_nistz256_to_mont,.-ecp_nistz256_to_mont
1592 ################################################################################
1593 # void ecp_nistz256_mul_mont(
1598 .globl ecp_nistz256_mul_mont
1599 .type ecp_nistz256_mul_mont,\@function,3
1601 ecp_nistz256_mul_mont:
1604 $code.=<<___ if ($addx);
1606 and OPENSSL_ia32cap_P+8(%rip), %ecx
1624 $code.=<<___ if ($addx);
1630 mov 8*0($b_org), %rax
1631 mov 8*0($a_ptr), $acc1
1632 mov 8*1($a_ptr), $acc2
1633 mov 8*2($a_ptr), $acc3
1634 mov 8*3($a_ptr), $acc4
1636 call __ecp_nistz256_mul_montq
1638 $code.=<<___ if ($addx);
1644 mov 8*0($b_org), %rdx
1645 mov 8*0($a_ptr), $acc1
1646 mov 8*1($a_ptr), $acc2
1647 mov 8*2($a_ptr), $acc3
1648 mov 8*3($a_ptr), $acc4
1649 lea -128($a_ptr), $a_ptr # control u-op density
1651 call __ecp_nistz256_mul_montx
1668 .cfi_adjust_cfa_offset -48
1672 .size ecp_nistz256_mul_mont,.-ecp_nistz256_mul_mont
1674 .type __ecp_nistz256_mul_montq,\@abi-omnipotent
1676 __ecp_nistz256_mul_montq:
1678 ########################################################################
1679 # Multiply a by b[0]
1682 mov .Lpoly+8*1(%rip),$poly1
1688 mov .Lpoly+8*3(%rip),$poly3
1707 ########################################################################
1708 # First reduction step
1709 # Basically now we want to multiply acc[0] by p256,
1710 # and add the result to the acc.
1711 # Due to the special form of p256 we do some optimizations
1713 # acc[0] x p256[0..1] = acc[0] x 2^96 - acc[0]
1714 # then we add acc[0] and get acc[0] x 2^96
1720 add $acc0, $acc1 # +=acc[0]<<96
1723 mov 8*1($b_ptr), %rax
1728 ########################################################################
1761 ########################################################################
1762 # Second reduction step
1770 mov 8*2($b_ptr), %rax
1775 ########################################################################
1808 ########################################################################
1809 # Third reduction step
1817 mov 8*3($b_ptr), %rax
1822 ########################################################################
1855 ########################################################################
1856 # Final reduction step
1869 ########################################################################
1870 # Branch-less conditional subtraction of P
1871 sub \$-1, $acc4 # .Lpoly[0]
1873 sbb $poly1, $acc5 # .Lpoly[1]
1874 sbb \$0, $acc0 # .Lpoly[2]
1876 sbb $poly3, $acc1 # .Lpoly[3]
1881 mov $acc4, 8*0($r_ptr)
1883 mov $acc5, 8*1($r_ptr)
1885 mov $acc0, 8*2($r_ptr)
1886 mov $acc1, 8*3($r_ptr)
1890 .size __ecp_nistz256_mul_montq,.-__ecp_nistz256_mul_montq
1892 ################################################################################
1893 # void ecp_nistz256_sqr_mont(
1897 # we optimize the square according to S.Gueron and V.Krasnov,
1898 # "Speeding up Big-Number Squaring"
1899 .globl ecp_nistz256_sqr_mont
1900 .type ecp_nistz256_sqr_mont,\@function,2
1902 ecp_nistz256_sqr_mont:
1905 $code.=<<___ if ($addx);
1907 and OPENSSL_ia32cap_P+8(%rip), %ecx
1924 $code.=<<___ if ($addx);
1929 mov 8*0($a_ptr), %rax
1930 mov 8*1($a_ptr), $acc6
1931 mov 8*2($a_ptr), $acc7
1932 mov 8*3($a_ptr), $acc0
1934 call __ecp_nistz256_sqr_montq
1936 $code.=<<___ if ($addx);
1941 mov 8*0($a_ptr), %rdx
1942 mov 8*1($a_ptr), $acc6
1943 mov 8*2($a_ptr), $acc7
1944 mov 8*3($a_ptr), $acc0
1945 lea -128($a_ptr), $a_ptr # control u-op density
1947 call __ecp_nistz256_sqr_montx
1964 .cfi_adjust_cfa_offset -48
1968 .size ecp_nistz256_sqr_mont,.-ecp_nistz256_sqr_mont
1970 .type __ecp_nistz256_sqr_montq,\@abi-omnipotent
1972 __ecp_nistz256_sqr_montq:
1975 mulq $acc6 # a[1]*a[0]
1980 mulq $acc5 # a[0]*a[2]
1986 mulq $acc5 # a[0]*a[3]
1992 #################################
1993 mulq $acc6 # a[1]*a[2]
1999 mulq $acc6 # a[1]*a[3]
2007 #################################
2008 mulq $acc7 # a[2]*a[3]
2011 mov 8*0($a_ptr), %rax
2015 add $acc1, $acc1 # acc1:6<<1
2025 mov 8*1($a_ptr), %rax
2031 mov 8*2($a_ptr), %rax
2038 mov 8*3($a_ptr), %rax
2048 mov .Lpoly+8*1(%rip), $a_ptr
2049 mov .Lpoly+8*3(%rip), $t1
2051 ##########################################
2058 add $acc0, $acc1 # +=acc[0]<<96
2064 ##########################################
2077 ##########################################
2090 ###########################################
2103 ############################################
2104 # Add the rest of the acc
2113 sub \$-1, $acc4 # .Lpoly[0]
2115 sbb $a_ptr, $acc5 # .Lpoly[1]
2116 sbb \$0, $acc6 # .Lpoly[2]
2118 sbb $t1, $acc7 # .Lpoly[3]
2123 mov $acc4, 8*0($r_ptr)
2125 mov $acc5, 8*1($r_ptr)
2127 mov $acc6, 8*2($r_ptr)
2128 mov $acc7, 8*3($r_ptr)
2132 .size __ecp_nistz256_sqr_montq,.-__ecp_nistz256_sqr_montq
2137 .type __ecp_nistz256_mul_montx,\@abi-omnipotent
2139 __ecp_nistz256_mul_montx:
2141 ########################################################################
2143 mulx $acc1, $acc0, $acc1
2144 mulx $acc2, $t0, $acc2
2146 xor $acc5, $acc5 # cf=0
2147 mulx $acc3, $t1, $acc3
2148 mov .Lpoly+8*3(%rip), $poly3
2150 mulx $acc4, $t0, $acc4
2153 shlx $poly1,$acc0,$t1
2155 shrx $poly1,$acc0,$t0
2158 ########################################################################
2159 # First reduction step
2163 mulx $poly3, $t0, $t1
2164 mov 8*1($b_ptr), %rdx
2168 xor $acc0, $acc0 # $acc0=0,cf=0,of=0
2170 ########################################################################
2172 mulx 8*0+128($a_ptr), $t0, $t1
2176 mulx 8*1+128($a_ptr), $t0, $t1
2180 mulx 8*2+128($a_ptr), $t0, $t1
2184 mulx 8*3+128($a_ptr), $t0, $t1
2187 shlx $poly1, $acc1, $t0
2189 shrx $poly1, $acc1, $t1
2195 ########################################################################
2196 # Second reduction step
2200 mulx $poly3, $t0, $t1
2201 mov 8*2($b_ptr), %rdx
2205 xor $acc1 ,$acc1 # $acc1=0,cf=0,of=0
2207 ########################################################################
2209 mulx 8*0+128($a_ptr), $t0, $t1
2213 mulx 8*1+128($a_ptr), $t0, $t1
2217 mulx 8*2+128($a_ptr), $t0, $t1
2221 mulx 8*3+128($a_ptr), $t0, $t1
2224 shlx $poly1, $acc2, $t0
2226 shrx $poly1, $acc2, $t1
2232 ########################################################################
2233 # Third reduction step
2237 mulx $poly3, $t0, $t1
2238 mov 8*3($b_ptr), %rdx
2242 xor $acc2, $acc2 # $acc2=0,cf=0,of=0
2244 ########################################################################
2246 mulx 8*0+128($a_ptr), $t0, $t1
2250 mulx 8*1+128($a_ptr), $t0, $t1
2254 mulx 8*2+128($a_ptr), $t0, $t1
2258 mulx 8*3+128($a_ptr), $t0, $t1
2261 shlx $poly1, $acc3, $t0
2263 shrx $poly1, $acc3, $t1
2269 ########################################################################
2270 # Fourth reduction step
2274 mulx $poly3, $t0, $t1
2276 mov .Lpoly+8*1(%rip), $poly1
2282 ########################################################################
2283 # Branch-less conditional subtraction of P
2286 sbb \$-1, $acc4 # .Lpoly[0]
2287 sbb $poly1, $acc5 # .Lpoly[1]
2288 sbb \$0, $acc0 # .Lpoly[2]
2290 sbb $poly3, $acc1 # .Lpoly[3]
2295 mov $acc4, 8*0($r_ptr)
2297 mov $acc5, 8*1($r_ptr)
2299 mov $acc0, 8*2($r_ptr)
2300 mov $acc1, 8*3($r_ptr)
2304 .size __ecp_nistz256_mul_montx,.-__ecp_nistz256_mul_montx
2306 .type __ecp_nistz256_sqr_montx,\@abi-omnipotent
2308 __ecp_nistz256_sqr_montx:
2310 mulx $acc6, $acc1, $acc2 # a[0]*a[1]
2311 mulx $acc7, $t0, $acc3 # a[0]*a[2]
2314 mulx $acc0, $t1, $acc4 # a[0]*a[3]
2318 xor $acc5, $acc5 # $acc5=0,cf=0,of=0
2320 #################################
2321 mulx $acc7, $t0, $t1 # a[1]*a[2]
2325 mulx $acc0, $t0, $t1 # a[1]*a[3]
2331 #################################
2332 mulx $acc0, $t0, $acc6 # a[2]*a[3]
2333 mov 8*0+128($a_ptr), %rdx
2334 xor $acc7, $acc7 # $acc7=0,cf=0,of=0
2335 adcx $acc1, $acc1 # acc1:6<<1
2338 adox $acc7, $acc6 # of=0
2340 mulx %rdx, $acc0, $t1
2341 mov 8*1+128($a_ptr), %rdx
2346 mov 8*2+128($a_ptr), %rdx
2352 mov 8*3+128($a_ptr), %rdx
2360 mov .Lpoly+8*3(%rip), %rdx
2362 shlx $a_ptr, $acc0, $t0
2364 shrx $a_ptr, $acc0, $t4
2371 mulx $acc0, $t0, $acc0
2373 shlx $a_ptr, $acc1, $t0
2375 shrx $a_ptr, $acc1, $t4
2381 mulx $acc1, $t0, $acc1
2383 shlx $a_ptr, $acc2, $t0
2385 shrx $a_ptr, $acc2, $t4
2391 mulx $acc2, $t0, $acc2
2393 shlx $a_ptr, $acc3, $t0
2395 shrx $a_ptr, $acc3, $t4
2401 mulx $acc3, $t0, $acc3
2406 add $acc0, $acc4 # accumulate upper half
2407 mov .Lpoly+8*1(%rip), $a_ptr
2415 sub \$-1, $acc4 # .Lpoly[0]
2417 sbb $a_ptr, $acc5 # .Lpoly[1]
2418 sbb \$0, $acc6 # .Lpoly[2]
2420 sbb $t1, $acc7 # .Lpoly[3]
2425 mov $acc4, 8*0($r_ptr)
2427 mov $acc5, 8*1($r_ptr)
2429 mov $acc6, 8*2($r_ptr)
2430 mov $acc7, 8*3($r_ptr)
2434 .size __ecp_nistz256_sqr_montx,.-__ecp_nistz256_sqr_montx
2439 my ($r_ptr,$in_ptr)=("%rdi","%rsi");
2440 my ($acc0,$acc1,$acc2,$acc3)=map("%r$_",(8..11));
2441 my ($t0,$t1,$t2)=("%rcx","%r12","%r13");
2444 ################################################################################
2445 # void ecp_nistz256_from_mont(
2448 # This one performs Montgomery multiplication by 1, so we only need the reduction
2450 .globl ecp_nistz256_from_mont
2451 .type ecp_nistz256_from_mont,\@function,2
2453 ecp_nistz256_from_mont:
2461 mov 8*0($in_ptr), %rax
2462 mov .Lpoly+8*3(%rip), $t2
2463 mov 8*1($in_ptr), $acc1
2464 mov 8*2($in_ptr), $acc2
2465 mov 8*3($in_ptr), $acc3
2467 mov .Lpoly+8*1(%rip), $t1
2469 #########################################
2481 #########################################
2494 ##########################################
2507 ###########################################
2521 ###########################################
2522 # Branch-less conditional subtraction
2532 cmovnz $in_ptr, $acc1
2533 mov $acc0, 8*0($r_ptr)
2535 mov $acc1, 8*1($r_ptr)
2537 mov $acc2, 8*2($r_ptr)
2538 mov $acc3, 8*3($r_ptr)
2545 .cfi_adjust_cfa_offset -16
2549 .size ecp_nistz256_from_mont,.-ecp_nistz256_from_mont
2553 my ($val,$in_t,$index)=$win64?("%rcx","%rdx","%r8d"):("%rdi","%rsi","%edx");
2554 my ($ONE,$INDEX,$Ra,$Rb,$Rc,$Rd,$Re,$Rf)=map("%xmm$_",(0..7));
2555 my ($M0,$T0a,$T0b,$T0c,$T0d,$T0e,$T0f,$TMP0)=map("%xmm$_",(8..15));
2556 my ($M1,$T2a,$T2b,$TMP2,$M2,$T2a,$T2b,$TMP2)=map("%xmm$_",(8..15));
2559 ################################################################################
2560 # void ecp_nistz256_scatter_w5(uint64_t *val, uint64_t *in_t, int index);
2561 .globl ecp_nistz256_scatter_w5
2562 .type ecp_nistz256_scatter_w5,\@abi-omnipotent
2564 ecp_nistz256_scatter_w5:
2565 lea -3($index,$index,2), $index
2566 movdqa 0x00($in_t), %xmm0
2568 movdqa 0x10($in_t), %xmm1
2569 movdqa 0x20($in_t), %xmm2
2570 movdqa 0x30($in_t), %xmm3
2571 movdqa 0x40($in_t), %xmm4
2572 movdqa 0x50($in_t), %xmm5
2573 movdqa %xmm0, 0x00($val,$index)
2574 movdqa %xmm1, 0x10($val,$index)
2575 movdqa %xmm2, 0x20($val,$index)
2576 movdqa %xmm3, 0x30($val,$index)
2577 movdqa %xmm4, 0x40($val,$index)
2578 movdqa %xmm5, 0x50($val,$index)
2581 .size ecp_nistz256_scatter_w5,.-ecp_nistz256_scatter_w5
2583 ################################################################################
2584 # void ecp_nistz256_gather_w5(uint64_t *val, uint64_t *in_t, int index);
2585 .globl ecp_nistz256_gather_w5
2586 .type ecp_nistz256_gather_w5,\@abi-omnipotent
2588 ecp_nistz256_gather_w5:
2591 $code.=<<___ if ($avx>1);
2592 mov OPENSSL_ia32cap_P+8(%rip), %eax
2594 jnz .Lavx2_gather_w5
2596 $code.=<<___ if ($win64);
2597 lea -0x88(%rsp), %rax
2598 .LSEH_begin_ecp_nistz256_gather_w5:
2599 .byte 0x48,0x8d,0x60,0xe0 #lea -0x20(%rax), %rsp
2600 .byte 0x0f,0x29,0x70,0xe0 #movaps %xmm6, -0x20(%rax)
2601 .byte 0x0f,0x29,0x78,0xf0 #movaps %xmm7, -0x10(%rax)
2602 .byte 0x44,0x0f,0x29,0x00 #movaps %xmm8, 0(%rax)
2603 .byte 0x44,0x0f,0x29,0x48,0x10 #movaps %xmm9, 0x10(%rax)
2604 .byte 0x44,0x0f,0x29,0x50,0x20 #movaps %xmm10, 0x20(%rax)
2605 .byte 0x44,0x0f,0x29,0x58,0x30 #movaps %xmm11, 0x30(%rax)
2606 .byte 0x44,0x0f,0x29,0x60,0x40 #movaps %xmm12, 0x40(%rax)
2607 .byte 0x44,0x0f,0x29,0x68,0x50 #movaps %xmm13, 0x50(%rax)
2608 .byte 0x44,0x0f,0x29,0x70,0x60 #movaps %xmm14, 0x60(%rax)
2609 .byte 0x44,0x0f,0x29,0x78,0x70 #movaps %xmm15, 0x70(%rax)
2612 movdqa .LOne(%rip), $ONE
2623 pshufd \$0, $INDEX, $INDEX
2626 .Lselect_loop_sse_w5:
2630 pcmpeqd $INDEX, $TMP0
2632 movdqa 16*0($in_t), $T0a
2633 movdqa 16*1($in_t), $T0b
2634 movdqa 16*2($in_t), $T0c
2635 movdqa 16*3($in_t), $T0d
2636 movdqa 16*4($in_t), $T0e
2637 movdqa 16*5($in_t), $T0f
2638 lea 16*6($in_t), $in_t
2654 jnz .Lselect_loop_sse_w5
2656 movdqu $Ra, 16*0($val)
2657 movdqu $Rb, 16*1($val)
2658 movdqu $Rc, 16*2($val)
2659 movdqu $Rd, 16*3($val)
2660 movdqu $Re, 16*4($val)
2661 movdqu $Rf, 16*5($val)
2663 $code.=<<___ if ($win64);
2664 movaps (%rsp), %xmm6
2665 movaps 0x10(%rsp), %xmm7
2666 movaps 0x20(%rsp), %xmm8
2667 movaps 0x30(%rsp), %xmm9
2668 movaps 0x40(%rsp), %xmm10
2669 movaps 0x50(%rsp), %xmm11
2670 movaps 0x60(%rsp), %xmm12
2671 movaps 0x70(%rsp), %xmm13
2672 movaps 0x80(%rsp), %xmm14
2673 movaps 0x90(%rsp), %xmm15
2674 lea 0xa8(%rsp), %rsp
2679 .LSEH_end_ecp_nistz256_gather_w5:
2680 .size ecp_nistz256_gather_w5,.-ecp_nistz256_gather_w5
2682 ################################################################################
2683 # void ecp_nistz256_scatter_w7(uint64_t *val, uint64_t *in_t, int index);
2684 .globl ecp_nistz256_scatter_w7
2685 .type ecp_nistz256_scatter_w7,\@abi-omnipotent
2687 ecp_nistz256_scatter_w7:
2688 movdqu 0x00($in_t), %xmm0
2690 movdqu 0x10($in_t), %xmm1
2691 movdqu 0x20($in_t), %xmm2
2692 movdqu 0x30($in_t), %xmm3
2693 movdqa %xmm0, 0x00($val,$index)
2694 movdqa %xmm1, 0x10($val,$index)
2695 movdqa %xmm2, 0x20($val,$index)
2696 movdqa %xmm3, 0x30($val,$index)
2699 .size ecp_nistz256_scatter_w7,.-ecp_nistz256_scatter_w7
2701 ################################################################################
2702 # void ecp_nistz256_gather_w7(uint64_t *val, uint64_t *in_t, int index);
2703 .globl ecp_nistz256_gather_w7
2704 .type ecp_nistz256_gather_w7,\@abi-omnipotent
2706 ecp_nistz256_gather_w7:
2709 $code.=<<___ if ($avx>1);
2710 mov OPENSSL_ia32cap_P+8(%rip), %eax
2712 jnz .Lavx2_gather_w7
2714 $code.=<<___ if ($win64);
2715 lea -0x88(%rsp), %rax
2716 .LSEH_begin_ecp_nistz256_gather_w7:
2717 .byte 0x48,0x8d,0x60,0xe0 #lea -0x20(%rax), %rsp
2718 .byte 0x0f,0x29,0x70,0xe0 #movaps %xmm6, -0x20(%rax)
2719 .byte 0x0f,0x29,0x78,0xf0 #movaps %xmm7, -0x10(%rax)
2720 .byte 0x44,0x0f,0x29,0x00 #movaps %xmm8, 0(%rax)
2721 .byte 0x44,0x0f,0x29,0x48,0x10 #movaps %xmm9, 0x10(%rax)
2722 .byte 0x44,0x0f,0x29,0x50,0x20 #movaps %xmm10, 0x20(%rax)
2723 .byte 0x44,0x0f,0x29,0x58,0x30 #movaps %xmm11, 0x30(%rax)
2724 .byte 0x44,0x0f,0x29,0x60,0x40 #movaps %xmm12, 0x40(%rax)
2725 .byte 0x44,0x0f,0x29,0x68,0x50 #movaps %xmm13, 0x50(%rax)
2726 .byte 0x44,0x0f,0x29,0x70,0x60 #movaps %xmm14, 0x60(%rax)
2727 .byte 0x44,0x0f,0x29,0x78,0x70 #movaps %xmm15, 0x70(%rax)
2730 movdqa .LOne(%rip), $M0
2739 pshufd \$0, $INDEX, $INDEX
2742 .Lselect_loop_sse_w7:
2745 movdqa 16*0($in_t), $T0a
2746 movdqa 16*1($in_t), $T0b
2747 pcmpeqd $INDEX, $TMP0
2748 movdqa 16*2($in_t), $T0c
2749 movdqa 16*3($in_t), $T0d
2750 lea 16*4($in_t), $in_t
2759 prefetcht0 255($in_t)
2763 jnz .Lselect_loop_sse_w7
2765 movdqu $Ra, 16*0($val)
2766 movdqu $Rb, 16*1($val)
2767 movdqu $Rc, 16*2($val)
2768 movdqu $Rd, 16*3($val)
2770 $code.=<<___ if ($win64);
2771 movaps (%rsp), %xmm6
2772 movaps 0x10(%rsp), %xmm7
2773 movaps 0x20(%rsp), %xmm8
2774 movaps 0x30(%rsp), %xmm9
2775 movaps 0x40(%rsp), %xmm10
2776 movaps 0x50(%rsp), %xmm11
2777 movaps 0x60(%rsp), %xmm12
2778 movaps 0x70(%rsp), %xmm13
2779 movaps 0x80(%rsp), %xmm14
2780 movaps 0x90(%rsp), %xmm15
2781 lea 0xa8(%rsp), %rsp
2786 .LSEH_end_ecp_nistz256_gather_w7:
2787 .size ecp_nistz256_gather_w7,.-ecp_nistz256_gather_w7
2791 my ($val,$in_t,$index)=$win64?("%rcx","%rdx","%r8d"):("%rdi","%rsi","%edx");
2792 my ($TWO,$INDEX,$Ra,$Rb,$Rc)=map("%ymm$_",(0..4));
2793 my ($M0,$T0a,$T0b,$T0c,$TMP0)=map("%ymm$_",(5..9));
2794 my ($M1,$T1a,$T1b,$T1c,$TMP1)=map("%ymm$_",(10..14));
2797 ################################################################################
2798 # void ecp_nistz256_avx2_gather_w5(uint64_t *val, uint64_t *in_t, int index);
2799 .type ecp_nistz256_avx2_gather_w5,\@abi-omnipotent
2801 ecp_nistz256_avx2_gather_w5:
2806 $code.=<<___ if ($win64);
2807 lea -0x88(%rsp), %rax
2809 .LSEH_begin_ecp_nistz256_avx2_gather_w5:
2810 .byte 0x48,0x8d,0x60,0xe0 # lea -0x20(%rax), %rsp
2811 .byte 0xc5,0xf8,0x29,0x70,0xe0 # vmovaps %xmm6, -0x20(%rax)
2812 .byte 0xc5,0xf8,0x29,0x78,0xf0 # vmovaps %xmm7, -0x10(%rax)
2813 .byte 0xc5,0x78,0x29,0x40,0x00 # vmovaps %xmm8, 8(%rax)
2814 .byte 0xc5,0x78,0x29,0x48,0x10 # vmovaps %xmm9, 0x10(%rax)
2815 .byte 0xc5,0x78,0x29,0x50,0x20 # vmovaps %xmm10, 0x20(%rax)
2816 .byte 0xc5,0x78,0x29,0x58,0x30 # vmovaps %xmm11, 0x30(%rax)
2817 .byte 0xc5,0x78,0x29,0x60,0x40 # vmovaps %xmm12, 0x40(%rax)
2818 .byte 0xc5,0x78,0x29,0x68,0x50 # vmovaps %xmm13, 0x50(%rax)
2819 .byte 0xc5,0x78,0x29,0x70,0x60 # vmovaps %xmm14, 0x60(%rax)
2820 .byte 0xc5,0x78,0x29,0x78,0x70 # vmovaps %xmm15, 0x70(%rax)
2823 vmovdqa .LTwo(%rip), $TWO
2829 vmovdqa .LOne(%rip), $M0
2830 vmovdqa .LTwo(%rip), $M1
2833 vpermd $INDEX, $Ra, $INDEX
2836 .Lselect_loop_avx2_w5:
2838 vmovdqa 32*0($in_t), $T0a
2839 vmovdqa 32*1($in_t), $T0b
2840 vmovdqa 32*2($in_t), $T0c
2842 vmovdqa 32*3($in_t), $T1a
2843 vmovdqa 32*4($in_t), $T1b
2844 vmovdqa 32*5($in_t), $T1c
2846 vpcmpeqd $INDEX, $M0, $TMP0
2847 vpcmpeqd $INDEX, $M1, $TMP1
2849 vpaddd $TWO, $M0, $M0
2850 vpaddd $TWO, $M1, $M1
2851 lea 32*6($in_t), $in_t
2853 vpand $TMP0, $T0a, $T0a
2854 vpand $TMP0, $T0b, $T0b
2855 vpand $TMP0, $T0c, $T0c
2856 vpand $TMP1, $T1a, $T1a
2857 vpand $TMP1, $T1b, $T1b
2858 vpand $TMP1, $T1c, $T1c
2860 vpxor $T0a, $Ra, $Ra
2861 vpxor $T0b, $Rb, $Rb
2862 vpxor $T0c, $Rc, $Rc
2863 vpxor $T1a, $Ra, $Ra
2864 vpxor $T1b, $Rb, $Rb
2865 vpxor $T1c, $Rc, $Rc
2868 jnz .Lselect_loop_avx2_w5
2870 vmovdqu $Ra, 32*0($val)
2871 vmovdqu $Rb, 32*1($val)
2872 vmovdqu $Rc, 32*2($val)
2875 $code.=<<___ if ($win64);
2876 movaps (%rsp), %xmm6
2877 movaps 0x10(%rsp), %xmm7
2878 movaps 0x20(%rsp), %xmm8
2879 movaps 0x30(%rsp), %xmm9
2880 movaps 0x40(%rsp), %xmm10
2881 movaps 0x50(%rsp), %xmm11
2882 movaps 0x60(%rsp), %xmm12
2883 movaps 0x70(%rsp), %xmm13
2884 movaps 0x80(%rsp), %xmm14
2885 movaps 0x90(%rsp), %xmm15
2891 .LSEH_end_ecp_nistz256_avx2_gather_w5:
2892 .size ecp_nistz256_avx2_gather_w5,.-ecp_nistz256_avx2_gather_w5
2896 my ($val,$in_t,$index)=$win64?("%rcx","%rdx","%r8d"):("%rdi","%rsi","%edx");
2897 my ($THREE,$INDEX,$Ra,$Rb)=map("%ymm$_",(0..3));
2898 my ($M0,$T0a,$T0b,$TMP0)=map("%ymm$_",(4..7));
2899 my ($M1,$T1a,$T1b,$TMP1)=map("%ymm$_",(8..11));
2900 my ($M2,$T2a,$T2b,$TMP2)=map("%ymm$_",(12..15));
2904 ################################################################################
2905 # void ecp_nistz256_avx2_gather_w7(uint64_t *val, uint64_t *in_t, int index);
2906 .globl ecp_nistz256_avx2_gather_w7
2907 .type ecp_nistz256_avx2_gather_w7,\@abi-omnipotent
2909 ecp_nistz256_avx2_gather_w7:
2914 $code.=<<___ if ($win64);
2916 lea -0x88(%rsp), %rax
2917 .LSEH_begin_ecp_nistz256_avx2_gather_w7:
2918 .byte 0x48,0x8d,0x60,0xe0 # lea -0x20(%rax), %rsp
2919 .byte 0xc5,0xf8,0x29,0x70,0xe0 # vmovaps %xmm6, -0x20(%rax)
2920 .byte 0xc5,0xf8,0x29,0x78,0xf0 # vmovaps %xmm7, -0x10(%rax)
2921 .byte 0xc5,0x78,0x29,0x40,0x00 # vmovaps %xmm8, 8(%rax)
2922 .byte 0xc5,0x78,0x29,0x48,0x10 # vmovaps %xmm9, 0x10(%rax)
2923 .byte 0xc5,0x78,0x29,0x50,0x20 # vmovaps %xmm10, 0x20(%rax)
2924 .byte 0xc5,0x78,0x29,0x58,0x30 # vmovaps %xmm11, 0x30(%rax)
2925 .byte 0xc5,0x78,0x29,0x60,0x40 # vmovaps %xmm12, 0x40(%rax)
2926 .byte 0xc5,0x78,0x29,0x68,0x50 # vmovaps %xmm13, 0x50(%rax)
2927 .byte 0xc5,0x78,0x29,0x70,0x60 # vmovaps %xmm14, 0x60(%rax)
2928 .byte 0xc5,0x78,0x29,0x78,0x70 # vmovaps %xmm15, 0x70(%rax)
2931 vmovdqa .LThree(%rip), $THREE
2936 vmovdqa .LOne(%rip), $M0
2937 vmovdqa .LTwo(%rip), $M1
2938 vmovdqa .LThree(%rip), $M2
2941 vpermd $INDEX, $Ra, $INDEX
2942 # Skip index = 0, because it is implicitly the point at infinity
2945 .Lselect_loop_avx2_w7:
2947 vmovdqa 32*0($in_t), $T0a
2948 vmovdqa 32*1($in_t), $T0b
2950 vmovdqa 32*2($in_t), $T1a
2951 vmovdqa 32*3($in_t), $T1b
2953 vmovdqa 32*4($in_t), $T2a
2954 vmovdqa 32*5($in_t), $T2b
2956 vpcmpeqd $INDEX, $M0, $TMP0
2957 vpcmpeqd $INDEX, $M1, $TMP1
2958 vpcmpeqd $INDEX, $M2, $TMP2
2960 vpaddd $THREE, $M0, $M0
2961 vpaddd $THREE, $M1, $M1
2962 vpaddd $THREE, $M2, $M2
2963 lea 32*6($in_t), $in_t
2965 vpand $TMP0, $T0a, $T0a
2966 vpand $TMP0, $T0b, $T0b
2967 vpand $TMP1, $T1a, $T1a
2968 vpand $TMP1, $T1b, $T1b
2969 vpand $TMP2, $T2a, $T2a
2970 vpand $TMP2, $T2b, $T2b
2972 vpxor $T0a, $Ra, $Ra
2973 vpxor $T0b, $Rb, $Rb
2974 vpxor $T1a, $Ra, $Ra
2975 vpxor $T1b, $Rb, $Rb
2976 vpxor $T2a, $Ra, $Ra
2977 vpxor $T2b, $Rb, $Rb
2980 jnz .Lselect_loop_avx2_w7
2983 vmovdqa 32*0($in_t), $T0a
2984 vmovdqa 32*1($in_t), $T0b
2986 vpcmpeqd $INDEX, $M0, $TMP0
2988 vpand $TMP0, $T0a, $T0a
2989 vpand $TMP0, $T0b, $T0b
2991 vpxor $T0a, $Ra, $Ra
2992 vpxor $T0b, $Rb, $Rb
2994 vmovdqu $Ra, 32*0($val)
2995 vmovdqu $Rb, 32*1($val)
2998 $code.=<<___ if ($win64);
2999 movaps (%rsp), %xmm6
3000 movaps 0x10(%rsp), %xmm7
3001 movaps 0x20(%rsp), %xmm8
3002 movaps 0x30(%rsp), %xmm9
3003 movaps 0x40(%rsp), %xmm10
3004 movaps 0x50(%rsp), %xmm11
3005 movaps 0x60(%rsp), %xmm12
3006 movaps 0x70(%rsp), %xmm13
3007 movaps 0x80(%rsp), %xmm14
3008 movaps 0x90(%rsp), %xmm15
3014 .LSEH_end_ecp_nistz256_avx2_gather_w7:
3015 .size ecp_nistz256_avx2_gather_w7,.-ecp_nistz256_avx2_gather_w7
3019 .globl ecp_nistz256_avx2_gather_w7
3020 .type ecp_nistz256_avx2_gather_w7,\@function,3
3022 ecp_nistz256_avx2_gather_w7:
3023 .byte 0x0f,0x0b # ud2
3025 .size ecp_nistz256_avx2_gather_w7,.-ecp_nistz256_avx2_gather_w7
3029 ########################################################################
3030 # This block implements higher level point_double, point_add and
3031 # point_add_affine. The key to performance in this case is to allow
3032 # out-of-order execution logic to overlap computations from next step
3033 # with tail processing from current step. By using tailored calling
3034 # sequence we minimize inter-step overhead to give processor better
3035 # shot at overlapping operations...
3037 # You will notice that input data is copied to stack. Trouble is that
3038 # there are no registers to spare for holding original pointers and
3039 # reloading them, pointers, would create undesired dependencies on
3040 # effective addresses calculation paths. In other words it's too done
3041 # to favour out-of-order execution logic.
3042 # <appro@openssl.org>
3044 my ($r_ptr,$a_ptr,$b_org,$b_ptr)=("%rdi","%rsi","%rdx","%rbx");
3045 my ($acc0,$acc1,$acc2,$acc3,$acc4,$acc5,$acc6,$acc7)=map("%r$_",(8..15));
3046 my ($t0,$t1,$t2,$t3,$t4)=("%rax","%rbp","%rcx",$acc4,$acc4);
3047 my ($poly1,$poly3)=($acc6,$acc7);
3049 sub load_for_mul () {
3050 my ($a,$b,$src0) = @_;
3051 my $bias = $src0 eq "%rax" ? 0 : -128;
3057 lea $bias+$a, $a_ptr
3062 sub load_for_sqr () {
3064 my $bias = $src0 eq "%rax" ? 0 : -128;
3068 lea $bias+$a, $a_ptr
3074 ########################################################################
3075 # operate in 4-5-0-1 "name space" that matches multiplication output
3077 my ($a0,$a1,$a2,$a3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
3080 .type __ecp_nistz256_add_toq,\@abi-omnipotent
3082 __ecp_nistz256_add_toq:
3085 add 8*0($b_ptr), $a0
3086 adc 8*1($b_ptr), $a1
3088 adc 8*2($b_ptr), $a2
3089 adc 8*3($b_ptr), $a3
3103 mov $a0, 8*0($r_ptr)
3105 mov $a1, 8*1($r_ptr)
3107 mov $a2, 8*2($r_ptr)
3108 mov $a3, 8*3($r_ptr)
3112 .size __ecp_nistz256_add_toq,.-__ecp_nistz256_add_toq
3114 .type __ecp_nistz256_sub_fromq,\@abi-omnipotent
3116 __ecp_nistz256_sub_fromq:
3118 sub 8*0($b_ptr), $a0
3119 sbb 8*1($b_ptr), $a1
3121 sbb 8*2($b_ptr), $a2
3122 sbb 8*3($b_ptr), $a3
3136 mov $a0, 8*0($r_ptr)
3138 mov $a1, 8*1($r_ptr)
3140 mov $a2, 8*2($r_ptr)
3141 mov $a3, 8*3($r_ptr)
3145 .size __ecp_nistz256_sub_fromq,.-__ecp_nistz256_sub_fromq
3147 .type __ecp_nistz256_subq,\@abi-omnipotent
3149 __ecp_nistz256_subq:
3174 .size __ecp_nistz256_subq,.-__ecp_nistz256_subq
3176 .type __ecp_nistz256_mul_by_2q,\@abi-omnipotent
3178 __ecp_nistz256_mul_by_2q:
3181 add $a0, $a0 # a0:a3+a0:a3
3199 mov $a0, 8*0($r_ptr)
3201 mov $a1, 8*1($r_ptr)
3203 mov $a2, 8*2($r_ptr)
3204 mov $a3, 8*3($r_ptr)
3208 .size __ecp_nistz256_mul_by_2q,.-__ecp_nistz256_mul_by_2q
3213 my ($src0,$sfx,$bias);
3214 my ($S,$M,$Zsqr,$in_x,$tmp0)=map(32*$_,(0..4));
3222 .globl ecp_nistz256_point_double
3223 .type ecp_nistz256_point_double,\@function,2
3225 ecp_nistz256_point_double:
3228 $code.=<<___ if ($addx);
3230 and OPENSSL_ia32cap_P+8(%rip), %ecx
3240 .type ecp_nistz256_point_doublex,\@function,2
3242 ecp_nistz256_point_doublex:
3261 .cfi_adjust_cfa_offset 32*5+8
3262 .Lpoint_double${x}_body:
3264 .Lpoint_double_shortcut$x:
3265 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$a_ptr.x
3266 mov $a_ptr, $b_ptr # backup copy
3267 movdqu 0x10($a_ptr), %xmm1
3268 mov 0x20+8*0($a_ptr), $acc4 # load in_y in "5-4-0-1" order
3269 mov 0x20+8*1($a_ptr), $acc5
3270 mov 0x20+8*2($a_ptr), $acc0
3271 mov 0x20+8*3($a_ptr), $acc1
3272 mov .Lpoly+8*1(%rip), $poly1
3273 mov .Lpoly+8*3(%rip), $poly3
3274 movdqa %xmm0, $in_x(%rsp)
3275 movdqa %xmm1, $in_x+0x10(%rsp)
3276 lea 0x20($r_ptr), $acc2
3277 lea 0x40($r_ptr), $acc3
3282 lea $S(%rsp), $r_ptr
3283 call __ecp_nistz256_mul_by_2$x # p256_mul_by_2(S, in_y);
3285 mov 0x40+8*0($a_ptr), $src0
3286 mov 0x40+8*1($a_ptr), $acc6
3287 mov 0x40+8*2($a_ptr), $acc7
3288 mov 0x40+8*3($a_ptr), $acc0
3289 lea 0x40-$bias($a_ptr), $a_ptr
3290 lea $Zsqr(%rsp), $r_ptr
3291 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Zsqr, in_z);
3293 `&load_for_sqr("$S(%rsp)", "$src0")`
3294 lea $S(%rsp), $r_ptr
3295 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(S, S);
3297 mov 0x20($b_ptr), $src0 # $b_ptr is still valid
3298 mov 0x40+8*0($b_ptr), $acc1
3299 mov 0x40+8*1($b_ptr), $acc2
3300 mov 0x40+8*2($b_ptr), $acc3
3301 mov 0x40+8*3($b_ptr), $acc4
3302 lea 0x40-$bias($b_ptr), $a_ptr
3303 lea 0x20($b_ptr), $b_ptr
3305 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, in_z, in_y);
3306 call __ecp_nistz256_mul_by_2$x # p256_mul_by_2(res_z, res_z);
3308 mov $in_x+8*0(%rsp), $acc4 # "5-4-0-1" order
3309 mov $in_x+8*1(%rsp), $acc5
3310 lea $Zsqr(%rsp), $b_ptr
3311 mov $in_x+8*2(%rsp), $acc0
3312 mov $in_x+8*3(%rsp), $acc1
3313 lea $M(%rsp), $r_ptr
3314 call __ecp_nistz256_add_to$x # p256_add(M, in_x, Zsqr);
3316 mov $in_x+8*0(%rsp), $acc4 # "5-4-0-1" order
3317 mov $in_x+8*1(%rsp), $acc5
3318 lea $Zsqr(%rsp), $b_ptr
3319 mov $in_x+8*2(%rsp), $acc0
3320 mov $in_x+8*3(%rsp), $acc1
3321 lea $Zsqr(%rsp), $r_ptr
3322 call __ecp_nistz256_sub_from$x # p256_sub(Zsqr, in_x, Zsqr);
3324 `&load_for_sqr("$S(%rsp)", "$src0")`
3326 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(res_y, S);
3329 ######## ecp_nistz256_div_by_2(res_y, res_y); ##########################
3330 # operate in 4-5-6-7 "name space" that matches squaring output
3332 my ($poly1,$poly3)=($a_ptr,$t1);
3333 my ($a0,$a1,$a2,$a3,$t3,$t4,$t1)=($acc4,$acc5,$acc6,$acc7,$acc0,$acc1,$acc2);
3346 xor $a_ptr, $a_ptr # borrow $a_ptr
3355 mov $a1, $t0 # a0:a3>>1
3366 mov $a0, 8*0($r_ptr)
3368 mov $a1, 8*1($r_ptr)
3372 mov $a2, 8*2($r_ptr)
3373 mov $a3, 8*3($r_ptr)
3377 `&load_for_mul("$M(%rsp)", "$Zsqr(%rsp)", "$src0")`
3378 lea $M(%rsp), $r_ptr
3379 call __ecp_nistz256_mul_mont$x # p256_mul_mont(M, M, Zsqr);
3381 lea $tmp0(%rsp), $r_ptr
3382 call __ecp_nistz256_mul_by_2$x
3384 lea $M(%rsp), $b_ptr
3385 lea $M(%rsp), $r_ptr
3386 call __ecp_nistz256_add_to$x # p256_mul_by_3(M, M);
3388 `&load_for_mul("$S(%rsp)", "$in_x(%rsp)", "$src0")`
3389 lea $S(%rsp), $r_ptr
3390 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S, S, in_x);
3392 lea $tmp0(%rsp), $r_ptr
3393 call __ecp_nistz256_mul_by_2$x # p256_mul_by_2(tmp0, S);
3395 `&load_for_sqr("$M(%rsp)", "$src0")`
3397 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(res_x, M);
3399 lea $tmp0(%rsp), $b_ptr
3400 mov $acc6, $acc0 # harmonize sqr output and sub input
3404 call __ecp_nistz256_sub_from$x # p256_sub(res_x, res_x, tmp0);
3406 mov $S+8*0(%rsp), $t0
3407 mov $S+8*1(%rsp), $t1
3408 mov $S+8*2(%rsp), $t2
3409 mov $S+8*3(%rsp), $acc2 # "4-5-0-1" order
3410 lea $S(%rsp), $r_ptr
3411 call __ecp_nistz256_sub$x # p256_sub(S, S, res_x);
3414 lea $M(%rsp), $b_ptr
3415 mov $acc4, $acc6 # harmonize sub output and mul input
3417 mov $acc4, $S+8*0(%rsp) # have to save:-(
3419 mov $acc5, $S+8*1(%rsp)
3421 mov $acc0, $S+8*2(%rsp)
3422 lea $S-$bias(%rsp), $a_ptr
3424 mov $acc1, $S+8*3(%rsp)
3426 lea $S(%rsp), $r_ptr
3427 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S, S, M);
3431 call __ecp_nistz256_sub_from$x # p256_sub(res_y, S, res_y);
3433 lea 32*5+56(%rsp), %rsi
3448 .cfi_def_cfa_register %rsp
3449 .Lpoint_double${x}_epilogue:
3452 .size ecp_nistz256_point_double$sfx,.-ecp_nistz256_point_double$sfx
3459 my ($src0,$sfx,$bias);
3460 my ($H,$Hsqr,$R,$Rsqr,$Hcub,
3462 $res_x,$res_y,$res_z,
3463 $in1_x,$in1_y,$in1_z,
3464 $in2_x,$in2_y,$in2_z)=map(32*$_,(0..17));
3465 my ($Z1sqr, $Z2sqr) = ($Hsqr, $Rsqr);
3473 .globl ecp_nistz256_point_add
3474 .type ecp_nistz256_point_add,\@function,3
3476 ecp_nistz256_point_add:
3479 $code.=<<___ if ($addx);
3481 and OPENSSL_ia32cap_P+8(%rip), %ecx
3491 .type ecp_nistz256_point_addx,\@function,3
3493 ecp_nistz256_point_addx:
3512 .cfi_adjust_cfa_offset 32*18+8
3513 .Lpoint_add${x}_body:
3515 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$a_ptr
3516 movdqu 0x10($a_ptr), %xmm1
3517 movdqu 0x20($a_ptr), %xmm2
3518 movdqu 0x30($a_ptr), %xmm3
3519 movdqu 0x40($a_ptr), %xmm4
3520 movdqu 0x50($a_ptr), %xmm5
3521 mov $a_ptr, $b_ptr # reassign
3522 mov $b_org, $a_ptr # reassign
3523 movdqa %xmm0, $in1_x(%rsp)
3524 movdqa %xmm1, $in1_x+0x10(%rsp)
3525 movdqa %xmm2, $in1_y(%rsp)
3526 movdqa %xmm3, $in1_y+0x10(%rsp)
3527 movdqa %xmm4, $in1_z(%rsp)
3528 movdqa %xmm5, $in1_z+0x10(%rsp)
3531 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$b_ptr
3532 pshufd \$0xb1, %xmm5, %xmm3
3533 movdqu 0x10($a_ptr), %xmm1
3534 movdqu 0x20($a_ptr), %xmm2
3536 movdqu 0x30($a_ptr), %xmm3
3537 mov 0x40+8*0($a_ptr), $src0 # load original in2_z
3538 mov 0x40+8*1($a_ptr), $acc6
3539 mov 0x40+8*2($a_ptr), $acc7
3540 mov 0x40+8*3($a_ptr), $acc0
3541 movdqa %xmm0, $in2_x(%rsp)
3542 pshufd \$0x1e, %xmm5, %xmm4
3543 movdqa %xmm1, $in2_x+0x10(%rsp)
3544 movdqu 0x40($a_ptr),%xmm0 # in2_z again
3545 movdqu 0x50($a_ptr),%xmm1
3546 movdqa %xmm2, $in2_y(%rsp)
3547 movdqa %xmm3, $in2_y+0x10(%rsp)
3551 movq $r_ptr, %xmm0 # save $r_ptr
3553 lea 0x40-$bias($a_ptr), $a_ptr # $a_ptr is still valid
3554 mov $src0, $in2_z+8*0(%rsp) # make in2_z copy
3555 mov $acc6, $in2_z+8*1(%rsp)
3556 mov $acc7, $in2_z+8*2(%rsp)
3557 mov $acc0, $in2_z+8*3(%rsp)
3558 lea $Z2sqr(%rsp), $r_ptr # Z2^2
3559 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Z2sqr, in2_z);
3561 pcmpeqd %xmm4, %xmm5
3562 pshufd \$0xb1, %xmm1, %xmm4
3564 pshufd \$0, %xmm5, %xmm5 # in1infty
3565 pshufd \$0x1e, %xmm4, %xmm3
3568 pcmpeqd %xmm3, %xmm4
3569 pshufd \$0, %xmm4, %xmm4 # in2infty
3570 mov 0x40+8*0($b_ptr), $src0 # load original in1_z
3571 mov 0x40+8*1($b_ptr), $acc6
3572 mov 0x40+8*2($b_ptr), $acc7
3573 mov 0x40+8*3($b_ptr), $acc0
3576 lea 0x40-$bias($b_ptr), $a_ptr
3577 lea $Z1sqr(%rsp), $r_ptr # Z1^2
3578 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Z1sqr, in1_z);
3580 `&load_for_mul("$Z2sqr(%rsp)", "$in2_z(%rsp)", "$src0")`
3581 lea $S1(%rsp), $r_ptr # S1 = Z2^3
3582 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S1, Z2sqr, in2_z);
3584 `&load_for_mul("$Z1sqr(%rsp)", "$in1_z(%rsp)", "$src0")`
3585 lea $S2(%rsp), $r_ptr # S2 = Z1^3
3586 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, Z1sqr, in1_z);
3588 `&load_for_mul("$S1(%rsp)", "$in1_y(%rsp)", "$src0")`
3589 lea $S1(%rsp), $r_ptr # S1 = Y1*Z2^3
3590 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S1, S1, in1_y);
3592 `&load_for_mul("$S2(%rsp)", "$in2_y(%rsp)", "$src0")`
3593 lea $S2(%rsp), $r_ptr # S2 = Y2*Z1^3
3594 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, S2, in2_y);
3596 lea $S1(%rsp), $b_ptr
3597 lea $R(%rsp), $r_ptr # R = S2 - S1
3598 call __ecp_nistz256_sub_from$x # p256_sub(R, S2, S1);
3600 or $acc5, $acc4 # see if result is zero
3604 por %xmm5, %xmm2 # in1infty || in2infty
3607 `&load_for_mul("$Z2sqr(%rsp)", "$in1_x(%rsp)", "$src0")`
3608 lea $U1(%rsp), $r_ptr # U1 = X1*Z2^2
3609 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U1, in1_x, Z2sqr);
3611 `&load_for_mul("$Z1sqr(%rsp)", "$in2_x(%rsp)", "$src0")`
3612 lea $U2(%rsp), $r_ptr # U2 = X2*Z1^2
3613 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, in2_x, Z1sqr);
3615 lea $U1(%rsp), $b_ptr
3616 lea $H(%rsp), $r_ptr # H = U2 - U1
3617 call __ecp_nistz256_sub_from$x # p256_sub(H, U2, U1);
3619 or $acc5, $acc4 # see if result is zero
3623 .byte 0x3e # predict taken
3624 jnz .Ladd_proceed$x # is_equal(U1,U2)?
3628 jnz .Ladd_proceed$x # (in1infty || in2infty)?
3630 jz .Ladd_double$x # is_equal(S1,S2)?
3632 movq %xmm0, $r_ptr # restore $r_ptr
3634 movdqu %xmm0, 0x00($r_ptr)
3635 movdqu %xmm0, 0x10($r_ptr)
3636 movdqu %xmm0, 0x20($r_ptr)
3637 movdqu %xmm0, 0x30($r_ptr)
3638 movdqu %xmm0, 0x40($r_ptr)
3639 movdqu %xmm0, 0x50($r_ptr)
3644 movq %xmm1, $a_ptr # restore $a_ptr
3645 movq %xmm0, $r_ptr # restore $r_ptr
3646 add \$`32*(18-5)`, %rsp # difference in frame sizes
3647 .cfi_adjust_cfa_offset `-32*(18-5)`
3648 jmp .Lpoint_double_shortcut$x
3649 .cfi_adjust_cfa_offset `32*(18-5)`
3653 `&load_for_sqr("$R(%rsp)", "$src0")`
3654 lea $Rsqr(%rsp), $r_ptr # R^2
3655 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Rsqr, R);
3657 `&load_for_mul("$H(%rsp)", "$in1_z(%rsp)", "$src0")`
3658 lea $res_z(%rsp), $r_ptr # Z3 = H*Z1*Z2
3659 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, H, in1_z);
3661 `&load_for_sqr("$H(%rsp)", "$src0")`
3662 lea $Hsqr(%rsp), $r_ptr # H^2
3663 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Hsqr, H);
3665 `&load_for_mul("$res_z(%rsp)", "$in2_z(%rsp)", "$src0")`
3666 lea $res_z(%rsp), $r_ptr # Z3 = H*Z1*Z2
3667 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, res_z, in2_z);
3669 `&load_for_mul("$Hsqr(%rsp)", "$H(%rsp)", "$src0")`
3670 lea $Hcub(%rsp), $r_ptr # H^3
3671 call __ecp_nistz256_mul_mont$x # p256_mul_mont(Hcub, Hsqr, H);
3673 `&load_for_mul("$Hsqr(%rsp)", "$U1(%rsp)", "$src0")`
3674 lea $U2(%rsp), $r_ptr # U1*H^2
3675 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, U1, Hsqr);
3678 #######################################################################
3679 # operate in 4-5-0-1 "name space" that matches multiplication output
3681 my ($acc0,$acc1,$acc2,$acc3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
3682 my ($poly1, $poly3)=($acc6,$acc7);
3685 #lea $U2(%rsp), $a_ptr
3686 #lea $Hsqr(%rsp), $r_ptr # 2*U1*H^2
3687 #call __ecp_nistz256_mul_by_2 # ecp_nistz256_mul_by_2(Hsqr, U2);
3690 add $acc0, $acc0 # a0:a3+a0:a3
3691 lea $Rsqr(%rsp), $a_ptr
3708 mov 8*0($a_ptr), $t0
3710 mov 8*1($a_ptr), $t1
3712 mov 8*2($a_ptr), $t2
3714 mov 8*3($a_ptr), $t3
3716 call __ecp_nistz256_sub$x # p256_sub(res_x, Rsqr, Hsqr);
3718 lea $Hcub(%rsp), $b_ptr
3719 lea $res_x(%rsp), $r_ptr
3720 call __ecp_nistz256_sub_from$x # p256_sub(res_x, res_x, Hcub);
3722 mov $U2+8*0(%rsp), $t0
3723 mov $U2+8*1(%rsp), $t1
3724 mov $U2+8*2(%rsp), $t2
3725 mov $U2+8*3(%rsp), $t3
3726 lea $res_y(%rsp), $r_ptr
3728 call __ecp_nistz256_sub$x # p256_sub(res_y, U2, res_x);
3730 mov $acc0, 8*0($r_ptr) # save the result, as
3731 mov $acc1, 8*1($r_ptr) # __ecp_nistz256_sub doesn't
3732 mov $acc2, 8*2($r_ptr)
3733 mov $acc3, 8*3($r_ptr)
3737 `&load_for_mul("$S1(%rsp)", "$Hcub(%rsp)", "$src0")`
3738 lea $S2(%rsp), $r_ptr
3739 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, S1, Hcub);
3741 `&load_for_mul("$R(%rsp)", "$res_y(%rsp)", "$src0")`
3742 lea $res_y(%rsp), $r_ptr
3743 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_y, R, res_y);
3745 lea $S2(%rsp), $b_ptr
3746 lea $res_y(%rsp), $r_ptr
3747 call __ecp_nistz256_sub_from$x # p256_sub(res_y, res_y, S2);
3749 movq %xmm0, $r_ptr # restore $r_ptr
3751 movdqa %xmm5, %xmm0 # copy_conditional(res_z, in2_z, in1infty);
3753 pandn $res_z(%rsp), %xmm0
3755 pandn $res_z+0x10(%rsp), %xmm1
3757 pand $in2_z(%rsp), %xmm2
3758 pand $in2_z+0x10(%rsp), %xmm3
3762 movdqa %xmm4, %xmm0 # copy_conditional(res_z, in1_z, in2infty);
3768 pand $in1_z(%rsp), %xmm2
3769 pand $in1_z+0x10(%rsp), %xmm3
3772 movdqu %xmm2, 0x40($r_ptr)
3773 movdqu %xmm3, 0x50($r_ptr)
3775 movdqa %xmm5, %xmm0 # copy_conditional(res_x, in2_x, in1infty);
3777 pandn $res_x(%rsp), %xmm0
3779 pandn $res_x+0x10(%rsp), %xmm1
3781 pand $in2_x(%rsp), %xmm2
3782 pand $in2_x+0x10(%rsp), %xmm3
3786 movdqa %xmm4, %xmm0 # copy_conditional(res_x, in1_x, in2infty);
3792 pand $in1_x(%rsp), %xmm2
3793 pand $in1_x+0x10(%rsp), %xmm3
3796 movdqu %xmm2, 0x00($r_ptr)
3797 movdqu %xmm3, 0x10($r_ptr)
3799 movdqa %xmm5, %xmm0 # copy_conditional(res_y, in2_y, in1infty);
3801 pandn $res_y(%rsp), %xmm0
3803 pandn $res_y+0x10(%rsp), %xmm1
3805 pand $in2_y(%rsp), %xmm2
3806 pand $in2_y+0x10(%rsp), %xmm3
3810 movdqa %xmm4, %xmm0 # copy_conditional(res_y, in1_y, in2infty);
3816 pand $in1_y(%rsp), %xmm2
3817 pand $in1_y+0x10(%rsp), %xmm3
3820 movdqu %xmm2, 0x20($r_ptr)
3821 movdqu %xmm3, 0x30($r_ptr)
3824 lea 32*18+56(%rsp), %rsi
3839 .cfi_def_cfa_register %rsp
3840 .Lpoint_add${x}_epilogue:
3843 .size ecp_nistz256_point_add$sfx,.-ecp_nistz256_point_add$sfx
3848 sub gen_add_affine () {
3850 my ($src0,$sfx,$bias);
3851 my ($U2,$S2,$H,$R,$Hsqr,$Hcub,$Rsqr,
3852 $res_x,$res_y,$res_z,
3853 $in1_x,$in1_y,$in1_z,
3854 $in2_x,$in2_y)=map(32*$_,(0..14));
3863 .globl ecp_nistz256_point_add_affine
3864 .type ecp_nistz256_point_add_affine,\@function,3
3866 ecp_nistz256_point_add_affine:
3869 $code.=<<___ if ($addx);
3871 and OPENSSL_ia32cap_P+8(%rip), %ecx
3873 je .Lpoint_add_affinex
3881 .type ecp_nistz256_point_add_affinex,\@function,3
3883 ecp_nistz256_point_add_affinex:
3885 .Lpoint_add_affinex:
3902 .cfi_adjust_cfa_offset 32*15+8
3903 .Ladd_affine${x}_body:
3905 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$a_ptr
3906 mov $b_org, $b_ptr # reassign
3907 movdqu 0x10($a_ptr), %xmm1
3908 movdqu 0x20($a_ptr), %xmm2
3909 movdqu 0x30($a_ptr), %xmm3
3910 movdqu 0x40($a_ptr), %xmm4
3911 movdqu 0x50($a_ptr), %xmm5
3912 mov 0x40+8*0($a_ptr), $src0 # load original in1_z
3913 mov 0x40+8*1($a_ptr), $acc6
3914 mov 0x40+8*2($a_ptr), $acc7
3915 mov 0x40+8*3($a_ptr), $acc0
3916 movdqa %xmm0, $in1_x(%rsp)
3917 movdqa %xmm1, $in1_x+0x10(%rsp)
3918 movdqa %xmm2, $in1_y(%rsp)
3919 movdqa %xmm3, $in1_y+0x10(%rsp)
3920 movdqa %xmm4, $in1_z(%rsp)
3921 movdqa %xmm5, $in1_z+0x10(%rsp)
3924 movdqu 0x00($b_ptr), %xmm0 # copy *(P256_POINT_AFFINE *)$b_ptr
3925 pshufd \$0xb1, %xmm5, %xmm3
3926 movdqu 0x10($b_ptr), %xmm1
3927 movdqu 0x20($b_ptr), %xmm2
3929 movdqu 0x30($b_ptr), %xmm3
3930 movdqa %xmm0, $in2_x(%rsp)
3931 pshufd \$0x1e, %xmm5, %xmm4
3932 movdqa %xmm1, $in2_x+0x10(%rsp)
3934 movq $r_ptr, %xmm0 # save $r_ptr
3935 movdqa %xmm2, $in2_y(%rsp)
3936 movdqa %xmm3, $in2_y+0x10(%rsp)
3942 lea 0x40-$bias($a_ptr), $a_ptr # $a_ptr is still valid
3943 lea $Z1sqr(%rsp), $r_ptr # Z1^2
3944 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Z1sqr, in1_z);
3946 pcmpeqd %xmm4, %xmm5
3947 pshufd \$0xb1, %xmm3, %xmm4
3948 mov 0x00($b_ptr), $src0 # $b_ptr is still valid
3949 #lea 0x00($b_ptr), $b_ptr
3950 mov $acc4, $acc1 # harmonize sqr output and mul input
3952 pshufd \$0, %xmm5, %xmm5 # in1infty
3953 pshufd \$0x1e, %xmm4, %xmm3
3958 pcmpeqd %xmm3, %xmm4
3959 pshufd \$0, %xmm4, %xmm4 # in2infty
3961 lea $Z1sqr-$bias(%rsp), $a_ptr
3963 lea $U2(%rsp), $r_ptr # U2 = X2*Z1^2
3964 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, Z1sqr, in2_x);
3966 lea $in1_x(%rsp), $b_ptr
3967 lea $H(%rsp), $r_ptr # H = U2 - U1
3968 call __ecp_nistz256_sub_from$x # p256_sub(H, U2, in1_x);
3970 `&load_for_mul("$Z1sqr(%rsp)", "$in1_z(%rsp)", "$src0")`
3971 lea $S2(%rsp), $r_ptr # S2 = Z1^3
3972 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, Z1sqr, in1_z);
3974 `&load_for_mul("$H(%rsp)", "$in1_z(%rsp)", "$src0")`
3975 lea $res_z(%rsp), $r_ptr # Z3 = H*Z1*Z2
3976 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, H, in1_z);
3978 `&load_for_mul("$S2(%rsp)", "$in2_y(%rsp)", "$src0")`
3979 lea $S2(%rsp), $r_ptr # S2 = Y2*Z1^3
3980 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, S2, in2_y);
3982 lea $in1_y(%rsp), $b_ptr
3983 lea $R(%rsp), $r_ptr # R = S2 - S1
3984 call __ecp_nistz256_sub_from$x # p256_sub(R, S2, in1_y);
3986 `&load_for_sqr("$H(%rsp)", "$src0")`
3987 lea $Hsqr(%rsp), $r_ptr # H^2
3988 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Hsqr, H);
3990 `&load_for_sqr("$R(%rsp)", "$src0")`
3991 lea $Rsqr(%rsp), $r_ptr # R^2
3992 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Rsqr, R);
3994 `&load_for_mul("$H(%rsp)", "$Hsqr(%rsp)", "$src0")`
3995 lea $Hcub(%rsp), $r_ptr # H^3
3996 call __ecp_nistz256_mul_mont$x # p256_mul_mont(Hcub, Hsqr, H);
3998 `&load_for_mul("$Hsqr(%rsp)", "$in1_x(%rsp)", "$src0")`
3999 lea $U2(%rsp), $r_ptr # U1*H^2
4000 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, in1_x, Hsqr);
4003 #######################################################################
4004 # operate in 4-5-0-1 "name space" that matches multiplication output
4006 my ($acc0,$acc1,$acc2,$acc3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
4007 my ($poly1, $poly3)=($acc6,$acc7);
4010 #lea $U2(%rsp), $a_ptr
4011 #lea $Hsqr(%rsp), $r_ptr # 2*U1*H^2
4012 #call __ecp_nistz256_mul_by_2 # ecp_nistz256_mul_by_2(Hsqr, U2);
4015 add $acc0, $acc0 # a0:a3+a0:a3
4016 lea $Rsqr(%rsp), $a_ptr
4033 mov 8*0($a_ptr), $t0
4035 mov 8*1($a_ptr), $t1
4037 mov 8*2($a_ptr), $t2
4039 mov 8*3($a_ptr), $t3
4041 call __ecp_nistz256_sub$x # p256_sub(res_x, Rsqr, Hsqr);
4043 lea $Hcub(%rsp), $b_ptr
4044 lea $res_x(%rsp), $r_ptr
4045 call __ecp_nistz256_sub_from$x # p256_sub(res_x, res_x, Hcub);
4047 mov $U2+8*0(%rsp), $t0
4048 mov $U2+8*1(%rsp), $t1
4049 mov $U2+8*2(%rsp), $t2
4050 mov $U2+8*3(%rsp), $t3
4051 lea $H(%rsp), $r_ptr
4053 call __ecp_nistz256_sub$x # p256_sub(H, U2, res_x);
4055 mov $acc0, 8*0($r_ptr) # save the result, as
4056 mov $acc1, 8*1($r_ptr) # __ecp_nistz256_sub doesn't
4057 mov $acc2, 8*2($r_ptr)
4058 mov $acc3, 8*3($r_ptr)
4062 `&load_for_mul("$Hcub(%rsp)", "$in1_y(%rsp)", "$src0")`
4063 lea $S2(%rsp), $r_ptr
4064 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, Hcub, in1_y);
4066 `&load_for_mul("$H(%rsp)", "$R(%rsp)", "$src0")`
4067 lea $H(%rsp), $r_ptr
4068 call __ecp_nistz256_mul_mont$x # p256_mul_mont(H, H, R);
4070 lea $S2(%rsp), $b_ptr
4071 lea $res_y(%rsp), $r_ptr
4072 call __ecp_nistz256_sub_from$x # p256_sub(res_y, H, S2);
4074 movq %xmm0, $r_ptr # restore $r_ptr
4076 movdqa %xmm5, %xmm0 # copy_conditional(res_z, ONE, in1infty);
4078 pandn $res_z(%rsp), %xmm0
4080 pandn $res_z+0x10(%rsp), %xmm1
4082 pand .LONE_mont(%rip), %xmm2
4083 pand .LONE_mont+0x10(%rip), %xmm3
4087 movdqa %xmm4, %xmm0 # copy_conditional(res_z, in1_z, in2infty);
4093 pand $in1_z(%rsp), %xmm2
4094 pand $in1_z+0x10(%rsp), %xmm3
4097 movdqu %xmm2, 0x40($r_ptr)
4098 movdqu %xmm3, 0x50($r_ptr)
4100 movdqa %xmm5, %xmm0 # copy_conditional(res_x, in2_x, in1infty);
4102 pandn $res_x(%rsp), %xmm0
4104 pandn $res_x+0x10(%rsp), %xmm1
4106 pand $in2_x(%rsp), %xmm2
4107 pand $in2_x+0x10(%rsp), %xmm3
4111 movdqa %xmm4, %xmm0 # copy_conditional(res_x, in1_x, in2infty);
4117 pand $in1_x(%rsp), %xmm2
4118 pand $in1_x+0x10(%rsp), %xmm3
4121 movdqu %xmm2, 0x00($r_ptr)
4122 movdqu %xmm3, 0x10($r_ptr)
4124 movdqa %xmm5, %xmm0 # copy_conditional(res_y, in2_y, in1infty);
4126 pandn $res_y(%rsp), %xmm0
4128 pandn $res_y+0x10(%rsp), %xmm1
4130 pand $in2_y(%rsp), %xmm2
4131 pand $in2_y+0x10(%rsp), %xmm3
4135 movdqa %xmm4, %xmm0 # copy_conditional(res_y, in1_y, in2infty);
4141 pand $in1_y(%rsp), %xmm2
4142 pand $in1_y+0x10(%rsp), %xmm3
4145 movdqu %xmm2, 0x20($r_ptr)
4146 movdqu %xmm3, 0x30($r_ptr)
4148 lea 32*15+56(%rsp), %rsi
4163 .cfi_def_cfa_register %rsp
4164 .Ladd_affine${x}_epilogue:
4167 .size ecp_nistz256_point_add_affine$sfx,.-ecp_nistz256_point_add_affine$sfx
4170 &gen_add_affine("q");
4172 ########################################################################
4176 ########################################################################
4177 # operate in 4-5-0-1 "name space" that matches multiplication output
4179 my ($a0,$a1,$a2,$a3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
4182 .type __ecp_nistz256_add_tox,\@abi-omnipotent
4184 __ecp_nistz256_add_tox:
4187 adc 8*0($b_ptr), $a0
4188 adc 8*1($b_ptr), $a1
4190 adc 8*2($b_ptr), $a2
4191 adc 8*3($b_ptr), $a3
4206 mov $a0, 8*0($r_ptr)
4208 mov $a1, 8*1($r_ptr)
4210 mov $a2, 8*2($r_ptr)
4211 mov $a3, 8*3($r_ptr)
4215 .size __ecp_nistz256_add_tox,.-__ecp_nistz256_add_tox
4217 .type __ecp_nistz256_sub_fromx,\@abi-omnipotent
4219 __ecp_nistz256_sub_fromx:
4222 sbb 8*0($b_ptr), $a0
4223 sbb 8*1($b_ptr), $a1
4225 sbb 8*2($b_ptr), $a2
4226 sbb 8*3($b_ptr), $a3
4241 mov $a0, 8*0($r_ptr)
4243 mov $a1, 8*1($r_ptr)
4245 mov $a2, 8*2($r_ptr)
4246 mov $a3, 8*3($r_ptr)
4250 .size __ecp_nistz256_sub_fromx,.-__ecp_nistz256_sub_fromx
4252 .type __ecp_nistz256_subx,\@abi-omnipotent
4254 __ecp_nistz256_subx:
4281 .size __ecp_nistz256_subx,.-__ecp_nistz256_subx
4283 .type __ecp_nistz256_mul_by_2x,\@abi-omnipotent
4285 __ecp_nistz256_mul_by_2x:
4288 adc $a0, $a0 # a0:a3+a0:a3
4307 mov $a0, 8*0($r_ptr)
4309 mov $a1, 8*1($r_ptr)
4311 mov $a2, 8*2($r_ptr)
4312 mov $a3, 8*3($r_ptr)
4316 .size __ecp_nistz256_mul_by_2x,.-__ecp_nistz256_mul_by_2x
4321 &gen_add_affine("x");
4325 # EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
4326 # CONTEXT *context,DISPATCHER_CONTEXT *disp)
4334 .extern __imp_RtlVirtualUnwind
4336 .type short_handler,\@abi-omnipotent
4350 mov 120($context),%rax # pull context->Rax
4351 mov 248($context),%rbx # pull context->Rip
4353 mov 8($disp),%rsi # disp->ImageBase
4354 mov 56($disp),%r11 # disp->HandlerData
4356 mov 0(%r11),%r10d # HandlerData[0]
4357 lea (%rsi,%r10),%r10 # end of prologue label
4358 cmp %r10,%rbx # context->Rip<end of prologue label
4359 jb .Lcommon_seh_tail
4361 mov 152($context),%rax # pull context->Rsp
4363 mov 4(%r11),%r10d # HandlerData[1]
4364 lea (%rsi,%r10),%r10 # epilogue label
4365 cmp %r10,%rbx # context->Rip>=epilogue label
4366 jae .Lcommon_seh_tail
4372 mov %r12,216($context) # restore context->R12
4373 mov %r13,224($context) # restore context->R13
4375 jmp .Lcommon_seh_tail
4376 .size short_handler,.-short_handler
4378 .type full_handler,\@abi-omnipotent
4392 mov 120($context),%rax # pull context->Rax
4393 mov 248($context),%rbx # pull context->Rip
4395 mov 8($disp),%rsi # disp->ImageBase
4396 mov 56($disp),%r11 # disp->HandlerData
4398 mov 0(%r11),%r10d # HandlerData[0]
4399 lea (%rsi,%r10),%r10 # end of prologue label
4400 cmp %r10,%rbx # context->Rip<end of prologue label
4401 jb .Lcommon_seh_tail
4403 mov 152($context),%rax # pull context->Rsp
4405 mov 4(%r11),%r10d # HandlerData[1]
4406 lea (%rsi,%r10),%r10 # epilogue label
4407 cmp %r10,%rbx # context->Rip>=epilogue label
4408 jae .Lcommon_seh_tail
4410 mov 8(%r11),%r10d # HandlerData[2]
4411 lea (%rax,%r10),%rax
4419 mov %rbx,144($context) # restore context->Rbx
4420 mov %rbp,160($context) # restore context->Rbp
4421 mov %r12,216($context) # restore context->R12
4422 mov %r13,224($context) # restore context->R13
4423 mov %r14,232($context) # restore context->R14
4424 mov %r15,240($context) # restore context->R15
4429 mov %rax,152($context) # restore context->Rsp
4430 mov %rsi,168($context) # restore context->Rsi
4431 mov %rdi,176($context) # restore context->Rdi
4433 mov 40($disp),%rdi # disp->ContextRecord
4434 mov $context,%rsi # context
4435 mov \$154,%ecx # sizeof(CONTEXT)
4436 .long 0xa548f3fc # cld; rep movsq
4439 xor %rcx,%rcx # arg1, UNW_FLAG_NHANDLER
4440 mov 8(%rsi),%rdx # arg2, disp->ImageBase
4441 mov 0(%rsi),%r8 # arg3, disp->ControlPc
4442 mov 16(%rsi),%r9 # arg4, disp->FunctionEntry
4443 mov 40(%rsi),%r10 # disp->ContextRecord
4444 lea 56(%rsi),%r11 # &disp->HandlerData
4445 lea 24(%rsi),%r12 # &disp->EstablisherFrame
4446 mov %r10,32(%rsp) # arg5
4447 mov %r11,40(%rsp) # arg6
4448 mov %r12,48(%rsp) # arg7
4449 mov %rcx,56(%rsp) # arg8, (NULL)
4450 call *__imp_RtlVirtualUnwind(%rip)
4452 mov \$1,%eax # ExceptionContinueSearch
4464 .size full_handler,.-full_handler
4468 .rva .LSEH_begin_ecp_nistz256_mul_by_2
4469 .rva .LSEH_end_ecp_nistz256_mul_by_2
4470 .rva .LSEH_info_ecp_nistz256_mul_by_2
4472 .rva .LSEH_begin_ecp_nistz256_div_by_2
4473 .rva .LSEH_end_ecp_nistz256_div_by_2
4474 .rva .LSEH_info_ecp_nistz256_div_by_2
4476 .rva .LSEH_begin_ecp_nistz256_mul_by_3
4477 .rva .LSEH_end_ecp_nistz256_mul_by_3
4478 .rva .LSEH_info_ecp_nistz256_mul_by_3
4480 .rva .LSEH_begin_ecp_nistz256_add
4481 .rva .LSEH_end_ecp_nistz256_add
4482 .rva .LSEH_info_ecp_nistz256_add
4484 .rva .LSEH_begin_ecp_nistz256_sub
4485 .rva .LSEH_end_ecp_nistz256_sub
4486 .rva .LSEH_info_ecp_nistz256_sub
4488 .rva .LSEH_begin_ecp_nistz256_neg
4489 .rva .LSEH_end_ecp_nistz256_neg
4490 .rva .LSEH_info_ecp_nistz256_neg
4492 .rva .LSEH_begin_ecp_nistz256_ord_mul_mont
4493 .rva .LSEH_end_ecp_nistz256_ord_mul_mont
4494 .rva .LSEH_info_ecp_nistz256_ord_mul_mont
4496 .rva .LSEH_begin_ecp_nistz256_ord_sqr_mont
4497 .rva .LSEH_end_ecp_nistz256_ord_sqr_mont
4498 .rva .LSEH_info_ecp_nistz256_ord_sqr_mont
4500 $code.=<<___ if ($addx);
4501 .rva .LSEH_begin_ecp_nistz256_ord_mul_montx
4502 .rva .LSEH_end_ecp_nistz256_ord_mul_montx
4503 .rva .LSEH_info_ecp_nistz256_ord_mul_montx
4505 .rva .LSEH_begin_ecp_nistz256_ord_sqr_montx
4506 .rva .LSEH_end_ecp_nistz256_ord_sqr_montx
4507 .rva .LSEH_info_ecp_nistz256_ord_sqr_montx
4510 .rva .LSEH_begin_ecp_nistz256_to_mont
4511 .rva .LSEH_end_ecp_nistz256_to_mont
4512 .rva .LSEH_info_ecp_nistz256_to_mont
4514 .rva .LSEH_begin_ecp_nistz256_mul_mont
4515 .rva .LSEH_end_ecp_nistz256_mul_mont
4516 .rva .LSEH_info_ecp_nistz256_mul_mont
4518 .rva .LSEH_begin_ecp_nistz256_sqr_mont
4519 .rva .LSEH_end_ecp_nistz256_sqr_mont
4520 .rva .LSEH_info_ecp_nistz256_sqr_mont
4522 .rva .LSEH_begin_ecp_nistz256_from_mont
4523 .rva .LSEH_end_ecp_nistz256_from_mont
4524 .rva .LSEH_info_ecp_nistz256_from_mont
4526 .rva .LSEH_begin_ecp_nistz256_gather_w5
4527 .rva .LSEH_end_ecp_nistz256_gather_w5
4528 .rva .LSEH_info_ecp_nistz256_gather_wX
4530 .rva .LSEH_begin_ecp_nistz256_gather_w7
4531 .rva .LSEH_end_ecp_nistz256_gather_w7
4532 .rva .LSEH_info_ecp_nistz256_gather_wX
4534 $code.=<<___ if ($avx>1);
4535 .rva .LSEH_begin_ecp_nistz256_avx2_gather_w5
4536 .rva .LSEH_end_ecp_nistz256_avx2_gather_w5
4537 .rva .LSEH_info_ecp_nistz256_avx2_gather_wX
4539 .rva .LSEH_begin_ecp_nistz256_avx2_gather_w7
4540 .rva .LSEH_end_ecp_nistz256_avx2_gather_w7
4541 .rva .LSEH_info_ecp_nistz256_avx2_gather_wX
4544 .rva .LSEH_begin_ecp_nistz256_point_double
4545 .rva .LSEH_end_ecp_nistz256_point_double
4546 .rva .LSEH_info_ecp_nistz256_point_double
4548 .rva .LSEH_begin_ecp_nistz256_point_add
4549 .rva .LSEH_end_ecp_nistz256_point_add
4550 .rva .LSEH_info_ecp_nistz256_point_add
4552 .rva .LSEH_begin_ecp_nistz256_point_add_affine
4553 .rva .LSEH_end_ecp_nistz256_point_add_affine
4554 .rva .LSEH_info_ecp_nistz256_point_add_affine
4556 $code.=<<___ if ($addx);
4557 .rva .LSEH_begin_ecp_nistz256_point_doublex
4558 .rva .LSEH_end_ecp_nistz256_point_doublex
4559 .rva .LSEH_info_ecp_nistz256_point_doublex
4561 .rva .LSEH_begin_ecp_nistz256_point_addx
4562 .rva .LSEH_end_ecp_nistz256_point_addx
4563 .rva .LSEH_info_ecp_nistz256_point_addx
4565 .rva .LSEH_begin_ecp_nistz256_point_add_affinex
4566 .rva .LSEH_end_ecp_nistz256_point_add_affinex
4567 .rva .LSEH_info_ecp_nistz256_point_add_affinex
4573 .LSEH_info_ecp_nistz256_mul_by_2:
4576 .rva .Lmul_by_2_body,.Lmul_by_2_epilogue # HandlerData[]
4577 .LSEH_info_ecp_nistz256_div_by_2:
4580 .rva .Ldiv_by_2_body,.Ldiv_by_2_epilogue # HandlerData[]
4581 .LSEH_info_ecp_nistz256_mul_by_3:
4584 .rva .Lmul_by_3_body,.Lmul_by_3_epilogue # HandlerData[]
4585 .LSEH_info_ecp_nistz256_add:
4588 .rva .Ladd_body,.Ladd_epilogue # HandlerData[]
4589 .LSEH_info_ecp_nistz256_sub:
4592 .rva .Lsub_body,.Lsub_epilogue # HandlerData[]
4593 .LSEH_info_ecp_nistz256_neg:
4596 .rva .Lneg_body,.Lneg_epilogue # HandlerData[]
4597 .LSEH_info_ecp_nistz256_ord_mul_mont:
4600 .rva .Lord_mul_body,.Lord_mul_epilogue # HandlerData[]
4602 .LSEH_info_ecp_nistz256_ord_sqr_mont:
4605 .rva .Lord_sqr_body,.Lord_sqr_epilogue # HandlerData[]
4608 $code.=<<___ if ($addx);
4609 .LSEH_info_ecp_nistz256_ord_mul_montx:
4612 .rva .Lord_mulx_body,.Lord_mulx_epilogue # HandlerData[]
4614 .LSEH_info_ecp_nistz256_ord_sqr_montx:
4617 .rva .Lord_sqrx_body,.Lord_sqrx_epilogue # HandlerData[]
4621 .LSEH_info_ecp_nistz256_to_mont:
4624 .rva .Lmul_body,.Lmul_epilogue # HandlerData[]
4626 .LSEH_info_ecp_nistz256_mul_mont:
4629 .rva .Lmul_body,.Lmul_epilogue # HandlerData[]
4631 .LSEH_info_ecp_nistz256_sqr_mont:
4634 .rva .Lsqr_body,.Lsqr_epilogue # HandlerData[]
4636 .LSEH_info_ecp_nistz256_from_mont:
4639 .rva .Lfrom_body,.Lfrom_epilogue # HandlerData[]
4640 .LSEH_info_ecp_nistz256_gather_wX:
4641 .byte 0x01,0x33,0x16,0x00
4642 .byte 0x33,0xf8,0x09,0x00 #movaps 0x90(rsp),xmm15
4643 .byte 0x2e,0xe8,0x08,0x00 #movaps 0x80(rsp),xmm14
4644 .byte 0x29,0xd8,0x07,0x00 #movaps 0x70(rsp),xmm13
4645 .byte 0x24,0xc8,0x06,0x00 #movaps 0x60(rsp),xmm12
4646 .byte 0x1f,0xb8,0x05,0x00 #movaps 0x50(rsp),xmm11
4647 .byte 0x1a,0xa8,0x04,0x00 #movaps 0x40(rsp),xmm10
4648 .byte 0x15,0x98,0x03,0x00 #movaps 0x30(rsp),xmm9
4649 .byte 0x10,0x88,0x02,0x00 #movaps 0x20(rsp),xmm8
4650 .byte 0x0c,0x78,0x01,0x00 #movaps 0x10(rsp),xmm7
4651 .byte 0x08,0x68,0x00,0x00 #movaps 0x00(rsp),xmm6
4652 .byte 0x04,0x01,0x15,0x00 #sub rsp,0xa8
4655 $code.=<<___ if ($avx>1);
4656 .LSEH_info_ecp_nistz256_avx2_gather_wX:
4657 .byte 0x01,0x36,0x17,0x0b
4658 .byte 0x36,0xf8,0x09,0x00 # vmovaps 0x90(rsp),xmm15
4659 .byte 0x31,0xe8,0x08,0x00 # vmovaps 0x80(rsp),xmm14
4660 .byte 0x2c,0xd8,0x07,0x00 # vmovaps 0x70(rsp),xmm13
4661 .byte 0x27,0xc8,0x06,0x00 # vmovaps 0x60(rsp),xmm12
4662 .byte 0x22,0xb8,0x05,0x00 # vmovaps 0x50(rsp),xmm11
4663 .byte 0x1d,0xa8,0x04,0x00 # vmovaps 0x40(rsp),xmm10
4664 .byte 0x18,0x98,0x03,0x00 # vmovaps 0x30(rsp),xmm9
4665 .byte 0x13,0x88,0x02,0x00 # vmovaps 0x20(rsp),xmm8
4666 .byte 0x0e,0x78,0x01,0x00 # vmovaps 0x10(rsp),xmm7
4667 .byte 0x09,0x68,0x00,0x00 # vmovaps 0x00(rsp),xmm6
4668 .byte 0x04,0x01,0x15,0x00 # sub rsp,0xa8
4669 .byte 0x00,0xb3,0x00,0x00 # set_frame r11
4673 .LSEH_info_ecp_nistz256_point_double:
4676 .rva .Lpoint_doubleq_body,.Lpoint_doubleq_epilogue # HandlerData[]
4678 .LSEH_info_ecp_nistz256_point_add:
4681 .rva .Lpoint_addq_body,.Lpoint_addq_epilogue # HandlerData[]
4683 .LSEH_info_ecp_nistz256_point_add_affine:
4686 .rva .Ladd_affineq_body,.Ladd_affineq_epilogue # HandlerData[]
4689 $code.=<<___ if ($addx);
4691 .LSEH_info_ecp_nistz256_point_doublex:
4694 .rva .Lpoint_doublex_body,.Lpoint_doublex_epilogue # HandlerData[]
4696 .LSEH_info_ecp_nistz256_point_addx:
4699 .rva .Lpoint_addx_body,.Lpoint_addx_epilogue # HandlerData[]
4701 .LSEH_info_ecp_nistz256_point_add_affinex:
4704 .rva .Ladd_affinex_body,.Ladd_affinex_epilogue # HandlerData[]
4709 ########################################################################
4710 # Convert ecp_nistz256_table.c to layout expected by ecp_nistz_gather_w7
4712 open TABLE,"<ecp_nistz256_table.c" or
4713 open TABLE,"<${dir}../ecp_nistz256_table.c" or
4714 die "failed to open ecp_nistz256_table.c:",$!;
4719 s/TOBN\(\s*(0x[0-9a-f]+),\s*(0x[0-9a-f]+)\s*\)/push @arr,hex($2),hex($1)/geo;
4723 die "insane number of elements" if ($#arr != 64*16*37-1);
4727 .globl ecp_nistz256_precomputed
4728 .type ecp_nistz256_precomputed,\@object
4730 ecp_nistz256_precomputed:
4732 while (@line=splice(@arr,0,16)) {
4733 print ".long\t",join(',',map { sprintf "0x%08x",$_} @line),"\n";
4736 .size ecp_nistz256_precomputed,.-ecp_nistz256_precomputed
4739 $code =~ s/\`([^\`]*)\`/eval $1/gem;