3 ##############################################################################
5 # Copyright 2014 Intel Corporation #
7 # Licensed under the Apache License, Version 2.0 (the "License"); #
8 # you may not use this file except in compliance with the License. #
9 # You may obtain a copy of the License at #
11 # http://www.apache.org/licenses/LICENSE-2.0 #
13 # Unless required by applicable law or agreed to in writing, software #
14 # distributed under the License is distributed on an "AS IS" BASIS, #
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
16 # See the License for the specific language governing permissions and #
17 # limitations under the License. #
19 ##############################################################################
21 # Developers and authors: #
22 # Shay Gueron (1, 2), and Vlad Krasnov (1) #
23 # (1) Intel Corporation, Israel Development Center #
24 # (2) University of Haifa #
26 # S.Gueron and V.Krasnov, "Fast Prime Field Elliptic Curve Cryptography with#
29 ##############################################################################
31 # Further optimization by <appro@openssl.org>:
33 # this/original with/without -DECP_NISTZ256_ASM(*)
34 # Opteron +12-49% +110-150%
35 # Bulldozer +14-45% +175-210%
37 # Westmere +12-34% +80-87%
38 # Sandy Bridge +9-35% +110-120%
39 # Ivy Bridge +9-35% +110-125%
40 # Haswell +8-37% +140-160%
41 # Broadwell +18-58% +145-210%
42 # Atom +15-50% +130-180%
43 # VIA Nano +43-160% +300-480%
45 # (*) "without -DECP_NISTZ256_ASM" refers to build with
46 # "enable-ec_nistp_64_gcc_128";
48 # Ranges denote minimum and maximum improvement coefficients depending
49 # on benchmark. Lower coefficients are for ECDSA sign, relatively fastest
50 # server-side operation. Keep in mind that +100% means 2x improvement.
54 if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
56 $win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
58 $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
59 ( $xlate="${dir}x86_64-xlate.pl" and -f $xlate ) or
60 ( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
61 die "can't locate x86_64-xlate.pl";
63 open OUT,"| \"$^X\" $xlate $flavour $output";
66 if (`$ENV{CC} -Wa,-v -c -o /dev/null -x assembler /dev/null 2>&1`
67 =~ /GNU assembler version ([2-9]\.[0-9]+)/) {
68 $avx = ($1>=2.19) + ($1>=2.22);
72 if (!$addx && $win64 && ($flavour =~ /nasm/ || $ENV{ASM} =~ /nasm/) &&
73 `nasm -v 2>&1` =~ /NASM version ([2-9]\.[0-9]+)/) {
74 $avx = ($1>=2.09) + ($1>=2.10);
78 if (!$addx && $win64 && ($flavour =~ /masm/ || $ENV{ASM} =~ /ml64/) &&
79 `ml64 2>&1` =~ /Version ([0-9]+)\./) {
80 $avx = ($1>=10) + ($1>=11);
84 if (!$addx && `$ENV{CC} -v 2>&1` =~ /((?:^clang|LLVM) version|based on LLVM) ([3-9])\.([0-9]+)/) {
85 my $ver = $2 + $3/100.0; # 3.1->3.01, 3.10->3.10
86 $avx = ($ver>=3.0) + ($ver>=3.01);
92 .extern OPENSSL_ia32cap_P
97 .quad 0xffffffffffffffff, 0x00000000ffffffff, 0x0000000000000000, 0xffffffff00000001
99 # 2^512 mod P precomputed for NIST P256 polynomial
101 .quad 0x0000000000000003, 0xfffffffbffffffff, 0xfffffffffffffffe, 0x00000004fffffffd
104 .long 1,1,1,1,1,1,1,1
106 .long 2,2,2,2,2,2,2,2
108 .long 3,3,3,3,3,3,3,3
110 .quad 0x0000000000000001, 0xffffffff00000000, 0xffffffffffffffff, 0x00000000fffffffe
114 ################################################################################
115 # void ecp_nistz256_mul_by_2(uint64_t res[4], uint64_t a[4]);
117 my ($a0,$a1,$a2,$a3)=map("%r$_",(8..11));
118 my ($t0,$t1,$t2,$t3,$t4)=("%rax","%rdx","%rcx","%r12","%r13");
119 my ($r_ptr,$a_ptr,$b_ptr)=("%rdi","%rsi","%rdx");
123 .globl ecp_nistz256_mul_by_2
124 .type ecp_nistz256_mul_by_2,\@function,2
126 ecp_nistz256_mul_by_2:
132 add $a0, $a0 # a0:a3+a0:a3
136 lea .Lpoly(%rip), $a_ptr
163 .size ecp_nistz256_mul_by_2,.-ecp_nistz256_mul_by_2
165 ################################################################################
166 # void ecp_nistz256_div_by_2(uint64_t res[4], uint64_t a[4]);
167 .globl ecp_nistz256_div_by_2
168 .type ecp_nistz256_div_by_2,\@function,2
170 ecp_nistz256_div_by_2:
179 lea .Lpoly(%rip), $a_ptr
190 xor $a_ptr, $a_ptr # borrow $a_ptr
199 mov $a1, $t0 # a0:a3>>1
223 .size ecp_nistz256_div_by_2,.-ecp_nistz256_div_by_2
225 ################################################################################
226 # void ecp_nistz256_mul_by_3(uint64_t res[4], uint64_t a[4]);
227 .globl ecp_nistz256_mul_by_3
228 .type ecp_nistz256_mul_by_3,\@function,2
230 ecp_nistz256_mul_by_3:
237 add $a0, $a0 # a0:a3+a0:a3
249 sbb .Lpoly+8*1(%rip), $a1
252 sbb .Lpoly+8*3(%rip), $a3
261 add 8*0($a_ptr), $a0 # a0:a3+=a_ptr[0:3]
271 sbb .Lpoly+8*1(%rip), $a1
274 sbb .Lpoly+8*3(%rip), $a3
289 .size ecp_nistz256_mul_by_3,.-ecp_nistz256_mul_by_3
291 ################################################################################
292 # void ecp_nistz256_add(uint64_t res[4], uint64_t a[4], uint64_t b[4]);
293 .globl ecp_nistz256_add
294 .type ecp_nistz256_add,\@function,3
305 lea .Lpoly(%rip), $a_ptr
335 .size ecp_nistz256_add,.-ecp_nistz256_add
337 ################################################################################
338 # void ecp_nistz256_sub(uint64_t res[4], uint64_t a[4], uint64_t b[4]);
339 .globl ecp_nistz256_sub
340 .type ecp_nistz256_sub,\@function,3
351 lea .Lpoly(%rip), $a_ptr
381 .size ecp_nistz256_sub,.-ecp_nistz256_sub
383 ################################################################################
384 # void ecp_nistz256_neg(uint64_t res[4], uint64_t a[4]);
385 .globl ecp_nistz256_neg
386 .type ecp_nistz256_neg,\@function,2
403 lea .Lpoly(%rip), $a_ptr
427 .size ecp_nistz256_neg,.-ecp_nistz256_neg
431 my ($r_ptr,$a_ptr,$b_org,$b_ptr)=("%rdi","%rsi","%rdx","%rbx");
432 my ($acc0,$acc1,$acc2,$acc3,$acc4,$acc5,$acc6,$acc7)=map("%r$_",(8..15));
433 my ($t0,$t1,$t2,$t3,$t4)=("%rcx","%rbp","%rbx","%rdx","%rax");
434 my ($poly1,$poly3)=($acc6,$acc7);
437 ################################################################################
438 # void ecp_nistz256_to_mont(
441 .globl ecp_nistz256_to_mont
442 .type ecp_nistz256_to_mont,\@function,2
444 ecp_nistz256_to_mont:
446 $code.=<<___ if ($addx);
448 and OPENSSL_ia32cap_P+8(%rip), %ecx
451 lea .LRR(%rip), $b_org
453 .size ecp_nistz256_to_mont,.-ecp_nistz256_to_mont
455 ################################################################################
456 # void ecp_nistz256_mul_mont(
461 .globl ecp_nistz256_mul_mont
462 .type ecp_nistz256_mul_mont,\@function,3
464 ecp_nistz256_mul_mont:
466 $code.=<<___ if ($addx);
468 and OPENSSL_ia32cap_P+8(%rip), %ecx
479 $code.=<<___ if ($addx);
485 mov 8*0($b_org), %rax
486 mov 8*0($a_ptr), $acc1
487 mov 8*1($a_ptr), $acc2
488 mov 8*2($a_ptr), $acc3
489 mov 8*3($a_ptr), $acc4
491 call __ecp_nistz256_mul_montq
493 $code.=<<___ if ($addx);
499 mov 8*0($b_org), %rdx
500 mov 8*0($a_ptr), $acc1
501 mov 8*1($a_ptr), $acc2
502 mov 8*2($a_ptr), $acc3
503 mov 8*3($a_ptr), $acc4
504 lea -128($a_ptr), $a_ptr # control u-op density
506 call __ecp_nistz256_mul_montx
517 .size ecp_nistz256_mul_mont,.-ecp_nistz256_mul_mont
519 .type __ecp_nistz256_mul_montq,\@abi-omnipotent
521 __ecp_nistz256_mul_montq:
522 ########################################################################
526 mov .Lpoly+8*1(%rip),$poly1
532 mov .Lpoly+8*3(%rip),$poly3
551 ########################################################################
552 # First reduction step
553 # Basically now we want to multiply acc[0] by p256,
554 # and add the result to the acc.
555 # Due to the special form of p256 we do some optimizations
557 # acc[0] x p256[0..1] = acc[0] x 2^96 - acc[0]
558 # then we add acc[0] and get acc[0] x 2^96
564 add $acc0, $acc1 # +=acc[0]<<96
567 mov 8*1($b_ptr), %rax
572 ########################################################################
605 ########################################################################
606 # Second reduction step
614 mov 8*2($b_ptr), %rax
619 ########################################################################
652 ########################################################################
653 # Third reduction step
661 mov 8*3($b_ptr), %rax
666 ########################################################################
699 ########################################################################
700 # Final reduction step
713 ########################################################################
714 # Branch-less conditional subtraction of P
715 sub \$-1, $acc4 # .Lpoly[0]
717 sbb $poly1, $acc5 # .Lpoly[1]
718 sbb \$0, $acc0 # .Lpoly[2]
720 sbb $poly3, $acc1 # .Lpoly[3]
725 mov $acc4, 8*0($r_ptr)
727 mov $acc5, 8*1($r_ptr)
729 mov $acc0, 8*2($r_ptr)
730 mov $acc1, 8*3($r_ptr)
733 .size __ecp_nistz256_mul_montq,.-__ecp_nistz256_mul_montq
735 ################################################################################
736 # void ecp_nistz256_sqr_mont(
740 # we optimize the square according to S.Gueron and V.Krasnov,
741 # "Speeding up Big-Number Squaring"
742 .globl ecp_nistz256_sqr_mont
743 .type ecp_nistz256_sqr_mont,\@function,2
745 ecp_nistz256_sqr_mont:
747 $code.=<<___ if ($addx);
749 and OPENSSL_ia32cap_P+8(%rip), %ecx
759 $code.=<<___ if ($addx);
764 mov 8*0($a_ptr), %rax
765 mov 8*1($a_ptr), $acc6
766 mov 8*2($a_ptr), $acc7
767 mov 8*3($a_ptr), $acc0
769 call __ecp_nistz256_sqr_montq
771 $code.=<<___ if ($addx);
776 mov 8*0($a_ptr), %rdx
777 mov 8*1($a_ptr), $acc6
778 mov 8*2($a_ptr), $acc7
779 mov 8*3($a_ptr), $acc0
780 lea -128($a_ptr), $a_ptr # control u-op density
782 call __ecp_nistz256_sqr_montx
793 .size ecp_nistz256_sqr_mont,.-ecp_nistz256_sqr_mont
795 .type __ecp_nistz256_sqr_montq,\@abi-omnipotent
797 __ecp_nistz256_sqr_montq:
799 mulq $acc6 # a[1]*a[0]
804 mulq $acc5 # a[0]*a[2]
810 mulq $acc5 # a[0]*a[3]
816 #################################
817 mulq $acc6 # a[1]*a[2]
823 mulq $acc6 # a[1]*a[3]
831 #################################
832 mulq $acc7 # a[2]*a[3]
835 mov 8*0($a_ptr), %rax
839 add $acc1, $acc1 # acc1:6<<1
849 mov 8*1($a_ptr), %rax
855 mov 8*2($a_ptr), %rax
862 mov 8*3($a_ptr), %rax
872 mov .Lpoly+8*1(%rip), $a_ptr
873 mov .Lpoly+8*3(%rip), $t1
875 ##########################################
882 add $acc0, $acc1 # +=acc[0]<<96
888 ##########################################
901 ##########################################
914 ###########################################
927 ############################################
928 # Add the rest of the acc
937 sub \$-1, $acc4 # .Lpoly[0]
939 sbb $a_ptr, $acc5 # .Lpoly[1]
940 sbb \$0, $acc6 # .Lpoly[2]
942 sbb $t1, $acc7 # .Lpoly[3]
947 mov $acc4, 8*0($r_ptr)
949 mov $acc5, 8*1($r_ptr)
951 mov $acc6, 8*2($r_ptr)
952 mov $acc7, 8*3($r_ptr)
955 .size __ecp_nistz256_sqr_montq,.-__ecp_nistz256_sqr_montq
960 .type __ecp_nistz256_mul_montx,\@abi-omnipotent
962 __ecp_nistz256_mul_montx:
963 ########################################################################
965 mulx $acc1, $acc0, $acc1
966 mulx $acc2, $t0, $acc2
968 xor $acc5, $acc5 # cf=0
969 mulx $acc3, $t1, $acc3
970 mov .Lpoly+8*3(%rip), $poly3
972 mulx $acc4, $t0, $acc4
975 shlx $poly1,$acc0,$t1
977 shrx $poly1,$acc0,$t0
980 ########################################################################
981 # First reduction step
985 mulx $poly3, $t0, $t1
986 mov 8*1($b_ptr), %rdx
990 xor $acc0, $acc0 # $acc0=0,cf=0,of=0
992 ########################################################################
994 mulx 8*0+128($a_ptr), $t0, $t1
998 mulx 8*1+128($a_ptr), $t0, $t1
1002 mulx 8*2+128($a_ptr), $t0, $t1
1006 mulx 8*3+128($a_ptr), $t0, $t1
1009 shlx $poly1, $acc1, $t0
1011 shrx $poly1, $acc1, $t1
1017 ########################################################################
1018 # Second reduction step
1022 mulx $poly3, $t0, $t1
1023 mov 8*2($b_ptr), %rdx
1027 xor $acc1 ,$acc1 # $acc1=0,cf=0,of=0
1029 ########################################################################
1031 mulx 8*0+128($a_ptr), $t0, $t1
1035 mulx 8*1+128($a_ptr), $t0, $t1
1039 mulx 8*2+128($a_ptr), $t0, $t1
1043 mulx 8*3+128($a_ptr), $t0, $t1
1046 shlx $poly1, $acc2, $t0
1048 shrx $poly1, $acc2, $t1
1054 ########################################################################
1055 # Third reduction step
1059 mulx $poly3, $t0, $t1
1060 mov 8*3($b_ptr), %rdx
1064 xor $acc2, $acc2 # $acc2=0,cf=0,of=0
1066 ########################################################################
1068 mulx 8*0+128($a_ptr), $t0, $t1
1072 mulx 8*1+128($a_ptr), $t0, $t1
1076 mulx 8*2+128($a_ptr), $t0, $t1
1080 mulx 8*3+128($a_ptr), $t0, $t1
1083 shlx $poly1, $acc3, $t0
1085 shrx $poly1, $acc3, $t1
1091 ########################################################################
1092 # Fourth reduction step
1096 mulx $poly3, $t0, $t1
1098 mov .Lpoly+8*1(%rip), $poly1
1104 ########################################################################
1105 # Branch-less conditional subtraction of P
1108 sbb \$-1, $acc4 # .Lpoly[0]
1109 sbb $poly1, $acc5 # .Lpoly[1]
1110 sbb \$0, $acc0 # .Lpoly[2]
1112 sbb $poly3, $acc1 # .Lpoly[3]
1117 mov $acc4, 8*0($r_ptr)
1119 mov $acc5, 8*1($r_ptr)
1121 mov $acc0, 8*2($r_ptr)
1122 mov $acc1, 8*3($r_ptr)
1125 .size __ecp_nistz256_mul_montx,.-__ecp_nistz256_mul_montx
1127 .type __ecp_nistz256_sqr_montx,\@abi-omnipotent
1129 __ecp_nistz256_sqr_montx:
1130 mulx $acc6, $acc1, $acc2 # a[0]*a[1]
1131 mulx $acc7, $t0, $acc3 # a[0]*a[2]
1134 mulx $acc0, $t1, $acc4 # a[0]*a[3]
1138 xor $acc5, $acc5 # $acc5=0,cf=0,of=0
1140 #################################
1141 mulx $acc7, $t0, $t1 # a[1]*a[2]
1145 mulx $acc0, $t0, $t1 # a[1]*a[3]
1151 #################################
1152 mulx $acc0, $t0, $acc6 # a[2]*a[3]
1153 mov 8*0+128($a_ptr), %rdx
1154 xor $acc7, $acc7 # $acc7=0,cf=0,of=0
1155 adcx $acc1, $acc1 # acc1:6<<1
1158 adox $acc7, $acc6 # of=0
1160 mulx %rdx, $acc0, $t1
1161 mov 8*1+128($a_ptr), %rdx
1166 mov 8*2+128($a_ptr), %rdx
1172 mov 8*3+128($a_ptr), %rdx
1182 shlx $a_ptr, $acc0, $t0
1184 shrx $a_ptr, $acc0, $t4
1185 mov .Lpoly+8*3(%rip), $t1
1191 mulx $t1, $t0, $acc0
1194 shlx $a_ptr, $acc1, $t0
1196 shrx $a_ptr, $acc1, $t4
1202 mulx $t1, $t0, $acc1
1205 shlx $a_ptr, $acc2, $t0
1207 shrx $a_ptr, $acc2, $t4
1213 mulx $t1, $t0, $acc2
1216 shlx $a_ptr, $acc3, $t0
1218 shrx $a_ptr, $acc3, $t4
1224 mulx $t1, $t0, $acc3
1229 adc $acc0, $acc4 # accumulate upper half
1230 mov .Lpoly+8*1(%rip), $a_ptr
1238 xor %eax, %eax # cf=0
1239 sbb \$-1, $acc4 # .Lpoly[0]
1241 sbb $a_ptr, $acc5 # .Lpoly[1]
1242 sbb \$0, $acc6 # .Lpoly[2]
1244 sbb $t1, $acc7 # .Lpoly[3]
1249 mov $acc4, 8*0($r_ptr)
1251 mov $acc5, 8*1($r_ptr)
1253 mov $acc6, 8*2($r_ptr)
1254 mov $acc7, 8*3($r_ptr)
1257 .size __ecp_nistz256_sqr_montx,.-__ecp_nistz256_sqr_montx
1262 my ($r_ptr,$in_ptr)=("%rdi","%rsi");
1263 my ($acc0,$acc1,$acc2,$acc3)=map("%r$_",(8..11));
1264 my ($t0,$t1,$t2)=("%rcx","%r12","%r13");
1267 ################################################################################
1268 # void ecp_nistz256_from_mont(
1271 # This one performs Montgomery multiplication by 1, so we only need the reduction
1273 .globl ecp_nistz256_from_mont
1274 .type ecp_nistz256_from_mont,\@function,2
1276 ecp_nistz256_from_mont:
1280 mov 8*0($in_ptr), %rax
1281 mov .Lpoly+8*3(%rip), $t2
1282 mov 8*1($in_ptr), $acc1
1283 mov 8*2($in_ptr), $acc2
1284 mov 8*3($in_ptr), $acc3
1286 mov .Lpoly+8*1(%rip), $t1
1288 #########################################
1300 #########################################
1313 ##########################################
1326 ###########################################
1340 ###########################################
1341 # Branch-less conditional subtraction
1351 cmovnz $in_ptr, $acc1
1352 mov $acc0, 8*0($r_ptr)
1354 mov $acc1, 8*1($r_ptr)
1356 mov $acc2, 8*2($r_ptr)
1357 mov $acc3, 8*3($r_ptr)
1362 .size ecp_nistz256_from_mont,.-ecp_nistz256_from_mont
1366 my ($val,$in_t,$index)=$win64?("%rcx","%rdx","%r8d"):("%rdi","%rsi","%edx");
1367 my ($ONE,$INDEX,$Ra,$Rb,$Rc,$Rd,$Re,$Rf)=map("%xmm$_",(0..7));
1368 my ($M0,$T0a,$T0b,$T0c,$T0d,$T0e,$T0f,$TMP0)=map("%xmm$_",(8..15));
1369 my ($M1,$T2a,$T2b,$TMP2,$M2,$T2a,$T2b,$TMP2)=map("%xmm$_",(8..15));
1372 ################################################################################
1373 # void ecp_nistz256_select_w5(uint64_t *val, uint64_t *in_t, int index);
1374 .globl ecp_nistz256_select_w5
1375 .type ecp_nistz256_select_w5,\@abi-omnipotent
1377 ecp_nistz256_select_w5:
1379 $code.=<<___ if ($avx>1);
1380 mov OPENSSL_ia32cap_P+8(%rip), %eax
1382 jnz .Lavx2_select_w5
1384 $code.=<<___ if ($win64);
1385 lea -0x88(%rsp), %rax
1386 .LSEH_begin_ecp_nistz256_select_w5:
1387 .byte 0x48,0x8d,0x60,0xe0 #lea -0x20(%rax), %rsp
1388 .byte 0x0f,0x29,0x70,0xe0 #movaps %xmm6, -0x20(%rax)
1389 .byte 0x0f,0x29,0x78,0xf0 #movaps %xmm7, -0x10(%rax)
1390 .byte 0x44,0x0f,0x29,0x00 #movaps %xmm8, 0(%rax)
1391 .byte 0x44,0x0f,0x29,0x48,0x10 #movaps %xmm9, 0x10(%rax)
1392 .byte 0x44,0x0f,0x29,0x50,0x20 #movaps %xmm10, 0x20(%rax)
1393 .byte 0x44,0x0f,0x29,0x58,0x30 #movaps %xmm11, 0x30(%rax)
1394 .byte 0x44,0x0f,0x29,0x60,0x40 #movaps %xmm12, 0x40(%rax)
1395 .byte 0x44,0x0f,0x29,0x68,0x50 #movaps %xmm13, 0x50(%rax)
1396 .byte 0x44,0x0f,0x29,0x70,0x60 #movaps %xmm14, 0x60(%rax)
1397 .byte 0x44,0x0f,0x29,0x78,0x70 #movaps %xmm15, 0x70(%rax)
1400 movdqa .LOne(%rip), $ONE
1411 pshufd \$0, $INDEX, $INDEX
1414 .Lselect_loop_sse_w5:
1418 pcmpeqd $INDEX, $TMP0
1420 movdqa 16*0($in_t), $T0a
1421 movdqa 16*1($in_t), $T0b
1422 movdqa 16*2($in_t), $T0c
1423 movdqa 16*3($in_t), $T0d
1424 movdqa 16*4($in_t), $T0e
1425 movdqa 16*5($in_t), $T0f
1426 lea 16*6($in_t), $in_t
1442 jnz .Lselect_loop_sse_w5
1444 movdqu $Ra, 16*0($val)
1445 movdqu $Rb, 16*1($val)
1446 movdqu $Rc, 16*2($val)
1447 movdqu $Rd, 16*3($val)
1448 movdqu $Re, 16*4($val)
1449 movdqu $Rf, 16*5($val)
1451 $code.=<<___ if ($win64);
1452 movaps (%rsp), %xmm6
1453 movaps 0x10(%rsp), %xmm7
1454 movaps 0x20(%rsp), %xmm8
1455 movaps 0x30(%rsp), %xmm9
1456 movaps 0x40(%rsp), %xmm10
1457 movaps 0x50(%rsp), %xmm11
1458 movaps 0x60(%rsp), %xmm12
1459 movaps 0x70(%rsp), %xmm13
1460 movaps 0x80(%rsp), %xmm14
1461 movaps 0x90(%rsp), %xmm15
1462 lea 0xa8(%rsp), %rsp
1463 .LSEH_end_ecp_nistz256_select_w5:
1467 .size ecp_nistz256_select_w5,.-ecp_nistz256_select_w5
1469 ################################################################################
1470 # void ecp_nistz256_select_w7(uint64_t *val, uint64_t *in_t, int index);
1471 .globl ecp_nistz256_select_w7
1472 .type ecp_nistz256_select_w7,\@abi-omnipotent
1474 ecp_nistz256_select_w7:
1476 $code.=<<___ if ($avx>1);
1477 mov OPENSSL_ia32cap_P+8(%rip), %eax
1479 jnz .Lavx2_select_w7
1481 $code.=<<___ if ($win64);
1482 lea -0x88(%rsp), %rax
1483 .LSEH_begin_ecp_nistz256_select_w7:
1484 .byte 0x48,0x8d,0x60,0xe0 #lea -0x20(%rax), %rsp
1485 .byte 0x0f,0x29,0x70,0xe0 #movaps %xmm6, -0x20(%rax)
1486 .byte 0x0f,0x29,0x78,0xf0 #movaps %xmm7, -0x10(%rax)
1487 .byte 0x44,0x0f,0x29,0x00 #movaps %xmm8, 0(%rax)
1488 .byte 0x44,0x0f,0x29,0x48,0x10 #movaps %xmm9, 0x10(%rax)
1489 .byte 0x44,0x0f,0x29,0x50,0x20 #movaps %xmm10, 0x20(%rax)
1490 .byte 0x44,0x0f,0x29,0x58,0x30 #movaps %xmm11, 0x30(%rax)
1491 .byte 0x44,0x0f,0x29,0x60,0x40 #movaps %xmm12, 0x40(%rax)
1492 .byte 0x44,0x0f,0x29,0x68,0x50 #movaps %xmm13, 0x50(%rax)
1493 .byte 0x44,0x0f,0x29,0x70,0x60 #movaps %xmm14, 0x60(%rax)
1494 .byte 0x44,0x0f,0x29,0x78,0x70 #movaps %xmm15, 0x70(%rax)
1497 movdqa .LOne(%rip), $M0
1506 pshufd \$0, $INDEX, $INDEX
1509 .Lselect_loop_sse_w7:
1512 movdqa 16*0($in_t), $T0a
1513 movdqa 16*1($in_t), $T0b
1514 pcmpeqd $INDEX, $TMP0
1515 movdqa 16*2($in_t), $T0c
1516 movdqa 16*3($in_t), $T0d
1517 lea 16*4($in_t), $in_t
1526 prefetcht0 255($in_t)
1530 jnz .Lselect_loop_sse_w7
1532 movdqu $Ra, 16*0($val)
1533 movdqu $Rb, 16*1($val)
1534 movdqu $Rc, 16*2($val)
1535 movdqu $Rd, 16*3($val)
1537 $code.=<<___ if ($win64);
1538 movaps (%rsp), %xmm6
1539 movaps 0x10(%rsp), %xmm7
1540 movaps 0x20(%rsp), %xmm8
1541 movaps 0x30(%rsp), %xmm9
1542 movaps 0x40(%rsp), %xmm10
1543 movaps 0x50(%rsp), %xmm11
1544 movaps 0x60(%rsp), %xmm12
1545 movaps 0x70(%rsp), %xmm13
1546 movaps 0x80(%rsp), %xmm14
1547 movaps 0x90(%rsp), %xmm15
1548 lea 0xa8(%rsp), %rsp
1549 .LSEH_end_ecp_nistz256_select_w7:
1553 .size ecp_nistz256_select_w7,.-ecp_nistz256_select_w7
1557 my ($val,$in_t,$index)=$win64?("%rcx","%rdx","%r8d"):("%rdi","%rsi","%edx");
1558 my ($TWO,$INDEX,$Ra,$Rb,$Rc)=map("%ymm$_",(0..4));
1559 my ($M0,$T0a,$T0b,$T0c,$TMP0)=map("%ymm$_",(5..9));
1560 my ($M1,$T1a,$T1b,$T1c,$TMP1)=map("%ymm$_",(10..14));
1563 ################################################################################
1564 # void ecp_nistz256_avx2_select_w5(uint64_t *val, uint64_t *in_t, int index);
1565 .type ecp_nistz256_avx2_select_w5,\@abi-omnipotent
1567 ecp_nistz256_avx2_select_w5:
1571 $code.=<<___ if ($win64);
1572 lea -0x88(%rsp), %rax
1573 .LSEH_begin_ecp_nistz256_avx2_select_w5:
1574 .byte 0x48,0x8d,0x60,0xe0 #lea -0x20(%rax), %rsp
1575 .byte 0xc5,0xf8,0x29,0x70,0xe0 #vmovaps %xmm6, -0x20(%rax)
1576 .byte 0xc5,0xf8,0x29,0x78,0xf0 #vmovaps %xmm7, -0x10(%rax)
1577 .byte 0xc5,0x78,0x29,0x40,0x00 #vmovaps %xmm8, 8(%rax)
1578 .byte 0xc5,0x78,0x29,0x48,0x10 #vmovaps %xmm9, 0x10(%rax)
1579 .byte 0xc5,0x78,0x29,0x50,0x20 #vmovaps %xmm10, 0x20(%rax)
1580 .byte 0xc5,0x78,0x29,0x58,0x30 #vmovaps %xmm11, 0x30(%rax)
1581 .byte 0xc5,0x78,0x29,0x60,0x40 #vmovaps %xmm12, 0x40(%rax)
1582 .byte 0xc5,0x78,0x29,0x68,0x50 #vmovaps %xmm13, 0x50(%rax)
1583 .byte 0xc5,0x78,0x29,0x70,0x60 #vmovaps %xmm14, 0x60(%rax)
1584 .byte 0xc5,0x78,0x29,0x78,0x70 #vmovaps %xmm15, 0x70(%rax)
1587 vmovdqa .LTwo(%rip), $TWO
1593 vmovdqa .LOne(%rip), $M0
1594 vmovdqa .LTwo(%rip), $M1
1597 vpermd $INDEX, $Ra, $INDEX
1600 .Lselect_loop_avx2_w5:
1602 vmovdqa 32*0($in_t), $T0a
1603 vmovdqa 32*1($in_t), $T0b
1604 vmovdqa 32*2($in_t), $T0c
1606 vmovdqa 32*3($in_t), $T1a
1607 vmovdqa 32*4($in_t), $T1b
1608 vmovdqa 32*5($in_t), $T1c
1610 vpcmpeqd $INDEX, $M0, $TMP0
1611 vpcmpeqd $INDEX, $M1, $TMP1
1613 vpaddd $TWO, $M0, $M0
1614 vpaddd $TWO, $M1, $M1
1615 lea 32*6($in_t), $in_t
1617 vpand $TMP0, $T0a, $T0a
1618 vpand $TMP0, $T0b, $T0b
1619 vpand $TMP0, $T0c, $T0c
1620 vpand $TMP1, $T1a, $T1a
1621 vpand $TMP1, $T1b, $T1b
1622 vpand $TMP1, $T1c, $T1c
1624 vpxor $T0a, $Ra, $Ra
1625 vpxor $T0b, $Rb, $Rb
1626 vpxor $T0c, $Rc, $Rc
1627 vpxor $T1a, $Ra, $Ra
1628 vpxor $T1b, $Rb, $Rb
1629 vpxor $T1c, $Rc, $Rc
1632 jnz .Lselect_loop_avx2_w5
1634 vmovdqu $Ra, 32*0($val)
1635 vmovdqu $Rb, 32*1($val)
1636 vmovdqu $Rc, 32*2($val)
1639 $code.=<<___ if ($win64);
1640 movaps (%rsp), %xmm6
1641 movaps 0x10(%rsp), %xmm7
1642 movaps 0x20(%rsp), %xmm8
1643 movaps 0x30(%rsp), %xmm9
1644 movaps 0x40(%rsp), %xmm10
1645 movaps 0x50(%rsp), %xmm11
1646 movaps 0x60(%rsp), %xmm12
1647 movaps 0x70(%rsp), %xmm13
1648 movaps 0x80(%rsp), %xmm14
1649 movaps 0x90(%rsp), %xmm15
1650 lea 0xa8(%rsp), %rsp
1651 .LSEH_end_ecp_nistz256_avx2_select_w5:
1655 .size ecp_nistz256_avx2_select_w5,.-ecp_nistz256_avx2_select_w5
1659 my ($val,$in_t,$index)=$win64?("%rcx","%rdx","%r8d"):("%rdi","%rsi","%edx");
1660 my ($THREE,$INDEX,$Ra,$Rb)=map("%ymm$_",(0..3));
1661 my ($M0,$T0a,$T0b,$TMP0)=map("%ymm$_",(4..7));
1662 my ($M1,$T1a,$T1b,$TMP1)=map("%ymm$_",(8..11));
1663 my ($M2,$T2a,$T2b,$TMP2)=map("%ymm$_",(12..15));
1667 ################################################################################
1668 # void ecp_nistz256_avx2_select_w7(uint64_t *val, uint64_t *in_t, int index);
1669 .globl ecp_nistz256_avx2_select_w7
1670 .type ecp_nistz256_avx2_select_w7,\@abi-omnipotent
1672 ecp_nistz256_avx2_select_w7:
1676 $code.=<<___ if ($win64);
1677 lea -0x88(%rsp), %rax
1678 .LSEH_begin_ecp_nistz256_avx2_select_w7:
1679 .byte 0x48,0x8d,0x60,0xe0 #lea -0x20(%rax), %rsp
1680 .byte 0xc5,0xf8,0x29,0x70,0xe0 #vmovaps %xmm6, -0x20(%rax)
1681 .byte 0xc5,0xf8,0x29,0x78,0xf0 #vmovaps %xmm7, -0x10(%rax)
1682 .byte 0xc5,0x78,0x29,0x40,0x00 #vmovaps %xmm8, 8(%rax)
1683 .byte 0xc5,0x78,0x29,0x48,0x10 #vmovaps %xmm9, 0x10(%rax)
1684 .byte 0xc5,0x78,0x29,0x50,0x20 #vmovaps %xmm10, 0x20(%rax)
1685 .byte 0xc5,0x78,0x29,0x58,0x30 #vmovaps %xmm11, 0x30(%rax)
1686 .byte 0xc5,0x78,0x29,0x60,0x40 #vmovaps %xmm12, 0x40(%rax)
1687 .byte 0xc5,0x78,0x29,0x68,0x50 #vmovaps %xmm13, 0x50(%rax)
1688 .byte 0xc5,0x78,0x29,0x70,0x60 #vmovaps %xmm14, 0x60(%rax)
1689 .byte 0xc5,0x78,0x29,0x78,0x70 #vmovaps %xmm15, 0x70(%rax)
1692 vmovdqa .LThree(%rip), $THREE
1697 vmovdqa .LOne(%rip), $M0
1698 vmovdqa .LTwo(%rip), $M1
1699 vmovdqa .LThree(%rip), $M2
1702 vpermd $INDEX, $Ra, $INDEX
1703 # Skip index = 0, because it is implicitly the point at infinity
1706 .Lselect_loop_avx2_w7:
1708 vmovdqa 32*0($in_t), $T0a
1709 vmovdqa 32*1($in_t), $T0b
1711 vmovdqa 32*2($in_t), $T1a
1712 vmovdqa 32*3($in_t), $T1b
1714 vmovdqa 32*4($in_t), $T2a
1715 vmovdqa 32*5($in_t), $T2b
1717 vpcmpeqd $INDEX, $M0, $TMP0
1718 vpcmpeqd $INDEX, $M1, $TMP1
1719 vpcmpeqd $INDEX, $M2, $TMP2
1721 vpaddd $THREE, $M0, $M0
1722 vpaddd $THREE, $M1, $M1
1723 vpaddd $THREE, $M2, $M2
1724 lea 32*6($in_t), $in_t
1726 vpand $TMP0, $T0a, $T0a
1727 vpand $TMP0, $T0b, $T0b
1728 vpand $TMP1, $T1a, $T1a
1729 vpand $TMP1, $T1b, $T1b
1730 vpand $TMP2, $T2a, $T2a
1731 vpand $TMP2, $T2b, $T2b
1733 vpxor $T0a, $Ra, $Ra
1734 vpxor $T0b, $Rb, $Rb
1735 vpxor $T1a, $Ra, $Ra
1736 vpxor $T1b, $Rb, $Rb
1737 vpxor $T2a, $Ra, $Ra
1738 vpxor $T2b, $Rb, $Rb
1741 jnz .Lselect_loop_avx2_w7
1744 vmovdqa 32*0($in_t), $T0a
1745 vmovdqa 32*1($in_t), $T0b
1747 vpcmpeqd $INDEX, $M0, $TMP0
1749 vpand $TMP0, $T0a, $T0a
1750 vpand $TMP0, $T0b, $T0b
1752 vpxor $T0a, $Ra, $Ra
1753 vpxor $T0b, $Rb, $Rb
1755 vmovdqu $Ra, 32*0($val)
1756 vmovdqu $Rb, 32*1($val)
1759 $code.=<<___ if ($win64);
1760 movaps (%rsp), %xmm6
1761 movaps 0x10(%rsp), %xmm7
1762 movaps 0x20(%rsp), %xmm8
1763 movaps 0x30(%rsp), %xmm9
1764 movaps 0x40(%rsp), %xmm10
1765 movaps 0x50(%rsp), %xmm11
1766 movaps 0x60(%rsp), %xmm12
1767 movaps 0x70(%rsp), %xmm13
1768 movaps 0x80(%rsp), %xmm14
1769 movaps 0x90(%rsp), %xmm15
1770 lea 0xa8(%rsp), %rsp
1771 .LSEH_end_ecp_nistz256_avx2_select_w7:
1775 .size ecp_nistz256_avx2_select_w7,.-ecp_nistz256_avx2_select_w7
1779 .globl ecp_nistz256_avx2_select_w7
1780 .type ecp_nistz256_avx2_select_w7,\@function,3
1782 ecp_nistz256_avx2_select_w7:
1783 .byte 0x0f,0x0b # ud2
1785 .size ecp_nistz256_avx2_select_w7,.-ecp_nistz256_avx2_select_w7
1789 ########################################################################
1790 # This block implements higher level point_double, point_add and
1791 # point_add_affine. The key to performance in this case is to allow
1792 # out-of-order execution logic to overlap computations from next step
1793 # with tail processing from current step. By using tailored calling
1794 # sequence we minimize inter-step overhead to give processor better
1795 # shot at overlapping operations...
1797 # You will notice that input data is copied to stack. Trouble is that
1798 # there are no registers to spare for holding original pointers and
1799 # reloading them, pointers, would create undesired dependencies on
1800 # effective addresses calculation paths. In other words it's too done
1801 # to favour out-of-order execution logic.
1802 # <appro@openssl.org>
1804 my ($r_ptr,$a_ptr,$b_org,$b_ptr)=("%rdi","%rsi","%rdx","%rbx");
1805 my ($acc0,$acc1,$acc2,$acc3,$acc4,$acc5,$acc6,$acc7)=map("%r$_",(8..15));
1806 my ($t0,$t1,$t2,$t3,$t4)=("%rax","%rbp","%rcx",$acc4,$acc4);
1807 my ($poly1,$poly3)=($acc6,$acc7);
1809 sub load_for_mul () {
1810 my ($a,$b,$src0) = @_;
1811 my $bias = $src0 eq "%rax" ? 0 : -128;
1817 lea $bias+$a, $a_ptr
1822 sub load_for_sqr () {
1824 my $bias = $src0 eq "%rax" ? 0 : -128;
1828 lea $bias+$a, $a_ptr
1834 ########################################################################
1835 # operate in 4-5-0-1 "name space" that matches multiplication output
1837 my ($a0,$a1,$a2,$a3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
1840 .type __ecp_nistz256_add_toq,\@abi-omnipotent
1842 __ecp_nistz256_add_toq:
1843 add 8*0($b_ptr), $a0
1844 adc 8*1($b_ptr), $a1
1846 adc 8*2($b_ptr), $a2
1847 adc 8*3($b_ptr), $a3
1861 mov $a0, 8*0($r_ptr)
1863 mov $a1, 8*1($r_ptr)
1865 mov $a2, 8*2($r_ptr)
1866 mov $a3, 8*3($r_ptr)
1869 .size __ecp_nistz256_add_toq,.-__ecp_nistz256_add_toq
1871 .type __ecp_nistz256_sub_fromq,\@abi-omnipotent
1873 __ecp_nistz256_sub_fromq:
1874 sub 8*0($b_ptr), $a0
1875 sbb 8*1($b_ptr), $a1
1877 sbb 8*2($b_ptr), $a2
1878 sbb 8*3($b_ptr), $a3
1892 mov $a0, 8*0($r_ptr)
1894 mov $a1, 8*1($r_ptr)
1896 mov $a2, 8*2($r_ptr)
1897 mov $a3, 8*3($r_ptr)
1900 .size __ecp_nistz256_sub_fromq,.-__ecp_nistz256_sub_fromq
1902 .type __ecp_nistz256_subq,\@abi-omnipotent
1904 __ecp_nistz256_subq:
1927 .size __ecp_nistz256_subq,.-__ecp_nistz256_subq
1929 .type __ecp_nistz256_mul_by_2q,\@abi-omnipotent
1931 __ecp_nistz256_mul_by_2q:
1932 add $a0, $a0 # a0:a3+a0:a3
1950 mov $a0, 8*0($r_ptr)
1952 mov $a1, 8*1($r_ptr)
1954 mov $a2, 8*2($r_ptr)
1955 mov $a3, 8*3($r_ptr)
1958 .size __ecp_nistz256_mul_by_2q,.-__ecp_nistz256_mul_by_2q
1963 my ($src0,$sfx,$bias);
1964 my ($S,$M,$Zsqr,$in_x,$tmp0)=map(32*$_,(0..4));
1972 .globl ecp_nistz256_point_double
1973 .type ecp_nistz256_point_double,\@function,2
1975 ecp_nistz256_point_double:
1977 $code.=<<___ if ($addx);
1979 and OPENSSL_ia32cap_P+8(%rip), %ecx
1989 .type ecp_nistz256_point_doublex,\@function,2
1991 ecp_nistz256_point_doublex:
2004 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$a_ptr.x
2005 mov $a_ptr, $b_ptr # backup copy
2006 movdqu 0x10($a_ptr), %xmm1
2007 mov 0x20+8*0($a_ptr), $acc4 # load in_y in "5-4-0-1" order
2008 mov 0x20+8*1($a_ptr), $acc5
2009 mov 0x20+8*2($a_ptr), $acc0
2010 mov 0x20+8*3($a_ptr), $acc1
2011 mov .Lpoly+8*1(%rip), $poly1
2012 mov .Lpoly+8*3(%rip), $poly3
2013 movdqa %xmm0, $in_x(%rsp)
2014 movdqa %xmm1, $in_x+0x10(%rsp)
2015 lea 0x20($r_ptr), $acc2
2016 lea 0x40($r_ptr), $acc3
2021 lea $S(%rsp), $r_ptr
2022 call __ecp_nistz256_mul_by_2$x # p256_mul_by_2(S, in_y);
2024 mov 0x40+8*0($a_ptr), $src0
2025 mov 0x40+8*1($a_ptr), $acc6
2026 mov 0x40+8*2($a_ptr), $acc7
2027 mov 0x40+8*3($a_ptr), $acc0
2028 lea 0x40-$bias($a_ptr), $a_ptr
2029 lea $Zsqr(%rsp), $r_ptr
2030 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Zsqr, in_z);
2032 `&load_for_sqr("$S(%rsp)", "$src0")`
2033 lea $S(%rsp), $r_ptr
2034 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(S, S);
2036 mov 0x20($b_ptr), $src0 # $b_ptr is still valid
2037 mov 0x40+8*0($b_ptr), $acc1
2038 mov 0x40+8*1($b_ptr), $acc2
2039 mov 0x40+8*2($b_ptr), $acc3
2040 mov 0x40+8*3($b_ptr), $acc4
2041 lea 0x40-$bias($b_ptr), $a_ptr
2042 lea 0x20($b_ptr), $b_ptr
2044 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, in_z, in_y);
2045 call __ecp_nistz256_mul_by_2$x # p256_mul_by_2(res_z, res_z);
2047 mov $in_x+8*0(%rsp), $acc4 # "5-4-0-1" order
2048 mov $in_x+8*1(%rsp), $acc5
2049 lea $Zsqr(%rsp), $b_ptr
2050 mov $in_x+8*2(%rsp), $acc0
2051 mov $in_x+8*3(%rsp), $acc1
2052 lea $M(%rsp), $r_ptr
2053 call __ecp_nistz256_add_to$x # p256_add(M, in_x, Zsqr);
2055 mov $in_x+8*0(%rsp), $acc4 # "5-4-0-1" order
2056 mov $in_x+8*1(%rsp), $acc5
2057 lea $Zsqr(%rsp), $b_ptr
2058 mov $in_x+8*2(%rsp), $acc0
2059 mov $in_x+8*3(%rsp), $acc1
2060 lea $Zsqr(%rsp), $r_ptr
2061 call __ecp_nistz256_sub_from$x # p256_sub(Zsqr, in_x, Zsqr);
2063 `&load_for_sqr("$S(%rsp)", "$src0")`
2065 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(res_y, S);
2068 ######## ecp_nistz256_div_by_2(res_y, res_y); ##########################
2069 # operate in 4-5-6-7 "name space" that matches squaring output
2071 my ($poly1,$poly3)=($a_ptr,$t1);
2072 my ($a0,$a1,$a2,$a3,$t3,$t4,$t1)=($acc4,$acc5,$acc6,$acc7,$acc0,$acc1,$acc2);
2085 xor $a_ptr, $a_ptr # borrow $a_ptr
2094 mov $a1, $t0 # a0:a3>>1
2105 mov $a0, 8*0($r_ptr)
2107 mov $a1, 8*1($r_ptr)
2111 mov $a2, 8*2($r_ptr)
2112 mov $a3, 8*3($r_ptr)
2116 `&load_for_mul("$M(%rsp)", "$Zsqr(%rsp)", "$src0")`
2117 lea $M(%rsp), $r_ptr
2118 call __ecp_nistz256_mul_mont$x # p256_mul_mont(M, M, Zsqr);
2120 lea $tmp0(%rsp), $r_ptr
2121 call __ecp_nistz256_mul_by_2$x
2123 lea $M(%rsp), $b_ptr
2124 lea $M(%rsp), $r_ptr
2125 call __ecp_nistz256_add_to$x # p256_mul_by_3(M, M);
2127 `&load_for_mul("$S(%rsp)", "$in_x(%rsp)", "$src0")`
2128 lea $S(%rsp), $r_ptr
2129 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S, S, in_x);
2131 lea $tmp0(%rsp), $r_ptr
2132 call __ecp_nistz256_mul_by_2$x # p256_mul_by_2(tmp0, S);
2134 `&load_for_sqr("$M(%rsp)", "$src0")`
2136 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(res_x, M);
2138 lea $tmp0(%rsp), $b_ptr
2139 mov $acc6, $acc0 # harmonize sqr output and sub input
2143 call __ecp_nistz256_sub_from$x # p256_sub(res_x, res_x, tmp0);
2145 mov $S+8*0(%rsp), $t0
2146 mov $S+8*1(%rsp), $t1
2147 mov $S+8*2(%rsp), $t2
2148 mov $S+8*3(%rsp), $acc2 # "4-5-0-1" order
2149 lea $S(%rsp), $r_ptr
2150 call __ecp_nistz256_sub$x # p256_sub(S, S, res_x);
2153 lea $M(%rsp), $b_ptr
2154 mov $acc4, $acc6 # harmonize sub output and mul input
2156 mov $acc4, $S+8*0(%rsp) # have to save:-(
2158 mov $acc5, $S+8*1(%rsp)
2160 mov $acc0, $S+8*2(%rsp)
2161 lea $S-$bias(%rsp), $a_ptr
2163 mov $acc1, $S+8*3(%rsp)
2165 lea $S(%rsp), $r_ptr
2166 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S, S, M);
2170 call __ecp_nistz256_sub_from$x # p256_sub(res_y, S, res_y);
2180 .size ecp_nistz256_point_double$sfx,.-ecp_nistz256_point_double$sfx
2187 my ($src0,$sfx,$bias);
2188 my ($H,$Hsqr,$R,$Rsqr,$Hcub,
2190 $res_x,$res_y,$res_z,
2191 $in1_x,$in1_y,$in1_z,
2192 $in2_x,$in2_y,$in2_z)=map(32*$_,(0..17));
2193 my ($Z1sqr, $Z2sqr) = ($Hsqr, $Rsqr);
2201 .globl ecp_nistz256_point_add
2202 .type ecp_nistz256_point_add,\@function,3
2204 ecp_nistz256_point_add:
2206 $code.=<<___ if ($addx);
2208 and OPENSSL_ia32cap_P+8(%rip), %ecx
2218 .type ecp_nistz256_point_addx,\@function,3
2220 ecp_nistz256_point_addx:
2233 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$a_ptr
2234 movdqu 0x10($a_ptr), %xmm1
2235 movdqu 0x20($a_ptr), %xmm2
2236 movdqu 0x30($a_ptr), %xmm3
2237 movdqu 0x40($a_ptr), %xmm4
2238 movdqu 0x50($a_ptr), %xmm5
2239 mov $a_ptr, $b_ptr # reassign
2240 mov $b_org, $a_ptr # reassign
2241 movdqa %xmm0, $in1_x(%rsp)
2242 movdqa %xmm1, $in1_x+0x10(%rsp)
2244 movdqa %xmm2, $in1_y(%rsp)
2245 movdqa %xmm3, $in1_y+0x10(%rsp)
2247 movdqa %xmm4, $in1_z(%rsp)
2248 movdqa %xmm5, $in1_z+0x10(%rsp)
2251 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$b_ptr
2252 pshufd \$0xb1, %xmm3, %xmm5
2253 movdqu 0x10($a_ptr), %xmm1
2254 movdqu 0x20($a_ptr), %xmm2
2256 movdqu 0x30($a_ptr), %xmm3
2257 mov 0x40+8*0($a_ptr), $src0 # load original in2_z
2258 mov 0x40+8*1($a_ptr), $acc6
2259 mov 0x40+8*2($a_ptr), $acc7
2260 mov 0x40+8*3($a_ptr), $acc0
2261 movdqa %xmm0, $in2_x(%rsp)
2262 pshufd \$0x1e, %xmm5, %xmm4
2263 movdqa %xmm1, $in2_x+0x10(%rsp)
2265 movq $r_ptr, %xmm0 # save $r_ptr
2266 movdqa %xmm2, $in2_y(%rsp)
2267 movdqa %xmm3, $in2_y+0x10(%rsp)
2273 lea 0x40-$bias($a_ptr), $a_ptr # $a_ptr is still valid
2274 mov $src0, $in2_z+8*0(%rsp) # make in2_z copy
2275 mov $acc6, $in2_z+8*1(%rsp)
2276 mov $acc7, $in2_z+8*2(%rsp)
2277 mov $acc0, $in2_z+8*3(%rsp)
2278 lea $Z2sqr(%rsp), $r_ptr # Z2^2
2279 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Z2sqr, in2_z);
2281 pcmpeqd %xmm4, %xmm5
2282 pshufd \$0xb1, %xmm3, %xmm4
2284 pshufd \$0, %xmm5, %xmm5 # in1infty
2285 pshufd \$0x1e, %xmm4, %xmm3
2288 pcmpeqd %xmm3, %xmm4
2289 pshufd \$0, %xmm4, %xmm4 # in2infty
2290 mov 0x40+8*0($b_ptr), $src0 # load original in1_z
2291 mov 0x40+8*1($b_ptr), $acc6
2292 mov 0x40+8*2($b_ptr), $acc7
2293 mov 0x40+8*3($b_ptr), $acc0
2295 lea 0x40-$bias($b_ptr), $a_ptr
2296 lea $Z1sqr(%rsp), $r_ptr # Z1^2
2297 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Z1sqr, in1_z);
2299 `&load_for_mul("$Z2sqr(%rsp)", "$in2_z(%rsp)", "$src0")`
2300 lea $S1(%rsp), $r_ptr # S1 = Z2^3
2301 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S1, Z2sqr, in2_z);
2303 `&load_for_mul("$Z1sqr(%rsp)", "$in1_z(%rsp)", "$src0")`
2304 lea $S2(%rsp), $r_ptr # S2 = Z1^3
2305 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, Z1sqr, in1_z);
2307 `&load_for_mul("$S1(%rsp)", "$in1_y(%rsp)", "$src0")`
2308 lea $S1(%rsp), $r_ptr # S1 = Y1*Z2^3
2309 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S1, S1, in1_y);
2311 `&load_for_mul("$S2(%rsp)", "$in2_y(%rsp)", "$src0")`
2312 lea $S2(%rsp), $r_ptr # S2 = Y2*Z1^3
2313 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, S2, in2_y);
2315 lea $S1(%rsp), $b_ptr
2316 lea $R(%rsp), $r_ptr # R = S2 - S1
2317 call __ecp_nistz256_sub_from$x # p256_sub(R, S2, S1);
2319 or $acc5, $acc4 # see if result is zero
2323 por %xmm5, %xmm2 # in1infty || in2infty
2326 `&load_for_mul("$Z2sqr(%rsp)", "$in1_x(%rsp)", "$src0")`
2327 lea $U1(%rsp), $r_ptr # U1 = X1*Z2^2
2328 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U1, in1_x, Z2sqr);
2330 `&load_for_mul("$Z1sqr(%rsp)", "$in2_x(%rsp)", "$src0")`
2331 lea $U2(%rsp), $r_ptr # U2 = X2*Z1^2
2332 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, in2_x, Z1sqr);
2334 lea $U1(%rsp), $b_ptr
2335 lea $H(%rsp), $r_ptr # H = U2 - U1
2336 call __ecp_nistz256_sub_from$x # p256_sub(H, U2, U1);
2338 or $acc5, $acc4 # see if result is zero
2342 .byte 0x3e # predict taken
2343 jnz .Ladd_proceed$x # is_equal(U1,U2)?
2347 jnz .Ladd_proceed$x # (in1infty || in2infty)?
2349 jz .Ladd_proceed$x # is_equal(S1,S2)?
2351 movq %xmm0, $r_ptr # restore $r_ptr
2353 movdqu %xmm0, 0x00($r_ptr)
2354 movdqu %xmm0, 0x10($r_ptr)
2355 movdqu %xmm0, 0x20($r_ptr)
2356 movdqu %xmm0, 0x30($r_ptr)
2357 movdqu %xmm0, 0x40($r_ptr)
2358 movdqu %xmm0, 0x50($r_ptr)
2363 `&load_for_sqr("$R(%rsp)", "$src0")`
2364 lea $Rsqr(%rsp), $r_ptr # R^2
2365 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Rsqr, R);
2367 `&load_for_mul("$H(%rsp)", "$in1_z(%rsp)", "$src0")`
2368 lea $res_z(%rsp), $r_ptr # Z3 = H*Z1*Z2
2369 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, H, in1_z);
2371 `&load_for_sqr("$H(%rsp)", "$src0")`
2372 lea $Hsqr(%rsp), $r_ptr # H^2
2373 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Hsqr, H);
2375 `&load_for_mul("$res_z(%rsp)", "$in2_z(%rsp)", "$src0")`
2376 lea $res_z(%rsp), $r_ptr # Z3 = H*Z1*Z2
2377 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, res_z, in2_z);
2379 `&load_for_mul("$Hsqr(%rsp)", "$H(%rsp)", "$src0")`
2380 lea $Hcub(%rsp), $r_ptr # H^3
2381 call __ecp_nistz256_mul_mont$x # p256_mul_mont(Hcub, Hsqr, H);
2383 `&load_for_mul("$Hsqr(%rsp)", "$U1(%rsp)", "$src0")`
2384 lea $U2(%rsp), $r_ptr # U1*H^2
2385 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, U1, Hsqr);
2388 #######################################################################
2389 # operate in 4-5-0-1 "name space" that matches multiplication output
2391 my ($acc0,$acc1,$acc2,$acc3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
2392 my ($poly1, $poly3)=($acc6,$acc7);
2395 #lea $U2(%rsp), $a_ptr
2396 #lea $Hsqr(%rsp), $r_ptr # 2*U1*H^2
2397 #call __ecp_nistz256_mul_by_2 # ecp_nistz256_mul_by_2(Hsqr, U2);
2399 add $acc0, $acc0 # a0:a3+a0:a3
2400 lea $Rsqr(%rsp), $a_ptr
2417 mov 8*0($a_ptr), $t0
2419 mov 8*1($a_ptr), $t1
2421 mov 8*2($a_ptr), $t2
2423 mov 8*3($a_ptr), $t3
2425 call __ecp_nistz256_sub$x # p256_sub(res_x, Rsqr, Hsqr);
2427 lea $Hcub(%rsp), $b_ptr
2428 lea $res_x(%rsp), $r_ptr
2429 call __ecp_nistz256_sub_from$x # p256_sub(res_x, res_x, Hcub);
2431 mov $U2+8*0(%rsp), $t0
2432 mov $U2+8*1(%rsp), $t1
2433 mov $U2+8*2(%rsp), $t2
2434 mov $U2+8*3(%rsp), $t3
2435 lea $res_y(%rsp), $r_ptr
2437 call __ecp_nistz256_sub$x # p256_sub(res_y, U2, res_x);
2439 mov $acc0, 8*0($r_ptr) # save the result, as
2440 mov $acc1, 8*1($r_ptr) # __ecp_nistz256_sub doesn't
2441 mov $acc2, 8*2($r_ptr)
2442 mov $acc3, 8*3($r_ptr)
2446 `&load_for_mul("$S1(%rsp)", "$Hcub(%rsp)", "$src0")`
2447 lea $S2(%rsp), $r_ptr
2448 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, S1, Hcub);
2450 `&load_for_mul("$R(%rsp)", "$res_y(%rsp)", "$src0")`
2451 lea $res_y(%rsp), $r_ptr
2452 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_y, R, res_y);
2454 lea $S2(%rsp), $b_ptr
2455 lea $res_y(%rsp), $r_ptr
2456 call __ecp_nistz256_sub_from$x # p256_sub(res_y, res_y, S2);
2458 movq %xmm0, $r_ptr # restore $r_ptr
2460 movdqa %xmm5, %xmm0 # copy_conditional(res_z, in2_z, in1infty);
2462 pandn $res_z(%rsp), %xmm0
2464 pandn $res_z+0x10(%rsp), %xmm1
2466 pand $in2_z(%rsp), %xmm2
2467 pand $in2_z+0x10(%rsp), %xmm3
2471 movdqa %xmm4, %xmm0 # copy_conditional(res_z, in1_z, in2infty);
2477 pand $in1_z(%rsp), %xmm2
2478 pand $in1_z+0x10(%rsp), %xmm3
2481 movdqu %xmm2, 0x40($r_ptr)
2482 movdqu %xmm3, 0x50($r_ptr)
2484 movdqa %xmm5, %xmm0 # copy_conditional(res_x, in2_x, in1infty);
2486 pandn $res_x(%rsp), %xmm0
2488 pandn $res_x+0x10(%rsp), %xmm1
2490 pand $in2_x(%rsp), %xmm2
2491 pand $in2_x+0x10(%rsp), %xmm3
2495 movdqa %xmm4, %xmm0 # copy_conditional(res_x, in1_x, in2infty);
2501 pand $in1_x(%rsp), %xmm2
2502 pand $in1_x+0x10(%rsp), %xmm3
2505 movdqu %xmm2, 0x00($r_ptr)
2506 movdqu %xmm3, 0x10($r_ptr)
2508 movdqa %xmm5, %xmm0 # copy_conditional(res_y, in2_y, in1infty);
2510 pandn $res_y(%rsp), %xmm0
2512 pandn $res_y+0x10(%rsp), %xmm1
2514 pand $in2_y(%rsp), %xmm2
2515 pand $in2_y+0x10(%rsp), %xmm3
2519 movdqa %xmm4, %xmm0 # copy_conditional(res_y, in1_y, in2infty);
2525 pand $in1_y(%rsp), %xmm2
2526 pand $in1_y+0x10(%rsp), %xmm3
2529 movdqu %xmm2, 0x20($r_ptr)
2530 movdqu %xmm3, 0x30($r_ptr)
2541 .size ecp_nistz256_point_add$sfx,.-ecp_nistz256_point_add$sfx
2546 sub gen_add_affine () {
2548 my ($src0,$sfx,$bias);
2549 my ($U2,$S2,$H,$R,$Hsqr,$Hcub,$Rsqr,
2550 $res_x,$res_y,$res_z,
2551 $in1_x,$in1_y,$in1_z,
2552 $in2_x,$in2_y)=map(32*$_,(0..14));
2561 .globl ecp_nistz256_point_add_affine
2562 .type ecp_nistz256_point_add_affine,\@function,3
2564 ecp_nistz256_point_add_affine:
2566 $code.=<<___ if ($addx);
2568 and OPENSSL_ia32cap_P+8(%rip), %ecx
2570 je .Lpoint_add_affinex
2578 .type ecp_nistz256_point_add_affinex,\@function,3
2580 ecp_nistz256_point_add_affinex:
2581 .Lpoint_add_affinex:
2593 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$a_ptr
2594 mov $b_org, $b_ptr # reassign
2595 movdqu 0x10($a_ptr), %xmm1
2596 movdqu 0x20($a_ptr), %xmm2
2597 movdqu 0x30($a_ptr), %xmm3
2598 movdqu 0x40($a_ptr), %xmm4
2599 movdqu 0x50($a_ptr), %xmm5
2600 mov 0x40+8*0($a_ptr), $src0 # load original in1_z
2601 mov 0x40+8*1($a_ptr), $acc6
2602 mov 0x40+8*2($a_ptr), $acc7
2603 mov 0x40+8*3($a_ptr), $acc0
2604 movdqa %xmm0, $in1_x(%rsp)
2605 movdqa %xmm1, $in1_x+0x10(%rsp)
2607 movdqa %xmm2, $in1_y(%rsp)
2608 movdqa %xmm3, $in1_y+0x10(%rsp)
2610 movdqa %xmm4, $in1_z(%rsp)
2611 movdqa %xmm5, $in1_z+0x10(%rsp)
2614 movdqu 0x00($b_ptr), %xmm0 # copy *(P256_POINT_AFFINE *)$b_ptr
2615 pshufd \$0xb1, %xmm3, %xmm5
2616 movdqu 0x10($b_ptr), %xmm1
2617 movdqu 0x20($b_ptr), %xmm2
2619 movdqu 0x30($b_ptr), %xmm3
2620 movdqa %xmm0, $in2_x(%rsp)
2621 pshufd \$0x1e, %xmm5, %xmm4
2622 movdqa %xmm1, $in2_x+0x10(%rsp)
2624 movq $r_ptr, %xmm0 # save $r_ptr
2625 movdqa %xmm2, $in2_y(%rsp)
2626 movdqa %xmm3, $in2_y+0x10(%rsp)
2632 lea 0x40-$bias($a_ptr), $a_ptr # $a_ptr is still valid
2633 lea $Z1sqr(%rsp), $r_ptr # Z1^2
2634 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Z1sqr, in1_z);
2636 pcmpeqd %xmm4, %xmm5
2637 pshufd \$0xb1, %xmm3, %xmm4
2638 mov 0x00($b_ptr), $src0 # $b_ptr is still valid
2639 #lea 0x00($b_ptr), $b_ptr
2640 mov $acc4, $acc1 # harmonize sqr output and mul input
2642 pshufd \$0, %xmm5, %xmm5 # in1infty
2643 pshufd \$0x1e, %xmm4, %xmm3
2648 pcmpeqd %xmm3, %xmm4
2649 pshufd \$0, %xmm4, %xmm4 # in2infty
2651 lea $Z1sqr-$bias(%rsp), $a_ptr
2653 lea $U2(%rsp), $r_ptr # U2 = X2*Z1^2
2654 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, Z1sqr, in2_x);
2656 lea $in1_x(%rsp), $b_ptr
2657 lea $H(%rsp), $r_ptr # H = U2 - U1
2658 call __ecp_nistz256_sub_from$x # p256_sub(H, U2, in1_x);
2660 `&load_for_mul("$Z1sqr(%rsp)", "$in1_z(%rsp)", "$src0")`
2661 lea $S2(%rsp), $r_ptr # S2 = Z1^3
2662 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, Z1sqr, in1_z);
2664 `&load_for_mul("$H(%rsp)", "$in1_z(%rsp)", "$src0")`
2665 lea $res_z(%rsp), $r_ptr # Z3 = H*Z1*Z2
2666 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, H, in1_z);
2668 `&load_for_mul("$S2(%rsp)", "$in2_y(%rsp)", "$src0")`
2669 lea $S2(%rsp), $r_ptr # S2 = Y2*Z1^3
2670 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, S2, in2_y);
2672 lea $in1_y(%rsp), $b_ptr
2673 lea $R(%rsp), $r_ptr # R = S2 - S1
2674 call __ecp_nistz256_sub_from$x # p256_sub(R, S2, in1_y);
2676 `&load_for_sqr("$H(%rsp)", "$src0")`
2677 lea $Hsqr(%rsp), $r_ptr # H^2
2678 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Hsqr, H);
2680 `&load_for_sqr("$R(%rsp)", "$src0")`
2681 lea $Rsqr(%rsp), $r_ptr # R^2
2682 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Rsqr, R);
2684 `&load_for_mul("$H(%rsp)", "$Hsqr(%rsp)", "$src0")`
2685 lea $Hcub(%rsp), $r_ptr # H^3
2686 call __ecp_nistz256_mul_mont$x # p256_mul_mont(Hcub, Hsqr, H);
2688 `&load_for_mul("$Hsqr(%rsp)", "$in1_x(%rsp)", "$src0")`
2689 lea $U2(%rsp), $r_ptr # U1*H^2
2690 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, in1_x, Hsqr);
2693 #######################################################################
2694 # operate in 4-5-0-1 "name space" that matches multiplication output
2696 my ($acc0,$acc1,$acc2,$acc3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
2697 my ($poly1, $poly3)=($acc6,$acc7);
2700 #lea $U2(%rsp), $a_ptr
2701 #lea $Hsqr(%rsp), $r_ptr # 2*U1*H^2
2702 #call __ecp_nistz256_mul_by_2 # ecp_nistz256_mul_by_2(Hsqr, U2);
2704 add $acc0, $acc0 # a0:a3+a0:a3
2705 lea $Rsqr(%rsp), $a_ptr
2722 mov 8*0($a_ptr), $t0
2724 mov 8*1($a_ptr), $t1
2726 mov 8*2($a_ptr), $t2
2728 mov 8*3($a_ptr), $t3
2730 call __ecp_nistz256_sub$x # p256_sub(res_x, Rsqr, Hsqr);
2732 lea $Hcub(%rsp), $b_ptr
2733 lea $res_x(%rsp), $r_ptr
2734 call __ecp_nistz256_sub_from$x # p256_sub(res_x, res_x, Hcub);
2736 mov $U2+8*0(%rsp), $t0
2737 mov $U2+8*1(%rsp), $t1
2738 mov $U2+8*2(%rsp), $t2
2739 mov $U2+8*3(%rsp), $t3
2740 lea $H(%rsp), $r_ptr
2742 call __ecp_nistz256_sub$x # p256_sub(H, U2, res_x);
2744 mov $acc0, 8*0($r_ptr) # save the result, as
2745 mov $acc1, 8*1($r_ptr) # __ecp_nistz256_sub doesn't
2746 mov $acc2, 8*2($r_ptr)
2747 mov $acc3, 8*3($r_ptr)
2751 `&load_for_mul("$Hcub(%rsp)", "$in1_y(%rsp)", "$src0")`
2752 lea $S2(%rsp), $r_ptr
2753 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, Hcub, in1_y);
2755 `&load_for_mul("$H(%rsp)", "$R(%rsp)", "$src0")`
2756 lea $H(%rsp), $r_ptr
2757 call __ecp_nistz256_mul_mont$x # p256_mul_mont(H, H, R);
2759 lea $S2(%rsp), $b_ptr
2760 lea $res_y(%rsp), $r_ptr
2761 call __ecp_nistz256_sub_from$x # p256_sub(res_y, H, S2);
2763 movq %xmm0, $r_ptr # restore $r_ptr
2765 movdqa %xmm5, %xmm0 # copy_conditional(res_z, ONE, in1infty);
2767 pandn $res_z(%rsp), %xmm0
2769 pandn $res_z+0x10(%rsp), %xmm1
2771 pand .LONE_mont(%rip), %xmm2
2772 pand .LONE_mont+0x10(%rip), %xmm3
2776 movdqa %xmm4, %xmm0 # copy_conditional(res_z, in1_z, in2infty);
2782 pand $in1_z(%rsp), %xmm2
2783 pand $in1_z+0x10(%rsp), %xmm3
2786 movdqu %xmm2, 0x40($r_ptr)
2787 movdqu %xmm3, 0x50($r_ptr)
2789 movdqa %xmm5, %xmm0 # copy_conditional(res_x, in2_x, in1infty);
2791 pandn $res_x(%rsp), %xmm0
2793 pandn $res_x+0x10(%rsp), %xmm1
2795 pand $in2_x(%rsp), %xmm2
2796 pand $in2_x+0x10(%rsp), %xmm3
2800 movdqa %xmm4, %xmm0 # copy_conditional(res_x, in1_x, in2infty);
2806 pand $in1_x(%rsp), %xmm2
2807 pand $in1_x+0x10(%rsp), %xmm3
2810 movdqu %xmm2, 0x00($r_ptr)
2811 movdqu %xmm3, 0x10($r_ptr)
2813 movdqa %xmm5, %xmm0 # copy_conditional(res_y, in2_y, in1infty);
2815 pandn $res_y(%rsp), %xmm0
2817 pandn $res_y+0x10(%rsp), %xmm1
2819 pand $in2_y(%rsp), %xmm2
2820 pand $in2_y+0x10(%rsp), %xmm3
2824 movdqa %xmm4, %xmm0 # copy_conditional(res_y, in1_y, in2infty);
2830 pand $in1_y(%rsp), %xmm2
2831 pand $in1_y+0x10(%rsp), %xmm3
2834 movdqu %xmm2, 0x20($r_ptr)
2835 movdqu %xmm3, 0x30($r_ptr)
2845 .size ecp_nistz256_point_add_affine$sfx,.-ecp_nistz256_point_add_affine$sfx
2848 &gen_add_affine("q");
2850 ########################################################################
2854 ########################################################################
2855 # operate in 4-5-0-1 "name space" that matches multiplication output
2857 my ($a0,$a1,$a2,$a3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
2860 .type __ecp_nistz256_add_tox,\@abi-omnipotent
2862 __ecp_nistz256_add_tox:
2864 adc 8*0($b_ptr), $a0
2865 adc 8*1($b_ptr), $a1
2867 adc 8*2($b_ptr), $a2
2868 adc 8*3($b_ptr), $a3
2883 mov $a0, 8*0($r_ptr)
2885 mov $a1, 8*1($r_ptr)
2887 mov $a2, 8*2($r_ptr)
2888 mov $a3, 8*3($r_ptr)
2891 .size __ecp_nistz256_add_tox,.-__ecp_nistz256_add_tox
2893 .type __ecp_nistz256_sub_fromx,\@abi-omnipotent
2895 __ecp_nistz256_sub_fromx:
2897 sbb 8*0($b_ptr), $a0
2898 sbb 8*1($b_ptr), $a1
2900 sbb 8*2($b_ptr), $a2
2901 sbb 8*3($b_ptr), $a3
2916 mov $a0, 8*0($r_ptr)
2918 mov $a1, 8*1($r_ptr)
2920 mov $a2, 8*2($r_ptr)
2921 mov $a3, 8*3($r_ptr)
2924 .size __ecp_nistz256_sub_fromx,.-__ecp_nistz256_sub_fromx
2926 .type __ecp_nistz256_subx,\@abi-omnipotent
2928 __ecp_nistz256_subx:
2953 .size __ecp_nistz256_subx,.-__ecp_nistz256_subx
2955 .type __ecp_nistz256_mul_by_2x,\@abi-omnipotent
2957 __ecp_nistz256_mul_by_2x:
2959 adc $a0, $a0 # a0:a3+a0:a3
2978 mov $a0, 8*0($r_ptr)
2980 mov $a1, 8*1($r_ptr)
2982 mov $a2, 8*2($r_ptr)
2983 mov $a3, 8*3($r_ptr)
2986 .size __ecp_nistz256_mul_by_2x,.-__ecp_nistz256_mul_by_2x
2991 &gen_add_affine("x");
2995 $code =~ s/\`([^\`]*)\`/eval $1/gem;