2 # Copyright 2014-2020 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) ([0-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:
1584 $code.=<<___ if ($addx);
1586 and OPENSSL_ia32cap_P+8(%rip), %ecx
1589 lea .LRR(%rip), $b_org
1592 .size ecp_nistz256_to_mont,.-ecp_nistz256_to_mont
1594 ################################################################################
1595 # void ecp_nistz256_mul_mont(
1600 .globl ecp_nistz256_mul_mont
1601 .type ecp_nistz256_mul_mont,\@function,3
1603 ecp_nistz256_mul_mont:
1606 $code.=<<___ if ($addx);
1608 and OPENSSL_ia32cap_P+8(%rip), %ecx
1626 $code.=<<___ if ($addx);
1632 mov 8*0($b_org), %rax
1633 mov 8*0($a_ptr), $acc1
1634 mov 8*1($a_ptr), $acc2
1635 mov 8*2($a_ptr), $acc3
1636 mov 8*3($a_ptr), $acc4
1638 call __ecp_nistz256_mul_montq
1640 $code.=<<___ if ($addx);
1646 mov 8*0($b_org), %rdx
1647 mov 8*0($a_ptr), $acc1
1648 mov 8*1($a_ptr), $acc2
1649 mov 8*2($a_ptr), $acc3
1650 mov 8*3($a_ptr), $acc4
1651 lea -128($a_ptr), $a_ptr # control u-op density
1653 call __ecp_nistz256_mul_montx
1670 .cfi_adjust_cfa_offset -48
1674 .size ecp_nistz256_mul_mont,.-ecp_nistz256_mul_mont
1676 .type __ecp_nistz256_mul_montq,\@abi-omnipotent
1678 __ecp_nistz256_mul_montq:
1680 ########################################################################
1681 # Multiply a by b[0]
1684 mov .Lpoly+8*1(%rip),$poly1
1690 mov .Lpoly+8*3(%rip),$poly3
1709 ########################################################################
1710 # First reduction step
1711 # Basically now we want to multiply acc[0] by p256,
1712 # and add the result to the acc.
1713 # Due to the special form of p256 we do some optimizations
1715 # acc[0] x p256[0..1] = acc[0] x 2^96 - acc[0]
1716 # then we add acc[0] and get acc[0] x 2^96
1722 add $acc0, $acc1 # +=acc[0]<<96
1725 mov 8*1($b_ptr), %rax
1730 ########################################################################
1763 ########################################################################
1764 # Second reduction step
1772 mov 8*2($b_ptr), %rax
1777 ########################################################################
1810 ########################################################################
1811 # Third reduction step
1819 mov 8*3($b_ptr), %rax
1824 ########################################################################
1857 ########################################################################
1858 # Final reduction step
1871 ########################################################################
1872 # Branch-less conditional subtraction of P
1873 sub \$-1, $acc4 # .Lpoly[0]
1875 sbb $poly1, $acc5 # .Lpoly[1]
1876 sbb \$0, $acc0 # .Lpoly[2]
1878 sbb $poly3, $acc1 # .Lpoly[3]
1883 mov $acc4, 8*0($r_ptr)
1885 mov $acc5, 8*1($r_ptr)
1887 mov $acc0, 8*2($r_ptr)
1888 mov $acc1, 8*3($r_ptr)
1892 .size __ecp_nistz256_mul_montq,.-__ecp_nistz256_mul_montq
1894 ################################################################################
1895 # void ecp_nistz256_sqr_mont(
1899 # we optimize the square according to S.Gueron and V.Krasnov,
1900 # "Speeding up Big-Number Squaring"
1901 .globl ecp_nistz256_sqr_mont
1902 .type ecp_nistz256_sqr_mont,\@function,2
1904 ecp_nistz256_sqr_mont:
1907 $code.=<<___ if ($addx);
1909 and OPENSSL_ia32cap_P+8(%rip), %ecx
1926 $code.=<<___ if ($addx);
1931 mov 8*0($a_ptr), %rax
1932 mov 8*1($a_ptr), $acc6
1933 mov 8*2($a_ptr), $acc7
1934 mov 8*3($a_ptr), $acc0
1936 call __ecp_nistz256_sqr_montq
1938 $code.=<<___ if ($addx);
1943 mov 8*0($a_ptr), %rdx
1944 mov 8*1($a_ptr), $acc6
1945 mov 8*2($a_ptr), $acc7
1946 mov 8*3($a_ptr), $acc0
1947 lea -128($a_ptr), $a_ptr # control u-op density
1949 call __ecp_nistz256_sqr_montx
1966 .cfi_adjust_cfa_offset -48
1970 .size ecp_nistz256_sqr_mont,.-ecp_nistz256_sqr_mont
1972 .type __ecp_nistz256_sqr_montq,\@abi-omnipotent
1974 __ecp_nistz256_sqr_montq:
1977 mulq $acc6 # a[1]*a[0]
1982 mulq $acc5 # a[0]*a[2]
1988 mulq $acc5 # a[0]*a[3]
1994 #################################
1995 mulq $acc6 # a[1]*a[2]
2001 mulq $acc6 # a[1]*a[3]
2009 #################################
2010 mulq $acc7 # a[2]*a[3]
2013 mov 8*0($a_ptr), %rax
2017 add $acc1, $acc1 # acc1:6<<1
2027 mov 8*1($a_ptr), %rax
2033 mov 8*2($a_ptr), %rax
2040 mov 8*3($a_ptr), %rax
2050 mov .Lpoly+8*1(%rip), $a_ptr
2051 mov .Lpoly+8*3(%rip), $t1
2053 ##########################################
2060 add $acc0, $acc1 # +=acc[0]<<96
2066 ##########################################
2079 ##########################################
2092 ###########################################
2105 ############################################
2106 # Add the rest of the acc
2115 sub \$-1, $acc4 # .Lpoly[0]
2117 sbb $a_ptr, $acc5 # .Lpoly[1]
2118 sbb \$0, $acc6 # .Lpoly[2]
2120 sbb $t1, $acc7 # .Lpoly[3]
2125 mov $acc4, 8*0($r_ptr)
2127 mov $acc5, 8*1($r_ptr)
2129 mov $acc6, 8*2($r_ptr)
2130 mov $acc7, 8*3($r_ptr)
2134 .size __ecp_nistz256_sqr_montq,.-__ecp_nistz256_sqr_montq
2139 .type __ecp_nistz256_mul_montx,\@abi-omnipotent
2141 __ecp_nistz256_mul_montx:
2143 ########################################################################
2145 mulx $acc1, $acc0, $acc1
2146 mulx $acc2, $t0, $acc2
2148 xor $acc5, $acc5 # cf=0
2149 mulx $acc3, $t1, $acc3
2150 mov .Lpoly+8*3(%rip), $poly3
2152 mulx $acc4, $t0, $acc4
2155 shlx $poly1,$acc0,$t1
2157 shrx $poly1,$acc0,$t0
2160 ########################################################################
2161 # First reduction step
2165 mulx $poly3, $t0, $t1
2166 mov 8*1($b_ptr), %rdx
2170 xor $acc0, $acc0 # $acc0=0,cf=0,of=0
2172 ########################################################################
2174 mulx 8*0+128($a_ptr), $t0, $t1
2178 mulx 8*1+128($a_ptr), $t0, $t1
2182 mulx 8*2+128($a_ptr), $t0, $t1
2186 mulx 8*3+128($a_ptr), $t0, $t1
2189 shlx $poly1, $acc1, $t0
2191 shrx $poly1, $acc1, $t1
2197 ########################################################################
2198 # Second reduction step
2202 mulx $poly3, $t0, $t1
2203 mov 8*2($b_ptr), %rdx
2207 xor $acc1 ,$acc1 # $acc1=0,cf=0,of=0
2209 ########################################################################
2211 mulx 8*0+128($a_ptr), $t0, $t1
2215 mulx 8*1+128($a_ptr), $t0, $t1
2219 mulx 8*2+128($a_ptr), $t0, $t1
2223 mulx 8*3+128($a_ptr), $t0, $t1
2226 shlx $poly1, $acc2, $t0
2228 shrx $poly1, $acc2, $t1
2234 ########################################################################
2235 # Third reduction step
2239 mulx $poly3, $t0, $t1
2240 mov 8*3($b_ptr), %rdx
2244 xor $acc2, $acc2 # $acc2=0,cf=0,of=0
2246 ########################################################################
2248 mulx 8*0+128($a_ptr), $t0, $t1
2252 mulx 8*1+128($a_ptr), $t0, $t1
2256 mulx 8*2+128($a_ptr), $t0, $t1
2260 mulx 8*3+128($a_ptr), $t0, $t1
2263 shlx $poly1, $acc3, $t0
2265 shrx $poly1, $acc3, $t1
2271 ########################################################################
2272 # Fourth reduction step
2276 mulx $poly3, $t0, $t1
2278 mov .Lpoly+8*1(%rip), $poly1
2284 ########################################################################
2285 # Branch-less conditional subtraction of P
2288 sbb \$-1, $acc4 # .Lpoly[0]
2289 sbb $poly1, $acc5 # .Lpoly[1]
2290 sbb \$0, $acc0 # .Lpoly[2]
2292 sbb $poly3, $acc1 # .Lpoly[3]
2297 mov $acc4, 8*0($r_ptr)
2299 mov $acc5, 8*1($r_ptr)
2301 mov $acc0, 8*2($r_ptr)
2302 mov $acc1, 8*3($r_ptr)
2306 .size __ecp_nistz256_mul_montx,.-__ecp_nistz256_mul_montx
2308 .type __ecp_nistz256_sqr_montx,\@abi-omnipotent
2310 __ecp_nistz256_sqr_montx:
2312 mulx $acc6, $acc1, $acc2 # a[0]*a[1]
2313 mulx $acc7, $t0, $acc3 # a[0]*a[2]
2316 mulx $acc0, $t1, $acc4 # a[0]*a[3]
2320 xor $acc5, $acc5 # $acc5=0,cf=0,of=0
2322 #################################
2323 mulx $acc7, $t0, $t1 # a[1]*a[2]
2327 mulx $acc0, $t0, $t1 # a[1]*a[3]
2333 #################################
2334 mulx $acc0, $t0, $acc6 # a[2]*a[3]
2335 mov 8*0+128($a_ptr), %rdx
2336 xor $acc7, $acc7 # $acc7=0,cf=0,of=0
2337 adcx $acc1, $acc1 # acc1:6<<1
2340 adox $acc7, $acc6 # of=0
2342 mulx %rdx, $acc0, $t1
2343 mov 8*1+128($a_ptr), %rdx
2348 mov 8*2+128($a_ptr), %rdx
2354 mov 8*3+128($a_ptr), %rdx
2362 mov .Lpoly+8*3(%rip), %rdx
2364 shlx $a_ptr, $acc0, $t0
2366 shrx $a_ptr, $acc0, $t4
2373 mulx $acc0, $t0, $acc0
2375 shlx $a_ptr, $acc1, $t0
2377 shrx $a_ptr, $acc1, $t4
2383 mulx $acc1, $t0, $acc1
2385 shlx $a_ptr, $acc2, $t0
2387 shrx $a_ptr, $acc2, $t4
2393 mulx $acc2, $t0, $acc2
2395 shlx $a_ptr, $acc3, $t0
2397 shrx $a_ptr, $acc3, $t4
2403 mulx $acc3, $t0, $acc3
2408 add $acc0, $acc4 # accumulate upper half
2409 mov .Lpoly+8*1(%rip), $a_ptr
2417 sub \$-1, $acc4 # .Lpoly[0]
2419 sbb $a_ptr, $acc5 # .Lpoly[1]
2420 sbb \$0, $acc6 # .Lpoly[2]
2422 sbb $t1, $acc7 # .Lpoly[3]
2427 mov $acc4, 8*0($r_ptr)
2429 mov $acc5, 8*1($r_ptr)
2431 mov $acc6, 8*2($r_ptr)
2432 mov $acc7, 8*3($r_ptr)
2436 .size __ecp_nistz256_sqr_montx,.-__ecp_nistz256_sqr_montx
2441 my ($r_ptr,$in_ptr)=("%rdi","%rsi");
2442 my ($acc0,$acc1,$acc2,$acc3)=map("%r$_",(8..11));
2443 my ($t0,$t1,$t2)=("%rcx","%r12","%r13");
2446 ################################################################################
2447 # void ecp_nistz256_from_mont(
2450 # This one performs Montgomery multiplication by 1, so we only need the reduction
2452 .globl ecp_nistz256_from_mont
2453 .type ecp_nistz256_from_mont,\@function,2
2455 ecp_nistz256_from_mont:
2463 mov 8*0($in_ptr), %rax
2464 mov .Lpoly+8*3(%rip), $t2
2465 mov 8*1($in_ptr), $acc1
2466 mov 8*2($in_ptr), $acc2
2467 mov 8*3($in_ptr), $acc3
2469 mov .Lpoly+8*1(%rip), $t1
2471 #########################################
2483 #########################################
2496 ##########################################
2509 ###########################################
2523 ###########################################
2524 # Branch-less conditional subtraction
2534 cmovnz $in_ptr, $acc1
2535 mov $acc0, 8*0($r_ptr)
2537 mov $acc1, 8*1($r_ptr)
2539 mov $acc2, 8*2($r_ptr)
2540 mov $acc3, 8*3($r_ptr)
2547 .cfi_adjust_cfa_offset -16
2551 .size ecp_nistz256_from_mont,.-ecp_nistz256_from_mont
2555 my ($val,$in_t,$index)=$win64?("%rcx","%rdx","%r8d"):("%rdi","%rsi","%edx");
2556 my ($ONE,$INDEX,$Ra,$Rb,$Rc,$Rd,$Re,$Rf)=map("%xmm$_",(0..7));
2557 my ($M0,$T0a,$T0b,$T0c,$T0d,$T0e,$T0f,$TMP0)=map("%xmm$_",(8..15));
2558 my ($M1,$T2a,$T2b,$TMP2,$M2,$T2a,$T2b,$TMP2)=map("%xmm$_",(8..15));
2561 ################################################################################
2562 # void ecp_nistz256_scatter_w5(uint64_t *val, uint64_t *in_t, int index);
2563 .globl ecp_nistz256_scatter_w5
2564 .type ecp_nistz256_scatter_w5,\@abi-omnipotent
2566 ecp_nistz256_scatter_w5:
2568 lea -3($index,$index,2), $index
2569 movdqa 0x00($in_t), %xmm0
2571 movdqa 0x10($in_t), %xmm1
2572 movdqa 0x20($in_t), %xmm2
2573 movdqa 0x30($in_t), %xmm3
2574 movdqa 0x40($in_t), %xmm4
2575 movdqa 0x50($in_t), %xmm5
2576 movdqa %xmm0, 0x00($val,$index)
2577 movdqa %xmm1, 0x10($val,$index)
2578 movdqa %xmm2, 0x20($val,$index)
2579 movdqa %xmm3, 0x30($val,$index)
2580 movdqa %xmm4, 0x40($val,$index)
2581 movdqa %xmm5, 0x50($val,$index)
2585 .size ecp_nistz256_scatter_w5,.-ecp_nistz256_scatter_w5
2587 ################################################################################
2588 # void ecp_nistz256_gather_w5(uint64_t *val, uint64_t *in_t, int index);
2589 .globl ecp_nistz256_gather_w5
2590 .type ecp_nistz256_gather_w5,\@abi-omnipotent
2592 ecp_nistz256_gather_w5:
2595 $code.=<<___ if ($avx>1);
2596 mov OPENSSL_ia32cap_P+8(%rip), %eax
2598 jnz .Lavx2_gather_w5
2600 $code.=<<___ if ($win64);
2601 lea -0x88(%rsp), %rax
2602 .LSEH_begin_ecp_nistz256_gather_w5:
2603 .byte 0x48,0x8d,0x60,0xe0 #lea -0x20(%rax), %rsp
2604 .byte 0x0f,0x29,0x70,0xe0 #movaps %xmm6, -0x20(%rax)
2605 .byte 0x0f,0x29,0x78,0xf0 #movaps %xmm7, -0x10(%rax)
2606 .byte 0x44,0x0f,0x29,0x00 #movaps %xmm8, 0(%rax)
2607 .byte 0x44,0x0f,0x29,0x48,0x10 #movaps %xmm9, 0x10(%rax)
2608 .byte 0x44,0x0f,0x29,0x50,0x20 #movaps %xmm10, 0x20(%rax)
2609 .byte 0x44,0x0f,0x29,0x58,0x30 #movaps %xmm11, 0x30(%rax)
2610 .byte 0x44,0x0f,0x29,0x60,0x40 #movaps %xmm12, 0x40(%rax)
2611 .byte 0x44,0x0f,0x29,0x68,0x50 #movaps %xmm13, 0x50(%rax)
2612 .byte 0x44,0x0f,0x29,0x70,0x60 #movaps %xmm14, 0x60(%rax)
2613 .byte 0x44,0x0f,0x29,0x78,0x70 #movaps %xmm15, 0x70(%rax)
2616 movdqa .LOne(%rip), $ONE
2627 pshufd \$0, $INDEX, $INDEX
2630 .Lselect_loop_sse_w5:
2634 pcmpeqd $INDEX, $TMP0
2636 movdqa 16*0($in_t), $T0a
2637 movdqa 16*1($in_t), $T0b
2638 movdqa 16*2($in_t), $T0c
2639 movdqa 16*3($in_t), $T0d
2640 movdqa 16*4($in_t), $T0e
2641 movdqa 16*5($in_t), $T0f
2642 lea 16*6($in_t), $in_t
2658 jnz .Lselect_loop_sse_w5
2660 movdqu $Ra, 16*0($val)
2661 movdqu $Rb, 16*1($val)
2662 movdqu $Rc, 16*2($val)
2663 movdqu $Rd, 16*3($val)
2664 movdqu $Re, 16*4($val)
2665 movdqu $Rf, 16*5($val)
2667 $code.=<<___ if ($win64);
2668 movaps (%rsp), %xmm6
2669 movaps 0x10(%rsp), %xmm7
2670 movaps 0x20(%rsp), %xmm8
2671 movaps 0x30(%rsp), %xmm9
2672 movaps 0x40(%rsp), %xmm10
2673 movaps 0x50(%rsp), %xmm11
2674 movaps 0x60(%rsp), %xmm12
2675 movaps 0x70(%rsp), %xmm13
2676 movaps 0x80(%rsp), %xmm14
2677 movaps 0x90(%rsp), %xmm15
2678 lea 0xa8(%rsp), %rsp
2683 .LSEH_end_ecp_nistz256_gather_w5:
2684 .size ecp_nistz256_gather_w5,.-ecp_nistz256_gather_w5
2686 ################################################################################
2687 # void ecp_nistz256_scatter_w7(uint64_t *val, uint64_t *in_t, int index);
2688 .globl ecp_nistz256_scatter_w7
2689 .type ecp_nistz256_scatter_w7,\@abi-omnipotent
2691 ecp_nistz256_scatter_w7:
2693 movdqu 0x00($in_t), %xmm0
2695 movdqu 0x10($in_t), %xmm1
2696 movdqu 0x20($in_t), %xmm2
2697 movdqu 0x30($in_t), %xmm3
2698 movdqa %xmm0, 0x00($val,$index)
2699 movdqa %xmm1, 0x10($val,$index)
2700 movdqa %xmm2, 0x20($val,$index)
2701 movdqa %xmm3, 0x30($val,$index)
2705 .size ecp_nistz256_scatter_w7,.-ecp_nistz256_scatter_w7
2707 ################################################################################
2708 # void ecp_nistz256_gather_w7(uint64_t *val, uint64_t *in_t, int index);
2709 .globl ecp_nistz256_gather_w7
2710 .type ecp_nistz256_gather_w7,\@abi-omnipotent
2712 ecp_nistz256_gather_w7:
2715 $code.=<<___ if ($avx>1);
2716 mov OPENSSL_ia32cap_P+8(%rip), %eax
2718 jnz .Lavx2_gather_w7
2720 $code.=<<___ if ($win64);
2721 lea -0x88(%rsp), %rax
2722 .LSEH_begin_ecp_nistz256_gather_w7:
2723 .byte 0x48,0x8d,0x60,0xe0 #lea -0x20(%rax), %rsp
2724 .byte 0x0f,0x29,0x70,0xe0 #movaps %xmm6, -0x20(%rax)
2725 .byte 0x0f,0x29,0x78,0xf0 #movaps %xmm7, -0x10(%rax)
2726 .byte 0x44,0x0f,0x29,0x00 #movaps %xmm8, 0(%rax)
2727 .byte 0x44,0x0f,0x29,0x48,0x10 #movaps %xmm9, 0x10(%rax)
2728 .byte 0x44,0x0f,0x29,0x50,0x20 #movaps %xmm10, 0x20(%rax)
2729 .byte 0x44,0x0f,0x29,0x58,0x30 #movaps %xmm11, 0x30(%rax)
2730 .byte 0x44,0x0f,0x29,0x60,0x40 #movaps %xmm12, 0x40(%rax)
2731 .byte 0x44,0x0f,0x29,0x68,0x50 #movaps %xmm13, 0x50(%rax)
2732 .byte 0x44,0x0f,0x29,0x70,0x60 #movaps %xmm14, 0x60(%rax)
2733 .byte 0x44,0x0f,0x29,0x78,0x70 #movaps %xmm15, 0x70(%rax)
2736 movdqa .LOne(%rip), $M0
2745 pshufd \$0, $INDEX, $INDEX
2748 .Lselect_loop_sse_w7:
2751 movdqa 16*0($in_t), $T0a
2752 movdqa 16*1($in_t), $T0b
2753 pcmpeqd $INDEX, $TMP0
2754 movdqa 16*2($in_t), $T0c
2755 movdqa 16*3($in_t), $T0d
2756 lea 16*4($in_t), $in_t
2765 prefetcht0 255($in_t)
2769 jnz .Lselect_loop_sse_w7
2771 movdqu $Ra, 16*0($val)
2772 movdqu $Rb, 16*1($val)
2773 movdqu $Rc, 16*2($val)
2774 movdqu $Rd, 16*3($val)
2776 $code.=<<___ if ($win64);
2777 movaps (%rsp), %xmm6
2778 movaps 0x10(%rsp), %xmm7
2779 movaps 0x20(%rsp), %xmm8
2780 movaps 0x30(%rsp), %xmm9
2781 movaps 0x40(%rsp), %xmm10
2782 movaps 0x50(%rsp), %xmm11
2783 movaps 0x60(%rsp), %xmm12
2784 movaps 0x70(%rsp), %xmm13
2785 movaps 0x80(%rsp), %xmm14
2786 movaps 0x90(%rsp), %xmm15
2787 lea 0xa8(%rsp), %rsp
2792 .LSEH_end_ecp_nistz256_gather_w7:
2793 .size ecp_nistz256_gather_w7,.-ecp_nistz256_gather_w7
2797 my ($val,$in_t,$index)=$win64?("%rcx","%rdx","%r8d"):("%rdi","%rsi","%edx");
2798 my ($TWO,$INDEX,$Ra,$Rb,$Rc)=map("%ymm$_",(0..4));
2799 my ($M0,$T0a,$T0b,$T0c,$TMP0)=map("%ymm$_",(5..9));
2800 my ($M1,$T1a,$T1b,$T1c,$TMP1)=map("%ymm$_",(10..14));
2803 ################################################################################
2804 # void ecp_nistz256_avx2_gather_w5(uint64_t *val, uint64_t *in_t, int index);
2805 .type ecp_nistz256_avx2_gather_w5,\@abi-omnipotent
2807 ecp_nistz256_avx2_gather_w5:
2812 $code.=<<___ if ($win64);
2813 lea -0x88(%rsp), %rax
2815 .LSEH_begin_ecp_nistz256_avx2_gather_w5:
2816 .byte 0x48,0x8d,0x60,0xe0 # lea -0x20(%rax), %rsp
2817 .byte 0xc5,0xf8,0x29,0x70,0xe0 # vmovaps %xmm6, -0x20(%rax)
2818 .byte 0xc5,0xf8,0x29,0x78,0xf0 # vmovaps %xmm7, -0x10(%rax)
2819 .byte 0xc5,0x78,0x29,0x40,0x00 # vmovaps %xmm8, 8(%rax)
2820 .byte 0xc5,0x78,0x29,0x48,0x10 # vmovaps %xmm9, 0x10(%rax)
2821 .byte 0xc5,0x78,0x29,0x50,0x20 # vmovaps %xmm10, 0x20(%rax)
2822 .byte 0xc5,0x78,0x29,0x58,0x30 # vmovaps %xmm11, 0x30(%rax)
2823 .byte 0xc5,0x78,0x29,0x60,0x40 # vmovaps %xmm12, 0x40(%rax)
2824 .byte 0xc5,0x78,0x29,0x68,0x50 # vmovaps %xmm13, 0x50(%rax)
2825 .byte 0xc5,0x78,0x29,0x70,0x60 # vmovaps %xmm14, 0x60(%rax)
2826 .byte 0xc5,0x78,0x29,0x78,0x70 # vmovaps %xmm15, 0x70(%rax)
2829 vmovdqa .LTwo(%rip), $TWO
2835 vmovdqa .LOne(%rip), $M0
2836 vmovdqa .LTwo(%rip), $M1
2839 vpermd $INDEX, $Ra, $INDEX
2842 .Lselect_loop_avx2_w5:
2844 vmovdqa 32*0($in_t), $T0a
2845 vmovdqa 32*1($in_t), $T0b
2846 vmovdqa 32*2($in_t), $T0c
2848 vmovdqa 32*3($in_t), $T1a
2849 vmovdqa 32*4($in_t), $T1b
2850 vmovdqa 32*5($in_t), $T1c
2852 vpcmpeqd $INDEX, $M0, $TMP0
2853 vpcmpeqd $INDEX, $M1, $TMP1
2855 vpaddd $TWO, $M0, $M0
2856 vpaddd $TWO, $M1, $M1
2857 lea 32*6($in_t), $in_t
2859 vpand $TMP0, $T0a, $T0a
2860 vpand $TMP0, $T0b, $T0b
2861 vpand $TMP0, $T0c, $T0c
2862 vpand $TMP1, $T1a, $T1a
2863 vpand $TMP1, $T1b, $T1b
2864 vpand $TMP1, $T1c, $T1c
2866 vpxor $T0a, $Ra, $Ra
2867 vpxor $T0b, $Rb, $Rb
2868 vpxor $T0c, $Rc, $Rc
2869 vpxor $T1a, $Ra, $Ra
2870 vpxor $T1b, $Rb, $Rb
2871 vpxor $T1c, $Rc, $Rc
2874 jnz .Lselect_loop_avx2_w5
2876 vmovdqu $Ra, 32*0($val)
2877 vmovdqu $Rb, 32*1($val)
2878 vmovdqu $Rc, 32*2($val)
2881 $code.=<<___ if ($win64);
2882 movaps (%rsp), %xmm6
2883 movaps 0x10(%rsp), %xmm7
2884 movaps 0x20(%rsp), %xmm8
2885 movaps 0x30(%rsp), %xmm9
2886 movaps 0x40(%rsp), %xmm10
2887 movaps 0x50(%rsp), %xmm11
2888 movaps 0x60(%rsp), %xmm12
2889 movaps 0x70(%rsp), %xmm13
2890 movaps 0x80(%rsp), %xmm14
2891 movaps 0x90(%rsp), %xmm15
2897 .LSEH_end_ecp_nistz256_avx2_gather_w5:
2898 .size ecp_nistz256_avx2_gather_w5,.-ecp_nistz256_avx2_gather_w5
2902 my ($val,$in_t,$index)=$win64?("%rcx","%rdx","%r8d"):("%rdi","%rsi","%edx");
2903 my ($THREE,$INDEX,$Ra,$Rb)=map("%ymm$_",(0..3));
2904 my ($M0,$T0a,$T0b,$TMP0)=map("%ymm$_",(4..7));
2905 my ($M1,$T1a,$T1b,$TMP1)=map("%ymm$_",(8..11));
2906 my ($M2,$T2a,$T2b,$TMP2)=map("%ymm$_",(12..15));
2910 ################################################################################
2911 # void ecp_nistz256_avx2_gather_w7(uint64_t *val, uint64_t *in_t, int index);
2912 .globl ecp_nistz256_avx2_gather_w7
2913 .type ecp_nistz256_avx2_gather_w7,\@abi-omnipotent
2915 ecp_nistz256_avx2_gather_w7:
2920 $code.=<<___ if ($win64);
2922 lea -0x88(%rsp), %rax
2923 .LSEH_begin_ecp_nistz256_avx2_gather_w7:
2924 .byte 0x48,0x8d,0x60,0xe0 # lea -0x20(%rax), %rsp
2925 .byte 0xc5,0xf8,0x29,0x70,0xe0 # vmovaps %xmm6, -0x20(%rax)
2926 .byte 0xc5,0xf8,0x29,0x78,0xf0 # vmovaps %xmm7, -0x10(%rax)
2927 .byte 0xc5,0x78,0x29,0x40,0x00 # vmovaps %xmm8, 8(%rax)
2928 .byte 0xc5,0x78,0x29,0x48,0x10 # vmovaps %xmm9, 0x10(%rax)
2929 .byte 0xc5,0x78,0x29,0x50,0x20 # vmovaps %xmm10, 0x20(%rax)
2930 .byte 0xc5,0x78,0x29,0x58,0x30 # vmovaps %xmm11, 0x30(%rax)
2931 .byte 0xc5,0x78,0x29,0x60,0x40 # vmovaps %xmm12, 0x40(%rax)
2932 .byte 0xc5,0x78,0x29,0x68,0x50 # vmovaps %xmm13, 0x50(%rax)
2933 .byte 0xc5,0x78,0x29,0x70,0x60 # vmovaps %xmm14, 0x60(%rax)
2934 .byte 0xc5,0x78,0x29,0x78,0x70 # vmovaps %xmm15, 0x70(%rax)
2937 vmovdqa .LThree(%rip), $THREE
2942 vmovdqa .LOne(%rip), $M0
2943 vmovdqa .LTwo(%rip), $M1
2944 vmovdqa .LThree(%rip), $M2
2947 vpermd $INDEX, $Ra, $INDEX
2948 # Skip index = 0, because it is implicitly the point at infinity
2951 .Lselect_loop_avx2_w7:
2953 vmovdqa 32*0($in_t), $T0a
2954 vmovdqa 32*1($in_t), $T0b
2956 vmovdqa 32*2($in_t), $T1a
2957 vmovdqa 32*3($in_t), $T1b
2959 vmovdqa 32*4($in_t), $T2a
2960 vmovdqa 32*5($in_t), $T2b
2962 vpcmpeqd $INDEX, $M0, $TMP0
2963 vpcmpeqd $INDEX, $M1, $TMP1
2964 vpcmpeqd $INDEX, $M2, $TMP2
2966 vpaddd $THREE, $M0, $M0
2967 vpaddd $THREE, $M1, $M1
2968 vpaddd $THREE, $M2, $M2
2969 lea 32*6($in_t), $in_t
2971 vpand $TMP0, $T0a, $T0a
2972 vpand $TMP0, $T0b, $T0b
2973 vpand $TMP1, $T1a, $T1a
2974 vpand $TMP1, $T1b, $T1b
2975 vpand $TMP2, $T2a, $T2a
2976 vpand $TMP2, $T2b, $T2b
2978 vpxor $T0a, $Ra, $Ra
2979 vpxor $T0b, $Rb, $Rb
2980 vpxor $T1a, $Ra, $Ra
2981 vpxor $T1b, $Rb, $Rb
2982 vpxor $T2a, $Ra, $Ra
2983 vpxor $T2b, $Rb, $Rb
2986 jnz .Lselect_loop_avx2_w7
2989 vmovdqa 32*0($in_t), $T0a
2990 vmovdqa 32*1($in_t), $T0b
2992 vpcmpeqd $INDEX, $M0, $TMP0
2994 vpand $TMP0, $T0a, $T0a
2995 vpand $TMP0, $T0b, $T0b
2997 vpxor $T0a, $Ra, $Ra
2998 vpxor $T0b, $Rb, $Rb
3000 vmovdqu $Ra, 32*0($val)
3001 vmovdqu $Rb, 32*1($val)
3004 $code.=<<___ if ($win64);
3005 movaps (%rsp), %xmm6
3006 movaps 0x10(%rsp), %xmm7
3007 movaps 0x20(%rsp), %xmm8
3008 movaps 0x30(%rsp), %xmm9
3009 movaps 0x40(%rsp), %xmm10
3010 movaps 0x50(%rsp), %xmm11
3011 movaps 0x60(%rsp), %xmm12
3012 movaps 0x70(%rsp), %xmm13
3013 movaps 0x80(%rsp), %xmm14
3014 movaps 0x90(%rsp), %xmm15
3020 .LSEH_end_ecp_nistz256_avx2_gather_w7:
3021 .size ecp_nistz256_avx2_gather_w7,.-ecp_nistz256_avx2_gather_w7
3025 .globl ecp_nistz256_avx2_gather_w7
3026 .type ecp_nistz256_avx2_gather_w7,\@function,3
3028 ecp_nistz256_avx2_gather_w7:
3030 .byte 0x0f,0x0b # ud2
3033 .size ecp_nistz256_avx2_gather_w7,.-ecp_nistz256_avx2_gather_w7
3037 ########################################################################
3038 # This block implements higher level point_double, point_add and
3039 # point_add_affine. The key to performance in this case is to allow
3040 # out-of-order execution logic to overlap computations from next step
3041 # with tail processing from current step. By using tailored calling
3042 # sequence we minimize inter-step overhead to give processor better
3043 # shot at overlapping operations...
3045 # You will notice that input data is copied to stack. Trouble is that
3046 # there are no registers to spare for holding original pointers and
3047 # reloading them, pointers, would create undesired dependencies on
3048 # effective addresses calculation paths. In other words it's too done
3049 # to favour out-of-order execution logic.
3050 # <appro@openssl.org>
3052 my ($r_ptr,$a_ptr,$b_org,$b_ptr)=("%rdi","%rsi","%rdx","%rbx");
3053 my ($acc0,$acc1,$acc2,$acc3,$acc4,$acc5,$acc6,$acc7)=map("%r$_",(8..15));
3054 my ($t0,$t1,$t2,$t3,$t4)=("%rax","%rbp","%rcx",$acc4,$acc4);
3055 my ($poly1,$poly3)=($acc6,$acc7);
3057 sub load_for_mul () {
3058 my ($a,$b,$src0) = @_;
3059 my $bias = $src0 eq "%rax" ? 0 : -128;
3065 lea $bias+$a, $a_ptr
3070 sub load_for_sqr () {
3072 my $bias = $src0 eq "%rax" ? 0 : -128;
3076 lea $bias+$a, $a_ptr
3082 ########################################################################
3083 # operate in 4-5-0-1 "name space" that matches multiplication output
3085 my ($a0,$a1,$a2,$a3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
3088 .type __ecp_nistz256_add_toq,\@abi-omnipotent
3090 __ecp_nistz256_add_toq:
3093 add 8*0($b_ptr), $a0
3094 adc 8*1($b_ptr), $a1
3096 adc 8*2($b_ptr), $a2
3097 adc 8*3($b_ptr), $a3
3111 mov $a0, 8*0($r_ptr)
3113 mov $a1, 8*1($r_ptr)
3115 mov $a2, 8*2($r_ptr)
3116 mov $a3, 8*3($r_ptr)
3120 .size __ecp_nistz256_add_toq,.-__ecp_nistz256_add_toq
3122 .type __ecp_nistz256_sub_fromq,\@abi-omnipotent
3124 __ecp_nistz256_sub_fromq:
3126 sub 8*0($b_ptr), $a0
3127 sbb 8*1($b_ptr), $a1
3129 sbb 8*2($b_ptr), $a2
3130 sbb 8*3($b_ptr), $a3
3144 mov $a0, 8*0($r_ptr)
3146 mov $a1, 8*1($r_ptr)
3148 mov $a2, 8*2($r_ptr)
3149 mov $a3, 8*3($r_ptr)
3153 .size __ecp_nistz256_sub_fromq,.-__ecp_nistz256_sub_fromq
3155 .type __ecp_nistz256_subq,\@abi-omnipotent
3157 __ecp_nistz256_subq:
3182 .size __ecp_nistz256_subq,.-__ecp_nistz256_subq
3184 .type __ecp_nistz256_mul_by_2q,\@abi-omnipotent
3186 __ecp_nistz256_mul_by_2q:
3189 add $a0, $a0 # a0:a3+a0:a3
3207 mov $a0, 8*0($r_ptr)
3209 mov $a1, 8*1($r_ptr)
3211 mov $a2, 8*2($r_ptr)
3212 mov $a3, 8*3($r_ptr)
3216 .size __ecp_nistz256_mul_by_2q,.-__ecp_nistz256_mul_by_2q
3221 my ($src0,$sfx,$bias);
3222 my ($S,$M,$Zsqr,$in_x,$tmp0)=map(32*$_,(0..4));
3230 .globl ecp_nistz256_point_double
3231 .type ecp_nistz256_point_double,\@function,2
3233 ecp_nistz256_point_double:
3236 $code.=<<___ if ($addx);
3238 and OPENSSL_ia32cap_P+8(%rip), %ecx
3248 .type ecp_nistz256_point_doublex,\@function,2
3250 ecp_nistz256_point_doublex:
3269 .cfi_adjust_cfa_offset 32*5+8
3270 .Lpoint_double${x}_body:
3272 .Lpoint_double_shortcut$x:
3273 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$a_ptr.x
3274 mov $a_ptr, $b_ptr # backup copy
3275 movdqu 0x10($a_ptr), %xmm1
3276 mov 0x20+8*0($a_ptr), $acc4 # load in_y in "5-4-0-1" order
3277 mov 0x20+8*1($a_ptr), $acc5
3278 mov 0x20+8*2($a_ptr), $acc0
3279 mov 0x20+8*3($a_ptr), $acc1
3280 mov .Lpoly+8*1(%rip), $poly1
3281 mov .Lpoly+8*3(%rip), $poly3
3282 movdqa %xmm0, $in_x(%rsp)
3283 movdqa %xmm1, $in_x+0x10(%rsp)
3284 lea 0x20($r_ptr), $acc2
3285 lea 0x40($r_ptr), $acc3
3290 lea $S(%rsp), $r_ptr
3291 call __ecp_nistz256_mul_by_2$x # p256_mul_by_2(S, in_y);
3293 mov 0x40+8*0($a_ptr), $src0
3294 mov 0x40+8*1($a_ptr), $acc6
3295 mov 0x40+8*2($a_ptr), $acc7
3296 mov 0x40+8*3($a_ptr), $acc0
3297 lea 0x40-$bias($a_ptr), $a_ptr
3298 lea $Zsqr(%rsp), $r_ptr
3299 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Zsqr, in_z);
3301 `&load_for_sqr("$S(%rsp)", "$src0")`
3302 lea $S(%rsp), $r_ptr
3303 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(S, S);
3305 mov 0x20($b_ptr), $src0 # $b_ptr is still valid
3306 mov 0x40+8*0($b_ptr), $acc1
3307 mov 0x40+8*1($b_ptr), $acc2
3308 mov 0x40+8*2($b_ptr), $acc3
3309 mov 0x40+8*3($b_ptr), $acc4
3310 lea 0x40-$bias($b_ptr), $a_ptr
3311 lea 0x20($b_ptr), $b_ptr
3313 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, in_z, in_y);
3314 call __ecp_nistz256_mul_by_2$x # p256_mul_by_2(res_z, res_z);
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 $M(%rsp), $r_ptr
3322 call __ecp_nistz256_add_to$x # p256_add(M, in_x, Zsqr);
3324 mov $in_x+8*0(%rsp), $acc4 # "5-4-0-1" order
3325 mov $in_x+8*1(%rsp), $acc5
3326 lea $Zsqr(%rsp), $b_ptr
3327 mov $in_x+8*2(%rsp), $acc0
3328 mov $in_x+8*3(%rsp), $acc1
3329 lea $Zsqr(%rsp), $r_ptr
3330 call __ecp_nistz256_sub_from$x # p256_sub(Zsqr, in_x, Zsqr);
3332 `&load_for_sqr("$S(%rsp)", "$src0")`
3334 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(res_y, S);
3337 ######## ecp_nistz256_div_by_2(res_y, res_y); ##########################
3338 # operate in 4-5-6-7 "name space" that matches squaring output
3340 my ($poly1,$poly3)=($a_ptr,$t1);
3341 my ($a0,$a1,$a2,$a3,$t3,$t4,$t1)=($acc4,$acc5,$acc6,$acc7,$acc0,$acc1,$acc2);
3354 xor $a_ptr, $a_ptr # borrow $a_ptr
3363 mov $a1, $t0 # a0:a3>>1
3374 mov $a0, 8*0($r_ptr)
3376 mov $a1, 8*1($r_ptr)
3380 mov $a2, 8*2($r_ptr)
3381 mov $a3, 8*3($r_ptr)
3385 `&load_for_mul("$M(%rsp)", "$Zsqr(%rsp)", "$src0")`
3386 lea $M(%rsp), $r_ptr
3387 call __ecp_nistz256_mul_mont$x # p256_mul_mont(M, M, Zsqr);
3389 lea $tmp0(%rsp), $r_ptr
3390 call __ecp_nistz256_mul_by_2$x
3392 lea $M(%rsp), $b_ptr
3393 lea $M(%rsp), $r_ptr
3394 call __ecp_nistz256_add_to$x # p256_mul_by_3(M, M);
3396 `&load_for_mul("$S(%rsp)", "$in_x(%rsp)", "$src0")`
3397 lea $S(%rsp), $r_ptr
3398 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S, S, in_x);
3400 lea $tmp0(%rsp), $r_ptr
3401 call __ecp_nistz256_mul_by_2$x # p256_mul_by_2(tmp0, S);
3403 `&load_for_sqr("$M(%rsp)", "$src0")`
3405 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(res_x, M);
3407 lea $tmp0(%rsp), $b_ptr
3408 mov $acc6, $acc0 # harmonize sqr output and sub input
3412 call __ecp_nistz256_sub_from$x # p256_sub(res_x, res_x, tmp0);
3414 mov $S+8*0(%rsp), $t0
3415 mov $S+8*1(%rsp), $t1
3416 mov $S+8*2(%rsp), $t2
3417 mov $S+8*3(%rsp), $acc2 # "4-5-0-1" order
3418 lea $S(%rsp), $r_ptr
3419 call __ecp_nistz256_sub$x # p256_sub(S, S, res_x);
3422 lea $M(%rsp), $b_ptr
3423 mov $acc4, $acc6 # harmonize sub output and mul input
3425 mov $acc4, $S+8*0(%rsp) # have to save:-(
3427 mov $acc5, $S+8*1(%rsp)
3429 mov $acc0, $S+8*2(%rsp)
3430 lea $S-$bias(%rsp), $a_ptr
3432 mov $acc1, $S+8*3(%rsp)
3434 lea $S(%rsp), $r_ptr
3435 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S, S, M);
3439 call __ecp_nistz256_sub_from$x # p256_sub(res_y, S, res_y);
3441 lea 32*5+56(%rsp), %rsi
3456 .cfi_def_cfa_register %rsp
3457 .Lpoint_double${x}_epilogue:
3460 .size ecp_nistz256_point_double$sfx,.-ecp_nistz256_point_double$sfx
3467 my ($src0,$sfx,$bias);
3468 my ($H,$Hsqr,$R,$Rsqr,$Hcub,
3470 $res_x,$res_y,$res_z,
3471 $in1_x,$in1_y,$in1_z,
3472 $in2_x,$in2_y,$in2_z)=map(32*$_,(0..17));
3473 my ($Z1sqr, $Z2sqr) = ($Hsqr, $Rsqr);
3481 .globl ecp_nistz256_point_add
3482 .type ecp_nistz256_point_add,\@function,3
3484 ecp_nistz256_point_add:
3487 $code.=<<___ if ($addx);
3489 and OPENSSL_ia32cap_P+8(%rip), %ecx
3499 .type ecp_nistz256_point_addx,\@function,3
3501 ecp_nistz256_point_addx:
3520 .cfi_adjust_cfa_offset 32*18+8
3521 .Lpoint_add${x}_body:
3523 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$a_ptr
3524 movdqu 0x10($a_ptr), %xmm1
3525 movdqu 0x20($a_ptr), %xmm2
3526 movdqu 0x30($a_ptr), %xmm3
3527 movdqu 0x40($a_ptr), %xmm4
3528 movdqu 0x50($a_ptr), %xmm5
3529 mov $a_ptr, $b_ptr # reassign
3530 mov $b_org, $a_ptr # reassign
3531 movdqa %xmm0, $in1_x(%rsp)
3532 movdqa %xmm1, $in1_x+0x10(%rsp)
3533 movdqa %xmm2, $in1_y(%rsp)
3534 movdqa %xmm3, $in1_y+0x10(%rsp)
3535 movdqa %xmm4, $in1_z(%rsp)
3536 movdqa %xmm5, $in1_z+0x10(%rsp)
3539 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$b_ptr
3540 pshufd \$0xb1, %xmm5, %xmm3
3541 movdqu 0x10($a_ptr), %xmm1
3542 movdqu 0x20($a_ptr), %xmm2
3544 movdqu 0x30($a_ptr), %xmm3
3545 mov 0x40+8*0($a_ptr), $src0 # load original in2_z
3546 mov 0x40+8*1($a_ptr), $acc6
3547 mov 0x40+8*2($a_ptr), $acc7
3548 mov 0x40+8*3($a_ptr), $acc0
3549 movdqa %xmm0, $in2_x(%rsp)
3550 pshufd \$0x1e, %xmm5, %xmm4
3551 movdqa %xmm1, $in2_x+0x10(%rsp)
3552 movdqu 0x40($a_ptr),%xmm0 # in2_z again
3553 movdqu 0x50($a_ptr),%xmm1
3554 movdqa %xmm2, $in2_y(%rsp)
3555 movdqa %xmm3, $in2_y+0x10(%rsp)
3559 movq $r_ptr, %xmm0 # save $r_ptr
3561 lea 0x40-$bias($a_ptr), $a_ptr # $a_ptr is still valid
3562 mov $src0, $in2_z+8*0(%rsp) # make in2_z copy
3563 mov $acc6, $in2_z+8*1(%rsp)
3564 mov $acc7, $in2_z+8*2(%rsp)
3565 mov $acc0, $in2_z+8*3(%rsp)
3566 lea $Z2sqr(%rsp), $r_ptr # Z2^2
3567 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Z2sqr, in2_z);
3569 pcmpeqd %xmm4, %xmm5
3570 pshufd \$0xb1, %xmm1, %xmm4
3572 pshufd \$0, %xmm5, %xmm5 # in1infty
3573 pshufd \$0x1e, %xmm4, %xmm3
3576 pcmpeqd %xmm3, %xmm4
3577 pshufd \$0, %xmm4, %xmm4 # in2infty
3578 mov 0x40+8*0($b_ptr), $src0 # load original in1_z
3579 mov 0x40+8*1($b_ptr), $acc6
3580 mov 0x40+8*2($b_ptr), $acc7
3581 mov 0x40+8*3($b_ptr), $acc0
3584 lea 0x40-$bias($b_ptr), $a_ptr
3585 lea $Z1sqr(%rsp), $r_ptr # Z1^2
3586 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Z1sqr, in1_z);
3588 `&load_for_mul("$Z2sqr(%rsp)", "$in2_z(%rsp)", "$src0")`
3589 lea $S1(%rsp), $r_ptr # S1 = Z2^3
3590 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S1, Z2sqr, in2_z);
3592 `&load_for_mul("$Z1sqr(%rsp)", "$in1_z(%rsp)", "$src0")`
3593 lea $S2(%rsp), $r_ptr # S2 = Z1^3
3594 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, Z1sqr, in1_z);
3596 `&load_for_mul("$S1(%rsp)", "$in1_y(%rsp)", "$src0")`
3597 lea $S1(%rsp), $r_ptr # S1 = Y1*Z2^3
3598 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S1, S1, in1_y);
3600 `&load_for_mul("$S2(%rsp)", "$in2_y(%rsp)", "$src0")`
3601 lea $S2(%rsp), $r_ptr # S2 = Y2*Z1^3
3602 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, S2, in2_y);
3604 lea $S1(%rsp), $b_ptr
3605 lea $R(%rsp), $r_ptr # R = S2 - S1
3606 call __ecp_nistz256_sub_from$x # p256_sub(R, S2, S1);
3608 or $acc5, $acc4 # see if result is zero
3612 por %xmm5, %xmm2 # in1infty || in2infty
3615 `&load_for_mul("$Z2sqr(%rsp)", "$in1_x(%rsp)", "$src0")`
3616 lea $U1(%rsp), $r_ptr # U1 = X1*Z2^2
3617 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U1, in1_x, Z2sqr);
3619 `&load_for_mul("$Z1sqr(%rsp)", "$in2_x(%rsp)", "$src0")`
3620 lea $U2(%rsp), $r_ptr # U2 = X2*Z1^2
3621 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, in2_x, Z1sqr);
3623 lea $U1(%rsp), $b_ptr
3624 lea $H(%rsp), $r_ptr # H = U2 - U1
3625 call __ecp_nistz256_sub_from$x # p256_sub(H, U2, U1);
3627 or $acc5, $acc4 # see if result is zero
3629 or $acc1, $acc4 # !is_equal(U1, U2)
3631 movq %xmm2, $acc0 # in1infty | in2infty
3632 movq %xmm3, $acc1 # !is_equal(S1, S2)
3637 # if (!is_equal(U1, U2) | in1infty | in2infty | !is_equal(S1, S2))
3638 .byte 0x3e # predict taken
3642 movq %xmm1, $a_ptr # restore $a_ptr
3643 movq %xmm0, $r_ptr # restore $r_ptr
3644 add \$`32*(18-5)`, %rsp # difference in frame sizes
3645 .cfi_adjust_cfa_offset `-32*(18-5)`
3646 jmp .Lpoint_double_shortcut$x
3647 .cfi_adjust_cfa_offset `32*(18-5)`
3651 `&load_for_sqr("$R(%rsp)", "$src0")`
3652 lea $Rsqr(%rsp), $r_ptr # R^2
3653 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Rsqr, R);
3655 `&load_for_mul("$H(%rsp)", "$in1_z(%rsp)", "$src0")`
3656 lea $res_z(%rsp), $r_ptr # Z3 = H*Z1*Z2
3657 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, H, in1_z);
3659 `&load_for_sqr("$H(%rsp)", "$src0")`
3660 lea $Hsqr(%rsp), $r_ptr # H^2
3661 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Hsqr, H);
3663 `&load_for_mul("$res_z(%rsp)", "$in2_z(%rsp)", "$src0")`
3664 lea $res_z(%rsp), $r_ptr # Z3 = H*Z1*Z2
3665 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, res_z, in2_z);
3667 `&load_for_mul("$Hsqr(%rsp)", "$H(%rsp)", "$src0")`
3668 lea $Hcub(%rsp), $r_ptr # H^3
3669 call __ecp_nistz256_mul_mont$x # p256_mul_mont(Hcub, Hsqr, H);
3671 `&load_for_mul("$Hsqr(%rsp)", "$U1(%rsp)", "$src0")`
3672 lea $U2(%rsp), $r_ptr # U1*H^2
3673 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, U1, Hsqr);
3676 #######################################################################
3677 # operate in 4-5-0-1 "name space" that matches multiplication output
3679 my ($acc0,$acc1,$acc2,$acc3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
3680 my ($poly1, $poly3)=($acc6,$acc7);
3683 #lea $U2(%rsp), $a_ptr
3684 #lea $Hsqr(%rsp), $r_ptr # 2*U1*H^2
3685 #call __ecp_nistz256_mul_by_2 # ecp_nistz256_mul_by_2(Hsqr, U2);
3688 add $acc0, $acc0 # a0:a3+a0:a3
3689 lea $Rsqr(%rsp), $a_ptr
3706 mov 8*0($a_ptr), $t0
3708 mov 8*1($a_ptr), $t1
3710 mov 8*2($a_ptr), $t2
3712 mov 8*3($a_ptr), $t3
3714 call __ecp_nistz256_sub$x # p256_sub(res_x, Rsqr, Hsqr);
3716 lea $Hcub(%rsp), $b_ptr
3717 lea $res_x(%rsp), $r_ptr
3718 call __ecp_nistz256_sub_from$x # p256_sub(res_x, res_x, Hcub);
3720 mov $U2+8*0(%rsp), $t0
3721 mov $U2+8*1(%rsp), $t1
3722 mov $U2+8*2(%rsp), $t2
3723 mov $U2+8*3(%rsp), $t3
3724 lea $res_y(%rsp), $r_ptr
3726 call __ecp_nistz256_sub$x # p256_sub(res_y, U2, res_x);
3728 mov $acc0, 8*0($r_ptr) # save the result, as
3729 mov $acc1, 8*1($r_ptr) # __ecp_nistz256_sub doesn't
3730 mov $acc2, 8*2($r_ptr)
3731 mov $acc3, 8*3($r_ptr)
3735 `&load_for_mul("$S1(%rsp)", "$Hcub(%rsp)", "$src0")`
3736 lea $S2(%rsp), $r_ptr
3737 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, S1, Hcub);
3739 `&load_for_mul("$R(%rsp)", "$res_y(%rsp)", "$src0")`
3740 lea $res_y(%rsp), $r_ptr
3741 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_y, R, res_y);
3743 lea $S2(%rsp), $b_ptr
3744 lea $res_y(%rsp), $r_ptr
3745 call __ecp_nistz256_sub_from$x # p256_sub(res_y, res_y, S2);
3747 movq %xmm0, $r_ptr # restore $r_ptr
3749 movdqa %xmm5, %xmm0 # copy_conditional(res_z, in2_z, in1infty);
3751 pandn $res_z(%rsp), %xmm0
3753 pandn $res_z+0x10(%rsp), %xmm1
3755 pand $in2_z(%rsp), %xmm2
3756 pand $in2_z+0x10(%rsp), %xmm3
3760 movdqa %xmm4, %xmm0 # copy_conditional(res_z, in1_z, in2infty);
3766 pand $in1_z(%rsp), %xmm2
3767 pand $in1_z+0x10(%rsp), %xmm3
3770 movdqu %xmm2, 0x40($r_ptr)
3771 movdqu %xmm3, 0x50($r_ptr)
3773 movdqa %xmm5, %xmm0 # copy_conditional(res_x, in2_x, in1infty);
3775 pandn $res_x(%rsp), %xmm0
3777 pandn $res_x+0x10(%rsp), %xmm1
3779 pand $in2_x(%rsp), %xmm2
3780 pand $in2_x+0x10(%rsp), %xmm3
3784 movdqa %xmm4, %xmm0 # copy_conditional(res_x, in1_x, in2infty);
3790 pand $in1_x(%rsp), %xmm2
3791 pand $in1_x+0x10(%rsp), %xmm3
3794 movdqu %xmm2, 0x00($r_ptr)
3795 movdqu %xmm3, 0x10($r_ptr)
3797 movdqa %xmm5, %xmm0 # copy_conditional(res_y, in2_y, in1infty);
3799 pandn $res_y(%rsp), %xmm0
3801 pandn $res_y+0x10(%rsp), %xmm1
3803 pand $in2_y(%rsp), %xmm2
3804 pand $in2_y+0x10(%rsp), %xmm3
3808 movdqa %xmm4, %xmm0 # copy_conditional(res_y, in1_y, in2infty);
3814 pand $in1_y(%rsp), %xmm2
3815 pand $in1_y+0x10(%rsp), %xmm3
3818 movdqu %xmm2, 0x20($r_ptr)
3819 movdqu %xmm3, 0x30($r_ptr)
3822 lea 32*18+56(%rsp), %rsi
3837 .cfi_def_cfa_register %rsp
3838 .Lpoint_add${x}_epilogue:
3841 .size ecp_nistz256_point_add$sfx,.-ecp_nistz256_point_add$sfx
3846 sub gen_add_affine () {
3848 my ($src0,$sfx,$bias);
3849 my ($U2,$S2,$H,$R,$Hsqr,$Hcub,$Rsqr,
3850 $res_x,$res_y,$res_z,
3851 $in1_x,$in1_y,$in1_z,
3852 $in2_x,$in2_y)=map(32*$_,(0..14));
3861 .globl ecp_nistz256_point_add_affine
3862 .type ecp_nistz256_point_add_affine,\@function,3
3864 ecp_nistz256_point_add_affine:
3867 $code.=<<___ if ($addx);
3869 and OPENSSL_ia32cap_P+8(%rip), %ecx
3871 je .Lpoint_add_affinex
3879 .type ecp_nistz256_point_add_affinex,\@function,3
3881 ecp_nistz256_point_add_affinex:
3883 .Lpoint_add_affinex:
3900 .cfi_adjust_cfa_offset 32*15+8
3901 .Ladd_affine${x}_body:
3903 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$a_ptr
3904 mov $b_org, $b_ptr # reassign
3905 movdqu 0x10($a_ptr), %xmm1
3906 movdqu 0x20($a_ptr), %xmm2
3907 movdqu 0x30($a_ptr), %xmm3
3908 movdqu 0x40($a_ptr), %xmm4
3909 movdqu 0x50($a_ptr), %xmm5
3910 mov 0x40+8*0($a_ptr), $src0 # load original in1_z
3911 mov 0x40+8*1($a_ptr), $acc6
3912 mov 0x40+8*2($a_ptr), $acc7
3913 mov 0x40+8*3($a_ptr), $acc0
3914 movdqa %xmm0, $in1_x(%rsp)
3915 movdqa %xmm1, $in1_x+0x10(%rsp)
3916 movdqa %xmm2, $in1_y(%rsp)
3917 movdqa %xmm3, $in1_y+0x10(%rsp)
3918 movdqa %xmm4, $in1_z(%rsp)
3919 movdqa %xmm5, $in1_z+0x10(%rsp)
3922 movdqu 0x00($b_ptr), %xmm0 # copy *(P256_POINT_AFFINE *)$b_ptr
3923 pshufd \$0xb1, %xmm5, %xmm3
3924 movdqu 0x10($b_ptr), %xmm1
3925 movdqu 0x20($b_ptr), %xmm2
3927 movdqu 0x30($b_ptr), %xmm3
3928 movdqa %xmm0, $in2_x(%rsp)
3929 pshufd \$0x1e, %xmm5, %xmm4
3930 movdqa %xmm1, $in2_x+0x10(%rsp)
3932 movq $r_ptr, %xmm0 # save $r_ptr
3933 movdqa %xmm2, $in2_y(%rsp)
3934 movdqa %xmm3, $in2_y+0x10(%rsp)
3940 lea 0x40-$bias($a_ptr), $a_ptr # $a_ptr is still valid
3941 lea $Z1sqr(%rsp), $r_ptr # Z1^2
3942 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Z1sqr, in1_z);
3944 pcmpeqd %xmm4, %xmm5
3945 pshufd \$0xb1, %xmm3, %xmm4
3946 mov 0x00($b_ptr), $src0 # $b_ptr is still valid
3947 #lea 0x00($b_ptr), $b_ptr
3948 mov $acc4, $acc1 # harmonize sqr output and mul input
3950 pshufd \$0, %xmm5, %xmm5 # in1infty
3951 pshufd \$0x1e, %xmm4, %xmm3
3956 pcmpeqd %xmm3, %xmm4
3957 pshufd \$0, %xmm4, %xmm4 # in2infty
3959 lea $Z1sqr-$bias(%rsp), $a_ptr
3961 lea $U2(%rsp), $r_ptr # U2 = X2*Z1^2
3962 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, Z1sqr, in2_x);
3964 lea $in1_x(%rsp), $b_ptr
3965 lea $H(%rsp), $r_ptr # H = U2 - U1
3966 call __ecp_nistz256_sub_from$x # p256_sub(H, U2, in1_x);
3968 `&load_for_mul("$Z1sqr(%rsp)", "$in1_z(%rsp)", "$src0")`
3969 lea $S2(%rsp), $r_ptr # S2 = Z1^3
3970 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, Z1sqr, in1_z);
3972 `&load_for_mul("$H(%rsp)", "$in1_z(%rsp)", "$src0")`
3973 lea $res_z(%rsp), $r_ptr # Z3 = H*Z1*Z2
3974 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, H, in1_z);
3976 `&load_for_mul("$S2(%rsp)", "$in2_y(%rsp)", "$src0")`
3977 lea $S2(%rsp), $r_ptr # S2 = Y2*Z1^3
3978 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, S2, in2_y);
3980 lea $in1_y(%rsp), $b_ptr
3981 lea $R(%rsp), $r_ptr # R = S2 - S1
3982 call __ecp_nistz256_sub_from$x # p256_sub(R, S2, in1_y);
3984 `&load_for_sqr("$H(%rsp)", "$src0")`
3985 lea $Hsqr(%rsp), $r_ptr # H^2
3986 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Hsqr, H);
3988 `&load_for_sqr("$R(%rsp)", "$src0")`
3989 lea $Rsqr(%rsp), $r_ptr # R^2
3990 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Rsqr, R);
3992 `&load_for_mul("$H(%rsp)", "$Hsqr(%rsp)", "$src0")`
3993 lea $Hcub(%rsp), $r_ptr # H^3
3994 call __ecp_nistz256_mul_mont$x # p256_mul_mont(Hcub, Hsqr, H);
3996 `&load_for_mul("$Hsqr(%rsp)", "$in1_x(%rsp)", "$src0")`
3997 lea $U2(%rsp), $r_ptr # U1*H^2
3998 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, in1_x, Hsqr);
4001 #######################################################################
4002 # operate in 4-5-0-1 "name space" that matches multiplication output
4004 my ($acc0,$acc1,$acc2,$acc3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
4005 my ($poly1, $poly3)=($acc6,$acc7);
4008 #lea $U2(%rsp), $a_ptr
4009 #lea $Hsqr(%rsp), $r_ptr # 2*U1*H^2
4010 #call __ecp_nistz256_mul_by_2 # ecp_nistz256_mul_by_2(Hsqr, U2);
4013 add $acc0, $acc0 # a0:a3+a0:a3
4014 lea $Rsqr(%rsp), $a_ptr
4031 mov 8*0($a_ptr), $t0
4033 mov 8*1($a_ptr), $t1
4035 mov 8*2($a_ptr), $t2
4037 mov 8*3($a_ptr), $t3
4039 call __ecp_nistz256_sub$x # p256_sub(res_x, Rsqr, Hsqr);
4041 lea $Hcub(%rsp), $b_ptr
4042 lea $res_x(%rsp), $r_ptr
4043 call __ecp_nistz256_sub_from$x # p256_sub(res_x, res_x, Hcub);
4045 mov $U2+8*0(%rsp), $t0
4046 mov $U2+8*1(%rsp), $t1
4047 mov $U2+8*2(%rsp), $t2
4048 mov $U2+8*3(%rsp), $t3
4049 lea $H(%rsp), $r_ptr
4051 call __ecp_nistz256_sub$x # p256_sub(H, U2, res_x);
4053 mov $acc0, 8*0($r_ptr) # save the result, as
4054 mov $acc1, 8*1($r_ptr) # __ecp_nistz256_sub doesn't
4055 mov $acc2, 8*2($r_ptr)
4056 mov $acc3, 8*3($r_ptr)
4060 `&load_for_mul("$Hcub(%rsp)", "$in1_y(%rsp)", "$src0")`
4061 lea $S2(%rsp), $r_ptr
4062 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, Hcub, in1_y);
4064 `&load_for_mul("$H(%rsp)", "$R(%rsp)", "$src0")`
4065 lea $H(%rsp), $r_ptr
4066 call __ecp_nistz256_mul_mont$x # p256_mul_mont(H, H, R);
4068 lea $S2(%rsp), $b_ptr
4069 lea $res_y(%rsp), $r_ptr
4070 call __ecp_nistz256_sub_from$x # p256_sub(res_y, H, S2);
4072 movq %xmm0, $r_ptr # restore $r_ptr
4074 movdqa %xmm5, %xmm0 # copy_conditional(res_z, ONE, in1infty);
4076 pandn $res_z(%rsp), %xmm0
4078 pandn $res_z+0x10(%rsp), %xmm1
4080 pand .LONE_mont(%rip), %xmm2
4081 pand .LONE_mont+0x10(%rip), %xmm3
4085 movdqa %xmm4, %xmm0 # copy_conditional(res_z, in1_z, in2infty);
4091 pand $in1_z(%rsp), %xmm2
4092 pand $in1_z+0x10(%rsp), %xmm3
4095 movdqu %xmm2, 0x40($r_ptr)
4096 movdqu %xmm3, 0x50($r_ptr)
4098 movdqa %xmm5, %xmm0 # copy_conditional(res_x, in2_x, in1infty);
4100 pandn $res_x(%rsp), %xmm0
4102 pandn $res_x+0x10(%rsp), %xmm1
4104 pand $in2_x(%rsp), %xmm2
4105 pand $in2_x+0x10(%rsp), %xmm3
4109 movdqa %xmm4, %xmm0 # copy_conditional(res_x, in1_x, in2infty);
4115 pand $in1_x(%rsp), %xmm2
4116 pand $in1_x+0x10(%rsp), %xmm3
4119 movdqu %xmm2, 0x00($r_ptr)
4120 movdqu %xmm3, 0x10($r_ptr)
4122 movdqa %xmm5, %xmm0 # copy_conditional(res_y, in2_y, in1infty);
4124 pandn $res_y(%rsp), %xmm0
4126 pandn $res_y+0x10(%rsp), %xmm1
4128 pand $in2_y(%rsp), %xmm2
4129 pand $in2_y+0x10(%rsp), %xmm3
4133 movdqa %xmm4, %xmm0 # copy_conditional(res_y, in1_y, in2infty);
4139 pand $in1_y(%rsp), %xmm2
4140 pand $in1_y+0x10(%rsp), %xmm3
4143 movdqu %xmm2, 0x20($r_ptr)
4144 movdqu %xmm3, 0x30($r_ptr)
4146 lea 32*15+56(%rsp), %rsi
4161 .cfi_def_cfa_register %rsp
4162 .Ladd_affine${x}_epilogue:
4165 .size ecp_nistz256_point_add_affine$sfx,.-ecp_nistz256_point_add_affine$sfx
4168 &gen_add_affine("q");
4170 ########################################################################
4174 ########################################################################
4175 # operate in 4-5-0-1 "name space" that matches multiplication output
4177 my ($a0,$a1,$a2,$a3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
4180 .type __ecp_nistz256_add_tox,\@abi-omnipotent
4182 __ecp_nistz256_add_tox:
4185 adc 8*0($b_ptr), $a0
4186 adc 8*1($b_ptr), $a1
4188 adc 8*2($b_ptr), $a2
4189 adc 8*3($b_ptr), $a3
4204 mov $a0, 8*0($r_ptr)
4206 mov $a1, 8*1($r_ptr)
4208 mov $a2, 8*2($r_ptr)
4209 mov $a3, 8*3($r_ptr)
4213 .size __ecp_nistz256_add_tox,.-__ecp_nistz256_add_tox
4215 .type __ecp_nistz256_sub_fromx,\@abi-omnipotent
4217 __ecp_nistz256_sub_fromx:
4220 sbb 8*0($b_ptr), $a0
4221 sbb 8*1($b_ptr), $a1
4223 sbb 8*2($b_ptr), $a2
4224 sbb 8*3($b_ptr), $a3
4239 mov $a0, 8*0($r_ptr)
4241 mov $a1, 8*1($r_ptr)
4243 mov $a2, 8*2($r_ptr)
4244 mov $a3, 8*3($r_ptr)
4248 .size __ecp_nistz256_sub_fromx,.-__ecp_nistz256_sub_fromx
4250 .type __ecp_nistz256_subx,\@abi-omnipotent
4252 __ecp_nistz256_subx:
4279 .size __ecp_nistz256_subx,.-__ecp_nistz256_subx
4281 .type __ecp_nistz256_mul_by_2x,\@abi-omnipotent
4283 __ecp_nistz256_mul_by_2x:
4286 adc $a0, $a0 # a0:a3+a0:a3
4305 mov $a0, 8*0($r_ptr)
4307 mov $a1, 8*1($r_ptr)
4309 mov $a2, 8*2($r_ptr)
4310 mov $a3, 8*3($r_ptr)
4314 .size __ecp_nistz256_mul_by_2x,.-__ecp_nistz256_mul_by_2x
4319 &gen_add_affine("x");
4323 # EXCEPTION_DISPOSITION handler (EXCEPTION_RECORD *rec,ULONG64 frame,
4324 # CONTEXT *context,DISPATCHER_CONTEXT *disp)
4332 .extern __imp_RtlVirtualUnwind
4334 .type short_handler,\@abi-omnipotent
4348 mov 120($context),%rax # pull context->Rax
4349 mov 248($context),%rbx # pull context->Rip
4351 mov 8($disp),%rsi # disp->ImageBase
4352 mov 56($disp),%r11 # disp->HandlerData
4354 mov 0(%r11),%r10d # HandlerData[0]
4355 lea (%rsi,%r10),%r10 # end of prologue label
4356 cmp %r10,%rbx # context->Rip<end of prologue label
4357 jb .Lcommon_seh_tail
4359 mov 152($context),%rax # pull context->Rsp
4361 mov 4(%r11),%r10d # HandlerData[1]
4362 lea (%rsi,%r10),%r10 # epilogue label
4363 cmp %r10,%rbx # context->Rip>=epilogue label
4364 jae .Lcommon_seh_tail
4370 mov %r12,216($context) # restore context->R12
4371 mov %r13,224($context) # restore context->R13
4373 jmp .Lcommon_seh_tail
4374 .size short_handler,.-short_handler
4376 .type full_handler,\@abi-omnipotent
4390 mov 120($context),%rax # pull context->Rax
4391 mov 248($context),%rbx # pull context->Rip
4393 mov 8($disp),%rsi # disp->ImageBase
4394 mov 56($disp),%r11 # disp->HandlerData
4396 mov 0(%r11),%r10d # HandlerData[0]
4397 lea (%rsi,%r10),%r10 # end of prologue label
4398 cmp %r10,%rbx # context->Rip<end of prologue label
4399 jb .Lcommon_seh_tail
4401 mov 152($context),%rax # pull context->Rsp
4403 mov 4(%r11),%r10d # HandlerData[1]
4404 lea (%rsi,%r10),%r10 # epilogue label
4405 cmp %r10,%rbx # context->Rip>=epilogue label
4406 jae .Lcommon_seh_tail
4408 mov 8(%r11),%r10d # HandlerData[2]
4409 lea (%rax,%r10),%rax
4417 mov %rbx,144($context) # restore context->Rbx
4418 mov %rbp,160($context) # restore context->Rbp
4419 mov %r12,216($context) # restore context->R12
4420 mov %r13,224($context) # restore context->R13
4421 mov %r14,232($context) # restore context->R14
4422 mov %r15,240($context) # restore context->R15
4427 mov %rax,152($context) # restore context->Rsp
4428 mov %rsi,168($context) # restore context->Rsi
4429 mov %rdi,176($context) # restore context->Rdi
4431 mov 40($disp),%rdi # disp->ContextRecord
4432 mov $context,%rsi # context
4433 mov \$154,%ecx # sizeof(CONTEXT)
4434 .long 0xa548f3fc # cld; rep movsq
4437 xor %rcx,%rcx # arg1, UNW_FLAG_NHANDLER
4438 mov 8(%rsi),%rdx # arg2, disp->ImageBase
4439 mov 0(%rsi),%r8 # arg3, disp->ControlPc
4440 mov 16(%rsi),%r9 # arg4, disp->FunctionEntry
4441 mov 40(%rsi),%r10 # disp->ContextRecord
4442 lea 56(%rsi),%r11 # &disp->HandlerData
4443 lea 24(%rsi),%r12 # &disp->EstablisherFrame
4444 mov %r10,32(%rsp) # arg5
4445 mov %r11,40(%rsp) # arg6
4446 mov %r12,48(%rsp) # arg7
4447 mov %rcx,56(%rsp) # arg8, (NULL)
4448 call *__imp_RtlVirtualUnwind(%rip)
4450 mov \$1,%eax # ExceptionContinueSearch
4462 .size full_handler,.-full_handler
4466 .rva .LSEH_begin_ecp_nistz256_mul_by_2
4467 .rva .LSEH_end_ecp_nistz256_mul_by_2
4468 .rva .LSEH_info_ecp_nistz256_mul_by_2
4470 .rva .LSEH_begin_ecp_nistz256_div_by_2
4471 .rva .LSEH_end_ecp_nistz256_div_by_2
4472 .rva .LSEH_info_ecp_nistz256_div_by_2
4474 .rva .LSEH_begin_ecp_nistz256_mul_by_3
4475 .rva .LSEH_end_ecp_nistz256_mul_by_3
4476 .rva .LSEH_info_ecp_nistz256_mul_by_3
4478 .rva .LSEH_begin_ecp_nistz256_add
4479 .rva .LSEH_end_ecp_nistz256_add
4480 .rva .LSEH_info_ecp_nistz256_add
4482 .rva .LSEH_begin_ecp_nistz256_sub
4483 .rva .LSEH_end_ecp_nistz256_sub
4484 .rva .LSEH_info_ecp_nistz256_sub
4486 .rva .LSEH_begin_ecp_nistz256_neg
4487 .rva .LSEH_end_ecp_nistz256_neg
4488 .rva .LSEH_info_ecp_nistz256_neg
4490 .rva .LSEH_begin_ecp_nistz256_ord_mul_mont
4491 .rva .LSEH_end_ecp_nistz256_ord_mul_mont
4492 .rva .LSEH_info_ecp_nistz256_ord_mul_mont
4494 .rva .LSEH_begin_ecp_nistz256_ord_sqr_mont
4495 .rva .LSEH_end_ecp_nistz256_ord_sqr_mont
4496 .rva .LSEH_info_ecp_nistz256_ord_sqr_mont
4498 $code.=<<___ if ($addx);
4499 .rva .LSEH_begin_ecp_nistz256_ord_mul_montx
4500 .rva .LSEH_end_ecp_nistz256_ord_mul_montx
4501 .rva .LSEH_info_ecp_nistz256_ord_mul_montx
4503 .rva .LSEH_begin_ecp_nistz256_ord_sqr_montx
4504 .rva .LSEH_end_ecp_nistz256_ord_sqr_montx
4505 .rva .LSEH_info_ecp_nistz256_ord_sqr_montx
4508 .rva .LSEH_begin_ecp_nistz256_to_mont
4509 .rva .LSEH_end_ecp_nistz256_to_mont
4510 .rva .LSEH_info_ecp_nistz256_to_mont
4512 .rva .LSEH_begin_ecp_nistz256_mul_mont
4513 .rva .LSEH_end_ecp_nistz256_mul_mont
4514 .rva .LSEH_info_ecp_nistz256_mul_mont
4516 .rva .LSEH_begin_ecp_nistz256_sqr_mont
4517 .rva .LSEH_end_ecp_nistz256_sqr_mont
4518 .rva .LSEH_info_ecp_nistz256_sqr_mont
4520 .rva .LSEH_begin_ecp_nistz256_from_mont
4521 .rva .LSEH_end_ecp_nistz256_from_mont
4522 .rva .LSEH_info_ecp_nistz256_from_mont
4524 .rva .LSEH_begin_ecp_nistz256_gather_w5
4525 .rva .LSEH_end_ecp_nistz256_gather_w5
4526 .rva .LSEH_info_ecp_nistz256_gather_wX
4528 .rva .LSEH_begin_ecp_nistz256_gather_w7
4529 .rva .LSEH_end_ecp_nistz256_gather_w7
4530 .rva .LSEH_info_ecp_nistz256_gather_wX
4532 $code.=<<___ if ($avx>1);
4533 .rva .LSEH_begin_ecp_nistz256_avx2_gather_w5
4534 .rva .LSEH_end_ecp_nistz256_avx2_gather_w5
4535 .rva .LSEH_info_ecp_nistz256_avx2_gather_wX
4537 .rva .LSEH_begin_ecp_nistz256_avx2_gather_w7
4538 .rva .LSEH_end_ecp_nistz256_avx2_gather_w7
4539 .rva .LSEH_info_ecp_nistz256_avx2_gather_wX
4542 .rva .LSEH_begin_ecp_nistz256_point_double
4543 .rva .LSEH_end_ecp_nistz256_point_double
4544 .rva .LSEH_info_ecp_nistz256_point_double
4546 .rva .LSEH_begin_ecp_nistz256_point_add
4547 .rva .LSEH_end_ecp_nistz256_point_add
4548 .rva .LSEH_info_ecp_nistz256_point_add
4550 .rva .LSEH_begin_ecp_nistz256_point_add_affine
4551 .rva .LSEH_end_ecp_nistz256_point_add_affine
4552 .rva .LSEH_info_ecp_nistz256_point_add_affine
4554 $code.=<<___ if ($addx);
4555 .rva .LSEH_begin_ecp_nistz256_point_doublex
4556 .rva .LSEH_end_ecp_nistz256_point_doublex
4557 .rva .LSEH_info_ecp_nistz256_point_doublex
4559 .rva .LSEH_begin_ecp_nistz256_point_addx
4560 .rva .LSEH_end_ecp_nistz256_point_addx
4561 .rva .LSEH_info_ecp_nistz256_point_addx
4563 .rva .LSEH_begin_ecp_nistz256_point_add_affinex
4564 .rva .LSEH_end_ecp_nistz256_point_add_affinex
4565 .rva .LSEH_info_ecp_nistz256_point_add_affinex
4571 .LSEH_info_ecp_nistz256_mul_by_2:
4574 .rva .Lmul_by_2_body,.Lmul_by_2_epilogue # HandlerData[]
4575 .LSEH_info_ecp_nistz256_div_by_2:
4578 .rva .Ldiv_by_2_body,.Ldiv_by_2_epilogue # HandlerData[]
4579 .LSEH_info_ecp_nistz256_mul_by_3:
4582 .rva .Lmul_by_3_body,.Lmul_by_3_epilogue # HandlerData[]
4583 .LSEH_info_ecp_nistz256_add:
4586 .rva .Ladd_body,.Ladd_epilogue # HandlerData[]
4587 .LSEH_info_ecp_nistz256_sub:
4590 .rva .Lsub_body,.Lsub_epilogue # HandlerData[]
4591 .LSEH_info_ecp_nistz256_neg:
4594 .rva .Lneg_body,.Lneg_epilogue # HandlerData[]
4595 .LSEH_info_ecp_nistz256_ord_mul_mont:
4598 .rva .Lord_mul_body,.Lord_mul_epilogue # HandlerData[]
4600 .LSEH_info_ecp_nistz256_ord_sqr_mont:
4603 .rva .Lord_sqr_body,.Lord_sqr_epilogue # HandlerData[]
4606 $code.=<<___ if ($addx);
4607 .LSEH_info_ecp_nistz256_ord_mul_montx:
4610 .rva .Lord_mulx_body,.Lord_mulx_epilogue # HandlerData[]
4612 .LSEH_info_ecp_nistz256_ord_sqr_montx:
4615 .rva .Lord_sqrx_body,.Lord_sqrx_epilogue # HandlerData[]
4619 .LSEH_info_ecp_nistz256_to_mont:
4622 .rva .Lmul_body,.Lmul_epilogue # HandlerData[]
4624 .LSEH_info_ecp_nistz256_mul_mont:
4627 .rva .Lmul_body,.Lmul_epilogue # HandlerData[]
4629 .LSEH_info_ecp_nistz256_sqr_mont:
4632 .rva .Lsqr_body,.Lsqr_epilogue # HandlerData[]
4634 .LSEH_info_ecp_nistz256_from_mont:
4637 .rva .Lfrom_body,.Lfrom_epilogue # HandlerData[]
4638 .LSEH_info_ecp_nistz256_gather_wX:
4639 .byte 0x01,0x33,0x16,0x00
4640 .byte 0x33,0xf8,0x09,0x00 #movaps 0x90(rsp),xmm15
4641 .byte 0x2e,0xe8,0x08,0x00 #movaps 0x80(rsp),xmm14
4642 .byte 0x29,0xd8,0x07,0x00 #movaps 0x70(rsp),xmm13
4643 .byte 0x24,0xc8,0x06,0x00 #movaps 0x60(rsp),xmm12
4644 .byte 0x1f,0xb8,0x05,0x00 #movaps 0x50(rsp),xmm11
4645 .byte 0x1a,0xa8,0x04,0x00 #movaps 0x40(rsp),xmm10
4646 .byte 0x15,0x98,0x03,0x00 #movaps 0x30(rsp),xmm9
4647 .byte 0x10,0x88,0x02,0x00 #movaps 0x20(rsp),xmm8
4648 .byte 0x0c,0x78,0x01,0x00 #movaps 0x10(rsp),xmm7
4649 .byte 0x08,0x68,0x00,0x00 #movaps 0x00(rsp),xmm6
4650 .byte 0x04,0x01,0x15,0x00 #sub rsp,0xa8
4653 $code.=<<___ if ($avx>1);
4654 .LSEH_info_ecp_nistz256_avx2_gather_wX:
4655 .byte 0x01,0x36,0x17,0x0b
4656 .byte 0x36,0xf8,0x09,0x00 # vmovaps 0x90(rsp),xmm15
4657 .byte 0x31,0xe8,0x08,0x00 # vmovaps 0x80(rsp),xmm14
4658 .byte 0x2c,0xd8,0x07,0x00 # vmovaps 0x70(rsp),xmm13
4659 .byte 0x27,0xc8,0x06,0x00 # vmovaps 0x60(rsp),xmm12
4660 .byte 0x22,0xb8,0x05,0x00 # vmovaps 0x50(rsp),xmm11
4661 .byte 0x1d,0xa8,0x04,0x00 # vmovaps 0x40(rsp),xmm10
4662 .byte 0x18,0x98,0x03,0x00 # vmovaps 0x30(rsp),xmm9
4663 .byte 0x13,0x88,0x02,0x00 # vmovaps 0x20(rsp),xmm8
4664 .byte 0x0e,0x78,0x01,0x00 # vmovaps 0x10(rsp),xmm7
4665 .byte 0x09,0x68,0x00,0x00 # vmovaps 0x00(rsp),xmm6
4666 .byte 0x04,0x01,0x15,0x00 # sub rsp,0xa8
4667 .byte 0x00,0xb3,0x00,0x00 # set_frame r11
4671 .LSEH_info_ecp_nistz256_point_double:
4674 .rva .Lpoint_doubleq_body,.Lpoint_doubleq_epilogue # HandlerData[]
4676 .LSEH_info_ecp_nistz256_point_add:
4679 .rva .Lpoint_addq_body,.Lpoint_addq_epilogue # HandlerData[]
4681 .LSEH_info_ecp_nistz256_point_add_affine:
4684 .rva .Ladd_affineq_body,.Ladd_affineq_epilogue # HandlerData[]
4687 $code.=<<___ if ($addx);
4689 .LSEH_info_ecp_nistz256_point_doublex:
4692 .rva .Lpoint_doublex_body,.Lpoint_doublex_epilogue # HandlerData[]
4694 .LSEH_info_ecp_nistz256_point_addx:
4697 .rva .Lpoint_addx_body,.Lpoint_addx_epilogue # HandlerData[]
4699 .LSEH_info_ecp_nistz256_point_add_affinex:
4702 .rva .Ladd_affinex_body,.Ladd_affinex_epilogue # HandlerData[]
4707 ########################################################################
4708 # Convert ecp_nistz256_table.c to layout expected by ecp_nistz_gather_w7
4710 open TABLE,"<ecp_nistz256_table.c" or
4711 open TABLE,"<${dir}../ecp_nistz256_table.c" or
4712 die "failed to open ecp_nistz256_table.c:",$!;
4717 s/TOBN\(\s*(0x[0-9a-f]+),\s*(0x[0-9a-f]+)\s*\)/push @arr,hex($2),hex($1)/geo;
4721 die "insane number of elements" if ($#arr != 64*16*37-1);
4725 .globl ecp_nistz256_precomputed
4726 .type ecp_nistz256_precomputed,\@object
4728 ecp_nistz256_precomputed:
4730 while (@line=splice(@arr,0,16)) {
4731 print ".long\t",join(',',map { sprintf "0x%08x",$_} @line),"\n";
4734 .size ecp_nistz256_precomputed,.-ecp_nistz256_precomputed
4737 $code =~ s/\`([^\`]*)\`/eval $1/gem;
4739 close STDOUT or die "error closing STDOUT: $!";