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:
133 add $a0, $a0 # a0:a3+a0:a3
137 lea .Lpoly(%rip), $a_ptr
164 .size ecp_nistz256_mul_by_2,.-ecp_nistz256_mul_by_2
166 ################################################################################
167 # void ecp_nistz256_div_by_2(uint64_t res[4], uint64_t a[4]);
168 .globl ecp_nistz256_div_by_2
169 .type ecp_nistz256_div_by_2,\@function,2
171 ecp_nistz256_div_by_2:
180 lea .Lpoly(%rip), $a_ptr
191 xor $a_ptr, $a_ptr # borrow $a_ptr
200 mov $a1, $t0 # a0:a3>>1
224 .size ecp_nistz256_div_by_2,.-ecp_nistz256_div_by_2
226 ################################################################################
227 # void ecp_nistz256_mul_by_3(uint64_t res[4], uint64_t a[4]);
228 .globl ecp_nistz256_mul_by_3
229 .type ecp_nistz256_mul_by_3,\@function,2
231 ecp_nistz256_mul_by_3:
238 add $a0, $a0 # a0:a3+a0:a3
250 sbb .Lpoly+8*1(%rip), $a1
253 sbb .Lpoly+8*3(%rip), $a3
262 add 8*0($a_ptr), $a0 # a0:a3+=a_ptr[0:3]
272 sbb .Lpoly+8*1(%rip), $a1
275 sbb .Lpoly+8*3(%rip), $a3
290 .size ecp_nistz256_mul_by_3,.-ecp_nistz256_mul_by_3
292 ################################################################################
293 # void ecp_nistz256_add(uint64_t res[4], uint64_t a[4], uint64_t b[4]);
294 .globl ecp_nistz256_add
295 .type ecp_nistz256_add,\@function,3
306 lea .Lpoly(%rip), $a_ptr
336 .size ecp_nistz256_add,.-ecp_nistz256_add
338 ################################################################################
339 # void ecp_nistz256_sub(uint64_t res[4], uint64_t a[4], uint64_t b[4]);
340 .globl ecp_nistz256_sub
341 .type ecp_nistz256_sub,\@function,3
352 lea .Lpoly(%rip), $a_ptr
382 .size ecp_nistz256_sub,.-ecp_nistz256_sub
384 ################################################################################
385 # void ecp_nistz256_neg(uint64_t res[4], uint64_t a[4]);
386 .globl ecp_nistz256_neg
387 .type ecp_nistz256_neg,\@function,2
404 lea .Lpoly(%rip), $a_ptr
428 .size ecp_nistz256_neg,.-ecp_nistz256_neg
432 my ($r_ptr,$a_ptr,$b_org,$b_ptr)=("%rdi","%rsi","%rdx","%rbx");
433 my ($acc0,$acc1,$acc2,$acc3,$acc4,$acc5,$acc6,$acc7)=map("%r$_",(8..15));
434 my ($t0,$t1,$t2,$t3,$t4)=("%rcx","%rbp","%rbx","%rdx","%rax");
435 my ($poly1,$poly3)=($acc6,$acc7);
438 ################################################################################
439 # void ecp_nistz256_to_mont(
442 .globl ecp_nistz256_to_mont
443 .type ecp_nistz256_to_mont,\@function,2
445 ecp_nistz256_to_mont:
447 $code.=<<___ if ($addx);
449 and OPENSSL_ia32cap_P+8(%rip), %ecx
452 lea .LRR(%rip), $b_org
454 .size ecp_nistz256_to_mont,.-ecp_nistz256_to_mont
456 ################################################################################
457 # void ecp_nistz256_mul_mont(
462 .globl ecp_nistz256_mul_mont
463 .type ecp_nistz256_mul_mont,\@function,3
465 ecp_nistz256_mul_mont:
467 $code.=<<___ if ($addx);
469 and OPENSSL_ia32cap_P+8(%rip), %ecx
480 $code.=<<___ if ($addx);
486 mov 8*0($b_org), %rax
487 mov 8*0($a_ptr), $acc1
488 mov 8*1($a_ptr), $acc2
489 mov 8*2($a_ptr), $acc3
490 mov 8*3($a_ptr), $acc4
492 call __ecp_nistz256_mul_montq
494 $code.=<<___ if ($addx);
500 mov 8*0($b_org), %rdx
501 mov 8*0($a_ptr), $acc1
502 mov 8*1($a_ptr), $acc2
503 mov 8*2($a_ptr), $acc3
504 mov 8*3($a_ptr), $acc4
505 lea -128($a_ptr), $a_ptr # control u-op density
507 call __ecp_nistz256_mul_montx
518 .size ecp_nistz256_mul_mont,.-ecp_nistz256_mul_mont
520 .type __ecp_nistz256_mul_montq,\@abi-omnipotent
522 __ecp_nistz256_mul_montq:
523 ########################################################################
527 mov .Lpoly+8*1(%rip),$poly1
533 mov .Lpoly+8*3(%rip),$poly3
552 ########################################################################
553 # First reduction step
554 # Basically now we want to multiply acc[0] by p256,
555 # and add the result to the acc.
556 # Due to the special form of p256 we do some optimizations
558 # acc[0] x p256[0..1] = acc[0] x 2^96 - acc[0]
559 # then we add acc[0] and get acc[0] x 2^96
565 add $acc0, $acc1 # +=acc[0]<<96
568 mov 8*1($b_ptr), %rax
573 ########################################################################
606 ########################################################################
607 # Second reduction step
615 mov 8*2($b_ptr), %rax
620 ########################################################################
653 ########################################################################
654 # Third reduction step
662 mov 8*3($b_ptr), %rax
667 ########################################################################
700 ########################################################################
701 # Final reduction step
714 ########################################################################
715 # Branch-less conditional subtraction of P
716 sub \$-1, $acc4 # .Lpoly[0]
718 sbb $poly1, $acc5 # .Lpoly[1]
719 sbb \$0, $acc0 # .Lpoly[2]
721 sbb $poly3, $acc1 # .Lpoly[3]
726 mov $acc4, 8*0($r_ptr)
728 mov $acc5, 8*1($r_ptr)
730 mov $acc0, 8*2($r_ptr)
731 mov $acc1, 8*3($r_ptr)
734 .size __ecp_nistz256_mul_montq,.-__ecp_nistz256_mul_montq
736 ################################################################################
737 # void ecp_nistz256_sqr_mont(
741 # we optimize the square according to S.Gueron and V.Krasnov,
742 # "Speeding up Big-Number Squaring"
743 .globl ecp_nistz256_sqr_mont
744 .type ecp_nistz256_sqr_mont,\@function,2
746 ecp_nistz256_sqr_mont:
748 $code.=<<___ if ($addx);
750 and OPENSSL_ia32cap_P+8(%rip), %ecx
760 $code.=<<___ if ($addx);
765 mov 8*0($a_ptr), %rax
766 mov 8*1($a_ptr), $acc6
767 mov 8*2($a_ptr), $acc7
768 mov 8*3($a_ptr), $acc0
770 call __ecp_nistz256_sqr_montq
772 $code.=<<___ if ($addx);
777 mov 8*0($a_ptr), %rdx
778 mov 8*1($a_ptr), $acc6
779 mov 8*2($a_ptr), $acc7
780 mov 8*3($a_ptr), $acc0
781 lea -128($a_ptr), $a_ptr # control u-op density
783 call __ecp_nistz256_sqr_montx
794 .size ecp_nistz256_sqr_mont,.-ecp_nistz256_sqr_mont
796 .type __ecp_nistz256_sqr_montq,\@abi-omnipotent
798 __ecp_nistz256_sqr_montq:
800 mulq $acc6 # a[1]*a[0]
805 mulq $acc5 # a[0]*a[2]
811 mulq $acc5 # a[0]*a[3]
817 #################################
818 mulq $acc6 # a[1]*a[2]
824 mulq $acc6 # a[1]*a[3]
832 #################################
833 mulq $acc7 # a[2]*a[3]
836 mov 8*0($a_ptr), %rax
840 add $acc1, $acc1 # acc1:6<<1
850 mov 8*1($a_ptr), %rax
856 mov 8*2($a_ptr), %rax
863 mov 8*3($a_ptr), %rax
873 mov .Lpoly+8*1(%rip), $a_ptr
874 mov .Lpoly+8*3(%rip), $t1
876 ##########################################
883 add $acc0, $acc1 # +=acc[0]<<96
889 ##########################################
902 ##########################################
915 ###########################################
928 ############################################
929 # Add the rest of the acc
938 sub \$-1, $acc4 # .Lpoly[0]
940 sbb $a_ptr, $acc5 # .Lpoly[1]
941 sbb \$0, $acc6 # .Lpoly[2]
943 sbb $t1, $acc7 # .Lpoly[3]
948 mov $acc4, 8*0($r_ptr)
950 mov $acc5, 8*1($r_ptr)
952 mov $acc6, 8*2($r_ptr)
953 mov $acc7, 8*3($r_ptr)
956 .size __ecp_nistz256_sqr_montq,.-__ecp_nistz256_sqr_montq
961 .type __ecp_nistz256_mul_montx,\@abi-omnipotent
963 __ecp_nistz256_mul_montx:
964 ########################################################################
966 mulx $acc1, $acc0, $acc1
967 mulx $acc2, $t0, $acc2
969 xor $acc5, $acc5 # cf=0
970 mulx $acc3, $t1, $acc3
971 mov .Lpoly+8*3(%rip), $poly3
973 mulx $acc4, $t0, $acc4
976 shlx $poly1,$acc0,$t1
978 shrx $poly1,$acc0,$t0
981 ########################################################################
982 # First reduction step
986 mulx $poly3, $t0, $t1
987 mov 8*1($b_ptr), %rdx
991 xor $acc0, $acc0 # $acc0=0,cf=0,of=0
993 ########################################################################
995 mulx 8*0+128($a_ptr), $t0, $t1
999 mulx 8*1+128($a_ptr), $t0, $t1
1003 mulx 8*2+128($a_ptr), $t0, $t1
1007 mulx 8*3+128($a_ptr), $t0, $t1
1010 shlx $poly1, $acc1, $t0
1012 shrx $poly1, $acc1, $t1
1018 ########################################################################
1019 # Second reduction step
1023 mulx $poly3, $t0, $t1
1024 mov 8*2($b_ptr), %rdx
1028 xor $acc1 ,$acc1 # $acc1=0,cf=0,of=0
1030 ########################################################################
1032 mulx 8*0+128($a_ptr), $t0, $t1
1036 mulx 8*1+128($a_ptr), $t0, $t1
1040 mulx 8*2+128($a_ptr), $t0, $t1
1044 mulx 8*3+128($a_ptr), $t0, $t1
1047 shlx $poly1, $acc2, $t0
1049 shrx $poly1, $acc2, $t1
1055 ########################################################################
1056 # Third reduction step
1060 mulx $poly3, $t0, $t1
1061 mov 8*3($b_ptr), %rdx
1065 xor $acc2, $acc2 # $acc2=0,cf=0,of=0
1067 ########################################################################
1069 mulx 8*0+128($a_ptr), $t0, $t1
1073 mulx 8*1+128($a_ptr), $t0, $t1
1077 mulx 8*2+128($a_ptr), $t0, $t1
1081 mulx 8*3+128($a_ptr), $t0, $t1
1084 shlx $poly1, $acc3, $t0
1086 shrx $poly1, $acc3, $t1
1092 ########################################################################
1093 # Fourth reduction step
1097 mulx $poly3, $t0, $t1
1099 mov .Lpoly+8*1(%rip), $poly1
1105 ########################################################################
1106 # Branch-less conditional subtraction of P
1109 sbb \$-1, $acc4 # .Lpoly[0]
1110 sbb $poly1, $acc5 # .Lpoly[1]
1111 sbb \$0, $acc0 # .Lpoly[2]
1113 sbb $poly3, $acc1 # .Lpoly[3]
1118 mov $acc4, 8*0($r_ptr)
1120 mov $acc5, 8*1($r_ptr)
1122 mov $acc0, 8*2($r_ptr)
1123 mov $acc1, 8*3($r_ptr)
1126 .size __ecp_nistz256_mul_montx,.-__ecp_nistz256_mul_montx
1128 .type __ecp_nistz256_sqr_montx,\@abi-omnipotent
1130 __ecp_nistz256_sqr_montx:
1131 mulx $acc6, $acc1, $acc2 # a[0]*a[1]
1132 mulx $acc7, $t0, $acc3 # a[0]*a[2]
1135 mulx $acc0, $t1, $acc4 # a[0]*a[3]
1139 xor $acc5, $acc5 # $acc5=0,cf=0,of=0
1141 #################################
1142 mulx $acc7, $t0, $t1 # a[1]*a[2]
1146 mulx $acc0, $t0, $t1 # a[1]*a[3]
1152 #################################
1153 mulx $acc0, $t0, $acc6 # a[2]*a[3]
1154 mov 8*0+128($a_ptr), %rdx
1155 xor $acc7, $acc7 # $acc7=0,cf=0,of=0
1156 adcx $acc1, $acc1 # acc1:6<<1
1159 adox $acc7, $acc6 # of=0
1161 mulx %rdx, $acc0, $t1
1162 mov 8*1+128($a_ptr), %rdx
1167 mov 8*2+128($a_ptr), %rdx
1173 mov 8*3+128($a_ptr), %rdx
1181 mov .Lpoly+8*3(%rip), %rdx
1183 shlx $a_ptr, $acc0, $t0
1185 shrx $a_ptr, $acc0, $t4
1192 mulx $acc0, $t0, $acc0
1194 shlx $a_ptr, $acc1, $t0
1196 shrx $a_ptr, $acc1, $t4
1202 mulx $acc1, $t0, $acc1
1204 shlx $a_ptr, $acc2, $t0
1206 shrx $a_ptr, $acc2, $t4
1212 mulx $acc2, $t0, $acc2
1214 shlx $a_ptr, $acc3, $t0
1216 shrx $a_ptr, $acc3, $t4
1222 mulx $acc3, $t0, $acc3
1227 add $acc0, $acc4 # accumulate upper half
1228 mov .Lpoly+8*1(%rip), $a_ptr
1236 sub \$-1, $acc4 # .Lpoly[0]
1238 sbb $a_ptr, $acc5 # .Lpoly[1]
1239 sbb \$0, $acc6 # .Lpoly[2]
1241 sbb $t1, $acc7 # .Lpoly[3]
1246 mov $acc4, 8*0($r_ptr)
1248 mov $acc5, 8*1($r_ptr)
1250 mov $acc6, 8*2($r_ptr)
1251 mov $acc7, 8*3($r_ptr)
1254 .size __ecp_nistz256_sqr_montx,.-__ecp_nistz256_sqr_montx
1259 my ($r_ptr,$in_ptr)=("%rdi","%rsi");
1260 my ($acc0,$acc1,$acc2,$acc3)=map("%r$_",(8..11));
1261 my ($t0,$t1,$t2)=("%rcx","%r12","%r13");
1264 ################################################################################
1265 # void ecp_nistz256_from_mont(
1268 # This one performs Montgomery multiplication by 1, so we only need the reduction
1270 .globl ecp_nistz256_from_mont
1271 .type ecp_nistz256_from_mont,\@function,2
1273 ecp_nistz256_from_mont:
1277 mov 8*0($in_ptr), %rax
1278 mov .Lpoly+8*3(%rip), $t2
1279 mov 8*1($in_ptr), $acc1
1280 mov 8*2($in_ptr), $acc2
1281 mov 8*3($in_ptr), $acc3
1283 mov .Lpoly+8*1(%rip), $t1
1285 #########################################
1297 #########################################
1310 ##########################################
1323 ###########################################
1337 ###########################################
1338 # Branch-less conditional subtraction
1348 cmovnz $in_ptr, $acc1
1349 mov $acc0, 8*0($r_ptr)
1351 mov $acc1, 8*1($r_ptr)
1353 mov $acc2, 8*2($r_ptr)
1354 mov $acc3, 8*3($r_ptr)
1359 .size ecp_nistz256_from_mont,.-ecp_nistz256_from_mont
1363 my ($val,$in_t,$index)=$win64?("%rcx","%rdx","%r8d"):("%rdi","%rsi","%edx");
1364 my ($ONE,$INDEX,$Ra,$Rb,$Rc,$Rd,$Re,$Rf)=map("%xmm$_",(0..7));
1365 my ($M0,$T0a,$T0b,$T0c,$T0d,$T0e,$T0f,$TMP0)=map("%xmm$_",(8..15));
1366 my ($M1,$T2a,$T2b,$TMP2,$M2,$T2a,$T2b,$TMP2)=map("%xmm$_",(8..15));
1369 ################################################################################
1370 # void ecp_nistz256_select_w5(uint64_t *val, uint64_t *in_t, int index);
1371 .globl ecp_nistz256_select_w5
1372 .type ecp_nistz256_select_w5,\@abi-omnipotent
1374 ecp_nistz256_select_w5:
1376 $code.=<<___ if ($avx>1);
1377 mov OPENSSL_ia32cap_P+8(%rip), %eax
1379 jnz .Lavx2_select_w5
1381 $code.=<<___ if ($win64);
1382 lea -0x88(%rsp), %rax
1383 .LSEH_begin_ecp_nistz256_select_w5:
1384 .byte 0x48,0x8d,0x60,0xe0 #lea -0x20(%rax), %rsp
1385 .byte 0x0f,0x29,0x70,0xe0 #movaps %xmm6, -0x20(%rax)
1386 .byte 0x0f,0x29,0x78,0xf0 #movaps %xmm7, -0x10(%rax)
1387 .byte 0x44,0x0f,0x29,0x00 #movaps %xmm8, 0(%rax)
1388 .byte 0x44,0x0f,0x29,0x48,0x10 #movaps %xmm9, 0x10(%rax)
1389 .byte 0x44,0x0f,0x29,0x50,0x20 #movaps %xmm10, 0x20(%rax)
1390 .byte 0x44,0x0f,0x29,0x58,0x30 #movaps %xmm11, 0x30(%rax)
1391 .byte 0x44,0x0f,0x29,0x60,0x40 #movaps %xmm12, 0x40(%rax)
1392 .byte 0x44,0x0f,0x29,0x68,0x50 #movaps %xmm13, 0x50(%rax)
1393 .byte 0x44,0x0f,0x29,0x70,0x60 #movaps %xmm14, 0x60(%rax)
1394 .byte 0x44,0x0f,0x29,0x78,0x70 #movaps %xmm15, 0x70(%rax)
1397 movdqa .LOne(%rip), $ONE
1408 pshufd \$0, $INDEX, $INDEX
1411 .Lselect_loop_sse_w5:
1415 pcmpeqd $INDEX, $TMP0
1417 movdqa 16*0($in_t), $T0a
1418 movdqa 16*1($in_t), $T0b
1419 movdqa 16*2($in_t), $T0c
1420 movdqa 16*3($in_t), $T0d
1421 movdqa 16*4($in_t), $T0e
1422 movdqa 16*5($in_t), $T0f
1423 lea 16*6($in_t), $in_t
1439 jnz .Lselect_loop_sse_w5
1441 movdqu $Ra, 16*0($val)
1442 movdqu $Rb, 16*1($val)
1443 movdqu $Rc, 16*2($val)
1444 movdqu $Rd, 16*3($val)
1445 movdqu $Re, 16*4($val)
1446 movdqu $Rf, 16*5($val)
1448 $code.=<<___ if ($win64);
1449 movaps (%rsp), %xmm6
1450 movaps 0x10(%rsp), %xmm7
1451 movaps 0x20(%rsp), %xmm8
1452 movaps 0x30(%rsp), %xmm9
1453 movaps 0x40(%rsp), %xmm10
1454 movaps 0x50(%rsp), %xmm11
1455 movaps 0x60(%rsp), %xmm12
1456 movaps 0x70(%rsp), %xmm13
1457 movaps 0x80(%rsp), %xmm14
1458 movaps 0x90(%rsp), %xmm15
1459 lea 0xa8(%rsp), %rsp
1460 .LSEH_end_ecp_nistz256_select_w5:
1464 .size ecp_nistz256_select_w5,.-ecp_nistz256_select_w5
1466 ################################################################################
1467 # void ecp_nistz256_select_w7(uint64_t *val, uint64_t *in_t, int index);
1468 .globl ecp_nistz256_select_w7
1469 .type ecp_nistz256_select_w7,\@abi-omnipotent
1471 ecp_nistz256_select_w7:
1473 $code.=<<___ if ($avx>1);
1474 mov OPENSSL_ia32cap_P+8(%rip), %eax
1476 jnz .Lavx2_select_w7
1478 $code.=<<___ if ($win64);
1479 lea -0x88(%rsp), %rax
1480 .LSEH_begin_ecp_nistz256_select_w7:
1481 .byte 0x48,0x8d,0x60,0xe0 #lea -0x20(%rax), %rsp
1482 .byte 0x0f,0x29,0x70,0xe0 #movaps %xmm6, -0x20(%rax)
1483 .byte 0x0f,0x29,0x78,0xf0 #movaps %xmm7, -0x10(%rax)
1484 .byte 0x44,0x0f,0x29,0x00 #movaps %xmm8, 0(%rax)
1485 .byte 0x44,0x0f,0x29,0x48,0x10 #movaps %xmm9, 0x10(%rax)
1486 .byte 0x44,0x0f,0x29,0x50,0x20 #movaps %xmm10, 0x20(%rax)
1487 .byte 0x44,0x0f,0x29,0x58,0x30 #movaps %xmm11, 0x30(%rax)
1488 .byte 0x44,0x0f,0x29,0x60,0x40 #movaps %xmm12, 0x40(%rax)
1489 .byte 0x44,0x0f,0x29,0x68,0x50 #movaps %xmm13, 0x50(%rax)
1490 .byte 0x44,0x0f,0x29,0x70,0x60 #movaps %xmm14, 0x60(%rax)
1491 .byte 0x44,0x0f,0x29,0x78,0x70 #movaps %xmm15, 0x70(%rax)
1494 movdqa .LOne(%rip), $M0
1503 pshufd \$0, $INDEX, $INDEX
1506 .Lselect_loop_sse_w7:
1509 movdqa 16*0($in_t), $T0a
1510 movdqa 16*1($in_t), $T0b
1511 pcmpeqd $INDEX, $TMP0
1512 movdqa 16*2($in_t), $T0c
1513 movdqa 16*3($in_t), $T0d
1514 lea 16*4($in_t), $in_t
1523 prefetcht0 255($in_t)
1527 jnz .Lselect_loop_sse_w7
1529 movdqu $Ra, 16*0($val)
1530 movdqu $Rb, 16*1($val)
1531 movdqu $Rc, 16*2($val)
1532 movdqu $Rd, 16*3($val)
1534 $code.=<<___ if ($win64);
1535 movaps (%rsp), %xmm6
1536 movaps 0x10(%rsp), %xmm7
1537 movaps 0x20(%rsp), %xmm8
1538 movaps 0x30(%rsp), %xmm9
1539 movaps 0x40(%rsp), %xmm10
1540 movaps 0x50(%rsp), %xmm11
1541 movaps 0x60(%rsp), %xmm12
1542 movaps 0x70(%rsp), %xmm13
1543 movaps 0x80(%rsp), %xmm14
1544 movaps 0x90(%rsp), %xmm15
1545 lea 0xa8(%rsp), %rsp
1546 .LSEH_end_ecp_nistz256_select_w7:
1550 .size ecp_nistz256_select_w7,.-ecp_nistz256_select_w7
1554 my ($val,$in_t,$index)=$win64?("%rcx","%rdx","%r8d"):("%rdi","%rsi","%edx");
1555 my ($TWO,$INDEX,$Ra,$Rb,$Rc)=map("%ymm$_",(0..4));
1556 my ($M0,$T0a,$T0b,$T0c,$TMP0)=map("%ymm$_",(5..9));
1557 my ($M1,$T1a,$T1b,$T1c,$TMP1)=map("%ymm$_",(10..14));
1560 ################################################################################
1561 # void ecp_nistz256_avx2_select_w5(uint64_t *val, uint64_t *in_t, int index);
1562 .type ecp_nistz256_avx2_select_w5,\@abi-omnipotent
1564 ecp_nistz256_avx2_select_w5:
1568 $code.=<<___ if ($win64);
1569 lea -0x88(%rsp), %rax
1570 .LSEH_begin_ecp_nistz256_avx2_select_w5:
1571 .byte 0x48,0x8d,0x60,0xe0 #lea -0x20(%rax), %rsp
1572 .byte 0xc5,0xf8,0x29,0x70,0xe0 #vmovaps %xmm6, -0x20(%rax)
1573 .byte 0xc5,0xf8,0x29,0x78,0xf0 #vmovaps %xmm7, -0x10(%rax)
1574 .byte 0xc5,0x78,0x29,0x40,0x00 #vmovaps %xmm8, 8(%rax)
1575 .byte 0xc5,0x78,0x29,0x48,0x10 #vmovaps %xmm9, 0x10(%rax)
1576 .byte 0xc5,0x78,0x29,0x50,0x20 #vmovaps %xmm10, 0x20(%rax)
1577 .byte 0xc5,0x78,0x29,0x58,0x30 #vmovaps %xmm11, 0x30(%rax)
1578 .byte 0xc5,0x78,0x29,0x60,0x40 #vmovaps %xmm12, 0x40(%rax)
1579 .byte 0xc5,0x78,0x29,0x68,0x50 #vmovaps %xmm13, 0x50(%rax)
1580 .byte 0xc5,0x78,0x29,0x70,0x60 #vmovaps %xmm14, 0x60(%rax)
1581 .byte 0xc5,0x78,0x29,0x78,0x70 #vmovaps %xmm15, 0x70(%rax)
1584 vmovdqa .LTwo(%rip), $TWO
1590 vmovdqa .LOne(%rip), $M0
1591 vmovdqa .LTwo(%rip), $M1
1594 vpermd $INDEX, $Ra, $INDEX
1597 .Lselect_loop_avx2_w5:
1599 vmovdqa 32*0($in_t), $T0a
1600 vmovdqa 32*1($in_t), $T0b
1601 vmovdqa 32*2($in_t), $T0c
1603 vmovdqa 32*3($in_t), $T1a
1604 vmovdqa 32*4($in_t), $T1b
1605 vmovdqa 32*5($in_t), $T1c
1607 vpcmpeqd $INDEX, $M0, $TMP0
1608 vpcmpeqd $INDEX, $M1, $TMP1
1610 vpaddd $TWO, $M0, $M0
1611 vpaddd $TWO, $M1, $M1
1612 lea 32*6($in_t), $in_t
1614 vpand $TMP0, $T0a, $T0a
1615 vpand $TMP0, $T0b, $T0b
1616 vpand $TMP0, $T0c, $T0c
1617 vpand $TMP1, $T1a, $T1a
1618 vpand $TMP1, $T1b, $T1b
1619 vpand $TMP1, $T1c, $T1c
1621 vpxor $T0a, $Ra, $Ra
1622 vpxor $T0b, $Rb, $Rb
1623 vpxor $T0c, $Rc, $Rc
1624 vpxor $T1a, $Ra, $Ra
1625 vpxor $T1b, $Rb, $Rb
1626 vpxor $T1c, $Rc, $Rc
1629 jnz .Lselect_loop_avx2_w5
1631 vmovdqu $Ra, 32*0($val)
1632 vmovdqu $Rb, 32*1($val)
1633 vmovdqu $Rc, 32*2($val)
1636 $code.=<<___ if ($win64);
1637 movaps (%rsp), %xmm6
1638 movaps 0x10(%rsp), %xmm7
1639 movaps 0x20(%rsp), %xmm8
1640 movaps 0x30(%rsp), %xmm9
1641 movaps 0x40(%rsp), %xmm10
1642 movaps 0x50(%rsp), %xmm11
1643 movaps 0x60(%rsp), %xmm12
1644 movaps 0x70(%rsp), %xmm13
1645 movaps 0x80(%rsp), %xmm14
1646 movaps 0x90(%rsp), %xmm15
1647 lea 0xa8(%rsp), %rsp
1648 .LSEH_end_ecp_nistz256_avx2_select_w5:
1652 .size ecp_nistz256_avx2_select_w5,.-ecp_nistz256_avx2_select_w5
1656 my ($val,$in_t,$index)=$win64?("%rcx","%rdx","%r8d"):("%rdi","%rsi","%edx");
1657 my ($THREE,$INDEX,$Ra,$Rb)=map("%ymm$_",(0..3));
1658 my ($M0,$T0a,$T0b,$TMP0)=map("%ymm$_",(4..7));
1659 my ($M1,$T1a,$T1b,$TMP1)=map("%ymm$_",(8..11));
1660 my ($M2,$T2a,$T2b,$TMP2)=map("%ymm$_",(12..15));
1664 ################################################################################
1665 # void ecp_nistz256_avx2_select_w7(uint64_t *val, uint64_t *in_t, int index);
1666 .globl ecp_nistz256_avx2_select_w7
1667 .type ecp_nistz256_avx2_select_w7,\@abi-omnipotent
1669 ecp_nistz256_avx2_select_w7:
1673 $code.=<<___ if ($win64);
1674 lea -0x88(%rsp), %rax
1675 .LSEH_begin_ecp_nistz256_avx2_select_w7:
1676 .byte 0x48,0x8d,0x60,0xe0 #lea -0x20(%rax), %rsp
1677 .byte 0xc5,0xf8,0x29,0x70,0xe0 #vmovaps %xmm6, -0x20(%rax)
1678 .byte 0xc5,0xf8,0x29,0x78,0xf0 #vmovaps %xmm7, -0x10(%rax)
1679 .byte 0xc5,0x78,0x29,0x40,0x00 #vmovaps %xmm8, 8(%rax)
1680 .byte 0xc5,0x78,0x29,0x48,0x10 #vmovaps %xmm9, 0x10(%rax)
1681 .byte 0xc5,0x78,0x29,0x50,0x20 #vmovaps %xmm10, 0x20(%rax)
1682 .byte 0xc5,0x78,0x29,0x58,0x30 #vmovaps %xmm11, 0x30(%rax)
1683 .byte 0xc5,0x78,0x29,0x60,0x40 #vmovaps %xmm12, 0x40(%rax)
1684 .byte 0xc5,0x78,0x29,0x68,0x50 #vmovaps %xmm13, 0x50(%rax)
1685 .byte 0xc5,0x78,0x29,0x70,0x60 #vmovaps %xmm14, 0x60(%rax)
1686 .byte 0xc5,0x78,0x29,0x78,0x70 #vmovaps %xmm15, 0x70(%rax)
1689 vmovdqa .LThree(%rip), $THREE
1694 vmovdqa .LOne(%rip), $M0
1695 vmovdqa .LTwo(%rip), $M1
1696 vmovdqa .LThree(%rip), $M2
1699 vpermd $INDEX, $Ra, $INDEX
1700 # Skip index = 0, because it is implicitly the point at infinity
1703 .Lselect_loop_avx2_w7:
1705 vmovdqa 32*0($in_t), $T0a
1706 vmovdqa 32*1($in_t), $T0b
1708 vmovdqa 32*2($in_t), $T1a
1709 vmovdqa 32*3($in_t), $T1b
1711 vmovdqa 32*4($in_t), $T2a
1712 vmovdqa 32*5($in_t), $T2b
1714 vpcmpeqd $INDEX, $M0, $TMP0
1715 vpcmpeqd $INDEX, $M1, $TMP1
1716 vpcmpeqd $INDEX, $M2, $TMP2
1718 vpaddd $THREE, $M0, $M0
1719 vpaddd $THREE, $M1, $M1
1720 vpaddd $THREE, $M2, $M2
1721 lea 32*6($in_t), $in_t
1723 vpand $TMP0, $T0a, $T0a
1724 vpand $TMP0, $T0b, $T0b
1725 vpand $TMP1, $T1a, $T1a
1726 vpand $TMP1, $T1b, $T1b
1727 vpand $TMP2, $T2a, $T2a
1728 vpand $TMP2, $T2b, $T2b
1730 vpxor $T0a, $Ra, $Ra
1731 vpxor $T0b, $Rb, $Rb
1732 vpxor $T1a, $Ra, $Ra
1733 vpxor $T1b, $Rb, $Rb
1734 vpxor $T2a, $Ra, $Ra
1735 vpxor $T2b, $Rb, $Rb
1738 jnz .Lselect_loop_avx2_w7
1741 vmovdqa 32*0($in_t), $T0a
1742 vmovdqa 32*1($in_t), $T0b
1744 vpcmpeqd $INDEX, $M0, $TMP0
1746 vpand $TMP0, $T0a, $T0a
1747 vpand $TMP0, $T0b, $T0b
1749 vpxor $T0a, $Ra, $Ra
1750 vpxor $T0b, $Rb, $Rb
1752 vmovdqu $Ra, 32*0($val)
1753 vmovdqu $Rb, 32*1($val)
1756 $code.=<<___ if ($win64);
1757 movaps (%rsp), %xmm6
1758 movaps 0x10(%rsp), %xmm7
1759 movaps 0x20(%rsp), %xmm8
1760 movaps 0x30(%rsp), %xmm9
1761 movaps 0x40(%rsp), %xmm10
1762 movaps 0x50(%rsp), %xmm11
1763 movaps 0x60(%rsp), %xmm12
1764 movaps 0x70(%rsp), %xmm13
1765 movaps 0x80(%rsp), %xmm14
1766 movaps 0x90(%rsp), %xmm15
1767 lea 0xa8(%rsp), %rsp
1768 .LSEH_end_ecp_nistz256_avx2_select_w7:
1772 .size ecp_nistz256_avx2_select_w7,.-ecp_nistz256_avx2_select_w7
1776 .globl ecp_nistz256_avx2_select_w7
1777 .type ecp_nistz256_avx2_select_w7,\@function,3
1779 ecp_nistz256_avx2_select_w7:
1780 .byte 0x0f,0x0b # ud2
1782 .size ecp_nistz256_avx2_select_w7,.-ecp_nistz256_avx2_select_w7
1786 ########################################################################
1787 # This block implements higher level point_double, point_add and
1788 # point_add_affine. The key to performance in this case is to allow
1789 # out-of-order execution logic to overlap computations from next step
1790 # with tail processing from current step. By using tailored calling
1791 # sequence we minimize inter-step overhead to give processor better
1792 # shot at overlapping operations...
1794 # You will notice that input data is copied to stack. Trouble is that
1795 # there are no registers to spare for holding original pointers and
1796 # reloading them, pointers, would create undesired dependencies on
1797 # effective addresses calculation paths. In other words it's too done
1798 # to favour out-of-order execution logic.
1799 # <appro@openssl.org>
1801 my ($r_ptr,$a_ptr,$b_org,$b_ptr)=("%rdi","%rsi","%rdx","%rbx");
1802 my ($acc0,$acc1,$acc2,$acc3,$acc4,$acc5,$acc6,$acc7)=map("%r$_",(8..15));
1803 my ($t0,$t1,$t2,$t3,$t4)=("%rax","%rbp","%rcx",$acc4,$acc4);
1804 my ($poly1,$poly3)=($acc6,$acc7);
1806 sub load_for_mul () {
1807 my ($a,$b,$src0) = @_;
1808 my $bias = $src0 eq "%rax" ? 0 : -128;
1814 lea $bias+$a, $a_ptr
1819 sub load_for_sqr () {
1821 my $bias = $src0 eq "%rax" ? 0 : -128;
1825 lea $bias+$a, $a_ptr
1831 ########################################################################
1832 # operate in 4-5-0-1 "name space" that matches multiplication output
1834 my ($a0,$a1,$a2,$a3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
1837 .type __ecp_nistz256_add_toq,\@abi-omnipotent
1839 __ecp_nistz256_add_toq:
1841 add 8*0($b_ptr), $a0
1842 adc 8*1($b_ptr), $a1
1844 adc 8*2($b_ptr), $a2
1845 adc 8*3($b_ptr), $a3
1859 mov $a0, 8*0($r_ptr)
1861 mov $a1, 8*1($r_ptr)
1863 mov $a2, 8*2($r_ptr)
1864 mov $a3, 8*3($r_ptr)
1867 .size __ecp_nistz256_add_toq,.-__ecp_nistz256_add_toq
1869 .type __ecp_nistz256_sub_fromq,\@abi-omnipotent
1871 __ecp_nistz256_sub_fromq:
1872 sub 8*0($b_ptr), $a0
1873 sbb 8*1($b_ptr), $a1
1875 sbb 8*2($b_ptr), $a2
1876 sbb 8*3($b_ptr), $a3
1890 mov $a0, 8*0($r_ptr)
1892 mov $a1, 8*1($r_ptr)
1894 mov $a2, 8*2($r_ptr)
1895 mov $a3, 8*3($r_ptr)
1898 .size __ecp_nistz256_sub_fromq,.-__ecp_nistz256_sub_fromq
1900 .type __ecp_nistz256_subq,\@abi-omnipotent
1902 __ecp_nistz256_subq:
1925 .size __ecp_nistz256_subq,.-__ecp_nistz256_subq
1927 .type __ecp_nistz256_mul_by_2q,\@abi-omnipotent
1929 __ecp_nistz256_mul_by_2q:
1931 add $a0, $a0 # a0:a3+a0:a3
1949 mov $a0, 8*0($r_ptr)
1951 mov $a1, 8*1($r_ptr)
1953 mov $a2, 8*2($r_ptr)
1954 mov $a3, 8*3($r_ptr)
1957 .size __ecp_nistz256_mul_by_2q,.-__ecp_nistz256_mul_by_2q
1962 my ($src0,$sfx,$bias);
1963 my ($S,$M,$Zsqr,$in_x,$tmp0)=map(32*$_,(0..4));
1971 .globl ecp_nistz256_point_double
1972 .type ecp_nistz256_point_double,\@function,2
1974 ecp_nistz256_point_double:
1976 $code.=<<___ if ($addx);
1978 and OPENSSL_ia32cap_P+8(%rip), %ecx
1988 .type ecp_nistz256_point_doublex,\@function,2
1990 ecp_nistz256_point_doublex:
2003 .Lpoint_double_shortcut$x:
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)
2243 movdqa %xmm2, $in1_y(%rsp)
2244 movdqa %xmm3, $in1_y+0x10(%rsp)
2245 movdqa %xmm4, $in1_z(%rsp)
2246 movdqa %xmm5, $in1_z+0x10(%rsp)
2249 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$b_ptr
2250 pshufd \$0xb1, %xmm5, %xmm3
2251 movdqu 0x10($a_ptr), %xmm1
2252 movdqu 0x20($a_ptr), %xmm2
2254 movdqu 0x30($a_ptr), %xmm3
2255 mov 0x40+8*0($a_ptr), $src0 # load original in2_z
2256 mov 0x40+8*1($a_ptr), $acc6
2257 mov 0x40+8*2($a_ptr), $acc7
2258 mov 0x40+8*3($a_ptr), $acc0
2259 movdqa %xmm0, $in2_x(%rsp)
2260 pshufd \$0x1e, %xmm5, %xmm4
2261 movdqa %xmm1, $in2_x+0x10(%rsp)
2262 movdqu 0x40($a_ptr),%xmm0 # in2_z again
2263 movdqu 0x50($a_ptr),%xmm1
2264 movdqa %xmm2, $in2_y(%rsp)
2265 movdqa %xmm3, $in2_y+0x10(%rsp)
2269 movq $r_ptr, %xmm0 # save $r_ptr
2271 lea 0x40-$bias($a_ptr), $a_ptr # $a_ptr is still valid
2272 mov $src0, $in2_z+8*0(%rsp) # make in2_z copy
2273 mov $acc6, $in2_z+8*1(%rsp)
2274 mov $acc7, $in2_z+8*2(%rsp)
2275 mov $acc0, $in2_z+8*3(%rsp)
2276 lea $Z2sqr(%rsp), $r_ptr # Z2^2
2277 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Z2sqr, in2_z);
2279 pcmpeqd %xmm4, %xmm5
2280 pshufd \$0xb1, %xmm1, %xmm4
2282 pshufd \$0, %xmm5, %xmm5 # in1infty
2283 pshufd \$0x1e, %xmm4, %xmm3
2286 pcmpeqd %xmm3, %xmm4
2287 pshufd \$0, %xmm4, %xmm4 # in2infty
2288 mov 0x40+8*0($b_ptr), $src0 # load original in1_z
2289 mov 0x40+8*1($b_ptr), $acc6
2290 mov 0x40+8*2($b_ptr), $acc7
2291 mov 0x40+8*3($b_ptr), $acc0
2294 lea 0x40-$bias($b_ptr), $a_ptr
2295 lea $Z1sqr(%rsp), $r_ptr # Z1^2
2296 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Z1sqr, in1_z);
2298 `&load_for_mul("$Z2sqr(%rsp)", "$in2_z(%rsp)", "$src0")`
2299 lea $S1(%rsp), $r_ptr # S1 = Z2^3
2300 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S1, Z2sqr, in2_z);
2302 `&load_for_mul("$Z1sqr(%rsp)", "$in1_z(%rsp)", "$src0")`
2303 lea $S2(%rsp), $r_ptr # S2 = Z1^3
2304 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, Z1sqr, in1_z);
2306 `&load_for_mul("$S1(%rsp)", "$in1_y(%rsp)", "$src0")`
2307 lea $S1(%rsp), $r_ptr # S1 = Y1*Z2^3
2308 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S1, S1, in1_y);
2310 `&load_for_mul("$S2(%rsp)", "$in2_y(%rsp)", "$src0")`
2311 lea $S2(%rsp), $r_ptr # S2 = Y2*Z1^3
2312 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, S2, in2_y);
2314 lea $S1(%rsp), $b_ptr
2315 lea $R(%rsp), $r_ptr # R = S2 - S1
2316 call __ecp_nistz256_sub_from$x # p256_sub(R, S2, S1);
2318 or $acc5, $acc4 # see if result is zero
2322 por %xmm5, %xmm2 # in1infty || in2infty
2325 `&load_for_mul("$Z2sqr(%rsp)", "$in1_x(%rsp)", "$src0")`
2326 lea $U1(%rsp), $r_ptr # U1 = X1*Z2^2
2327 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U1, in1_x, Z2sqr);
2329 `&load_for_mul("$Z1sqr(%rsp)", "$in2_x(%rsp)", "$src0")`
2330 lea $U2(%rsp), $r_ptr # U2 = X2*Z1^2
2331 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, in2_x, Z1sqr);
2333 lea $U1(%rsp), $b_ptr
2334 lea $H(%rsp), $r_ptr # H = U2 - U1
2335 call __ecp_nistz256_sub_from$x # p256_sub(H, U2, U1);
2337 or $acc5, $acc4 # see if result is zero
2341 .byte 0x3e # predict taken
2342 jnz .Ladd_proceed$x # is_equal(U1,U2)?
2346 jnz .Ladd_proceed$x # (in1infty || in2infty)?
2348 jz .Ladd_double$x # is_equal(S1,S2)?
2350 movq %xmm0, $r_ptr # restore $r_ptr
2352 movdqu %xmm0, 0x00($r_ptr)
2353 movdqu %xmm0, 0x10($r_ptr)
2354 movdqu %xmm0, 0x20($r_ptr)
2355 movdqu %xmm0, 0x30($r_ptr)
2356 movdqu %xmm0, 0x40($r_ptr)
2357 movdqu %xmm0, 0x50($r_ptr)
2362 movq %xmm1, $a_ptr # restore $a_ptr
2363 movq %xmm0, $r_ptr # restore $r_ptr
2364 add \$`32*(18-5)`, %rsp # difference in frame sizes
2365 jmp .Lpoint_double_shortcut$x
2369 `&load_for_sqr("$R(%rsp)", "$src0")`
2370 lea $Rsqr(%rsp), $r_ptr # R^2
2371 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Rsqr, R);
2373 `&load_for_mul("$H(%rsp)", "$in1_z(%rsp)", "$src0")`
2374 lea $res_z(%rsp), $r_ptr # Z3 = H*Z1*Z2
2375 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, H, in1_z);
2377 `&load_for_sqr("$H(%rsp)", "$src0")`
2378 lea $Hsqr(%rsp), $r_ptr # H^2
2379 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Hsqr, H);
2381 `&load_for_mul("$res_z(%rsp)", "$in2_z(%rsp)", "$src0")`
2382 lea $res_z(%rsp), $r_ptr # Z3 = H*Z1*Z2
2383 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, res_z, in2_z);
2385 `&load_for_mul("$Hsqr(%rsp)", "$H(%rsp)", "$src0")`
2386 lea $Hcub(%rsp), $r_ptr # H^3
2387 call __ecp_nistz256_mul_mont$x # p256_mul_mont(Hcub, Hsqr, H);
2389 `&load_for_mul("$Hsqr(%rsp)", "$U1(%rsp)", "$src0")`
2390 lea $U2(%rsp), $r_ptr # U1*H^2
2391 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, U1, Hsqr);
2394 #######################################################################
2395 # operate in 4-5-0-1 "name space" that matches multiplication output
2397 my ($acc0,$acc1,$acc2,$acc3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
2398 my ($poly1, $poly3)=($acc6,$acc7);
2401 #lea $U2(%rsp), $a_ptr
2402 #lea $Hsqr(%rsp), $r_ptr # 2*U1*H^2
2403 #call __ecp_nistz256_mul_by_2 # ecp_nistz256_mul_by_2(Hsqr, U2);
2406 add $acc0, $acc0 # a0:a3+a0:a3
2407 lea $Rsqr(%rsp), $a_ptr
2424 mov 8*0($a_ptr), $t0
2426 mov 8*1($a_ptr), $t1
2428 mov 8*2($a_ptr), $t2
2430 mov 8*3($a_ptr), $t3
2432 call __ecp_nistz256_sub$x # p256_sub(res_x, Rsqr, Hsqr);
2434 lea $Hcub(%rsp), $b_ptr
2435 lea $res_x(%rsp), $r_ptr
2436 call __ecp_nistz256_sub_from$x # p256_sub(res_x, res_x, Hcub);
2438 mov $U2+8*0(%rsp), $t0
2439 mov $U2+8*1(%rsp), $t1
2440 mov $U2+8*2(%rsp), $t2
2441 mov $U2+8*3(%rsp), $t3
2442 lea $res_y(%rsp), $r_ptr
2444 call __ecp_nistz256_sub$x # p256_sub(res_y, U2, res_x);
2446 mov $acc0, 8*0($r_ptr) # save the result, as
2447 mov $acc1, 8*1($r_ptr) # __ecp_nistz256_sub doesn't
2448 mov $acc2, 8*2($r_ptr)
2449 mov $acc3, 8*3($r_ptr)
2453 `&load_for_mul("$S1(%rsp)", "$Hcub(%rsp)", "$src0")`
2454 lea $S2(%rsp), $r_ptr
2455 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, S1, Hcub);
2457 `&load_for_mul("$R(%rsp)", "$res_y(%rsp)", "$src0")`
2458 lea $res_y(%rsp), $r_ptr
2459 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_y, R, res_y);
2461 lea $S2(%rsp), $b_ptr
2462 lea $res_y(%rsp), $r_ptr
2463 call __ecp_nistz256_sub_from$x # p256_sub(res_y, res_y, S2);
2465 movq %xmm0, $r_ptr # restore $r_ptr
2467 movdqa %xmm5, %xmm0 # copy_conditional(res_z, in2_z, in1infty);
2469 pandn $res_z(%rsp), %xmm0
2471 pandn $res_z+0x10(%rsp), %xmm1
2473 pand $in2_z(%rsp), %xmm2
2474 pand $in2_z+0x10(%rsp), %xmm3
2478 movdqa %xmm4, %xmm0 # copy_conditional(res_z, in1_z, in2infty);
2484 pand $in1_z(%rsp), %xmm2
2485 pand $in1_z+0x10(%rsp), %xmm3
2488 movdqu %xmm2, 0x40($r_ptr)
2489 movdqu %xmm3, 0x50($r_ptr)
2491 movdqa %xmm5, %xmm0 # copy_conditional(res_x, in2_x, in1infty);
2493 pandn $res_x(%rsp), %xmm0
2495 pandn $res_x+0x10(%rsp), %xmm1
2497 pand $in2_x(%rsp), %xmm2
2498 pand $in2_x+0x10(%rsp), %xmm3
2502 movdqa %xmm4, %xmm0 # copy_conditional(res_x, in1_x, in2infty);
2508 pand $in1_x(%rsp), %xmm2
2509 pand $in1_x+0x10(%rsp), %xmm3
2512 movdqu %xmm2, 0x00($r_ptr)
2513 movdqu %xmm3, 0x10($r_ptr)
2515 movdqa %xmm5, %xmm0 # copy_conditional(res_y, in2_y, in1infty);
2517 pandn $res_y(%rsp), %xmm0
2519 pandn $res_y+0x10(%rsp), %xmm1
2521 pand $in2_y(%rsp), %xmm2
2522 pand $in2_y+0x10(%rsp), %xmm3
2526 movdqa %xmm4, %xmm0 # copy_conditional(res_y, in1_y, in2infty);
2532 pand $in1_y(%rsp), %xmm2
2533 pand $in1_y+0x10(%rsp), %xmm3
2536 movdqu %xmm2, 0x20($r_ptr)
2537 movdqu %xmm3, 0x30($r_ptr)
2548 .size ecp_nistz256_point_add$sfx,.-ecp_nistz256_point_add$sfx
2553 sub gen_add_affine () {
2555 my ($src0,$sfx,$bias);
2556 my ($U2,$S2,$H,$R,$Hsqr,$Hcub,$Rsqr,
2557 $res_x,$res_y,$res_z,
2558 $in1_x,$in1_y,$in1_z,
2559 $in2_x,$in2_y)=map(32*$_,(0..14));
2568 .globl ecp_nistz256_point_add_affine
2569 .type ecp_nistz256_point_add_affine,\@function,3
2571 ecp_nistz256_point_add_affine:
2573 $code.=<<___ if ($addx);
2575 and OPENSSL_ia32cap_P+8(%rip), %ecx
2577 je .Lpoint_add_affinex
2585 .type ecp_nistz256_point_add_affinex,\@function,3
2587 ecp_nistz256_point_add_affinex:
2588 .Lpoint_add_affinex:
2600 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$a_ptr
2601 mov $b_org, $b_ptr # reassign
2602 movdqu 0x10($a_ptr), %xmm1
2603 movdqu 0x20($a_ptr), %xmm2
2604 movdqu 0x30($a_ptr), %xmm3
2605 movdqu 0x40($a_ptr), %xmm4
2606 movdqu 0x50($a_ptr), %xmm5
2607 mov 0x40+8*0($a_ptr), $src0 # load original in1_z
2608 mov 0x40+8*1($a_ptr), $acc6
2609 mov 0x40+8*2($a_ptr), $acc7
2610 mov 0x40+8*3($a_ptr), $acc0
2611 movdqa %xmm0, $in1_x(%rsp)
2612 movdqa %xmm1, $in1_x+0x10(%rsp)
2613 movdqa %xmm2, $in1_y(%rsp)
2614 movdqa %xmm3, $in1_y+0x10(%rsp)
2615 movdqa %xmm4, $in1_z(%rsp)
2616 movdqa %xmm5, $in1_z+0x10(%rsp)
2619 movdqu 0x00($b_ptr), %xmm0 # copy *(P256_POINT_AFFINE *)$b_ptr
2620 pshufd \$0xb1, %xmm5, %xmm3
2621 movdqu 0x10($b_ptr), %xmm1
2622 movdqu 0x20($b_ptr), %xmm2
2624 movdqu 0x30($b_ptr), %xmm3
2625 movdqa %xmm0, $in2_x(%rsp)
2626 pshufd \$0x1e, %xmm5, %xmm4
2627 movdqa %xmm1, $in2_x+0x10(%rsp)
2629 movq $r_ptr, %xmm0 # save $r_ptr
2630 movdqa %xmm2, $in2_y(%rsp)
2631 movdqa %xmm3, $in2_y+0x10(%rsp)
2637 lea 0x40-$bias($a_ptr), $a_ptr # $a_ptr is still valid
2638 lea $Z1sqr(%rsp), $r_ptr # Z1^2
2639 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Z1sqr, in1_z);
2641 pcmpeqd %xmm4, %xmm5
2642 pshufd \$0xb1, %xmm3, %xmm4
2643 mov 0x00($b_ptr), $src0 # $b_ptr is still valid
2644 #lea 0x00($b_ptr), $b_ptr
2645 mov $acc4, $acc1 # harmonize sqr output and mul input
2647 pshufd \$0, %xmm5, %xmm5 # in1infty
2648 pshufd \$0x1e, %xmm4, %xmm3
2653 pcmpeqd %xmm3, %xmm4
2654 pshufd \$0, %xmm4, %xmm4 # in2infty
2656 lea $Z1sqr-$bias(%rsp), $a_ptr
2658 lea $U2(%rsp), $r_ptr # U2 = X2*Z1^2
2659 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, Z1sqr, in2_x);
2661 lea $in1_x(%rsp), $b_ptr
2662 lea $H(%rsp), $r_ptr # H = U2 - U1
2663 call __ecp_nistz256_sub_from$x # p256_sub(H, U2, in1_x);
2665 `&load_for_mul("$Z1sqr(%rsp)", "$in1_z(%rsp)", "$src0")`
2666 lea $S2(%rsp), $r_ptr # S2 = Z1^3
2667 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, Z1sqr, in1_z);
2669 `&load_for_mul("$H(%rsp)", "$in1_z(%rsp)", "$src0")`
2670 lea $res_z(%rsp), $r_ptr # Z3 = H*Z1*Z2
2671 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, H, in1_z);
2673 `&load_for_mul("$S2(%rsp)", "$in2_y(%rsp)", "$src0")`
2674 lea $S2(%rsp), $r_ptr # S2 = Y2*Z1^3
2675 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, S2, in2_y);
2677 lea $in1_y(%rsp), $b_ptr
2678 lea $R(%rsp), $r_ptr # R = S2 - S1
2679 call __ecp_nistz256_sub_from$x # p256_sub(R, S2, in1_y);
2681 `&load_for_sqr("$H(%rsp)", "$src0")`
2682 lea $Hsqr(%rsp), $r_ptr # H^2
2683 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Hsqr, H);
2685 `&load_for_sqr("$R(%rsp)", "$src0")`
2686 lea $Rsqr(%rsp), $r_ptr # R^2
2687 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Rsqr, R);
2689 `&load_for_mul("$H(%rsp)", "$Hsqr(%rsp)", "$src0")`
2690 lea $Hcub(%rsp), $r_ptr # H^3
2691 call __ecp_nistz256_mul_mont$x # p256_mul_mont(Hcub, Hsqr, H);
2693 `&load_for_mul("$Hsqr(%rsp)", "$in1_x(%rsp)", "$src0")`
2694 lea $U2(%rsp), $r_ptr # U1*H^2
2695 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, in1_x, Hsqr);
2698 #######################################################################
2699 # operate in 4-5-0-1 "name space" that matches multiplication output
2701 my ($acc0,$acc1,$acc2,$acc3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
2702 my ($poly1, $poly3)=($acc6,$acc7);
2705 #lea $U2(%rsp), $a_ptr
2706 #lea $Hsqr(%rsp), $r_ptr # 2*U1*H^2
2707 #call __ecp_nistz256_mul_by_2 # ecp_nistz256_mul_by_2(Hsqr, U2);
2710 add $acc0, $acc0 # a0:a3+a0:a3
2711 lea $Rsqr(%rsp), $a_ptr
2728 mov 8*0($a_ptr), $t0
2730 mov 8*1($a_ptr), $t1
2732 mov 8*2($a_ptr), $t2
2734 mov 8*3($a_ptr), $t3
2736 call __ecp_nistz256_sub$x # p256_sub(res_x, Rsqr, Hsqr);
2738 lea $Hcub(%rsp), $b_ptr
2739 lea $res_x(%rsp), $r_ptr
2740 call __ecp_nistz256_sub_from$x # p256_sub(res_x, res_x, Hcub);
2742 mov $U2+8*0(%rsp), $t0
2743 mov $U2+8*1(%rsp), $t1
2744 mov $U2+8*2(%rsp), $t2
2745 mov $U2+8*3(%rsp), $t3
2746 lea $H(%rsp), $r_ptr
2748 call __ecp_nistz256_sub$x # p256_sub(H, U2, res_x);
2750 mov $acc0, 8*0($r_ptr) # save the result, as
2751 mov $acc1, 8*1($r_ptr) # __ecp_nistz256_sub doesn't
2752 mov $acc2, 8*2($r_ptr)
2753 mov $acc3, 8*3($r_ptr)
2757 `&load_for_mul("$Hcub(%rsp)", "$in1_y(%rsp)", "$src0")`
2758 lea $S2(%rsp), $r_ptr
2759 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, Hcub, in1_y);
2761 `&load_for_mul("$H(%rsp)", "$R(%rsp)", "$src0")`
2762 lea $H(%rsp), $r_ptr
2763 call __ecp_nistz256_mul_mont$x # p256_mul_mont(H, H, R);
2765 lea $S2(%rsp), $b_ptr
2766 lea $res_y(%rsp), $r_ptr
2767 call __ecp_nistz256_sub_from$x # p256_sub(res_y, H, S2);
2769 movq %xmm0, $r_ptr # restore $r_ptr
2771 movdqa %xmm5, %xmm0 # copy_conditional(res_z, ONE, in1infty);
2773 pandn $res_z(%rsp), %xmm0
2775 pandn $res_z+0x10(%rsp), %xmm1
2777 pand .LONE_mont(%rip), %xmm2
2778 pand .LONE_mont+0x10(%rip), %xmm3
2782 movdqa %xmm4, %xmm0 # copy_conditional(res_z, in1_z, in2infty);
2788 pand $in1_z(%rsp), %xmm2
2789 pand $in1_z+0x10(%rsp), %xmm3
2792 movdqu %xmm2, 0x40($r_ptr)
2793 movdqu %xmm3, 0x50($r_ptr)
2795 movdqa %xmm5, %xmm0 # copy_conditional(res_x, in2_x, in1infty);
2797 pandn $res_x(%rsp), %xmm0
2799 pandn $res_x+0x10(%rsp), %xmm1
2801 pand $in2_x(%rsp), %xmm2
2802 pand $in2_x+0x10(%rsp), %xmm3
2806 movdqa %xmm4, %xmm0 # copy_conditional(res_x, in1_x, in2infty);
2812 pand $in1_x(%rsp), %xmm2
2813 pand $in1_x+0x10(%rsp), %xmm3
2816 movdqu %xmm2, 0x00($r_ptr)
2817 movdqu %xmm3, 0x10($r_ptr)
2819 movdqa %xmm5, %xmm0 # copy_conditional(res_y, in2_y, in1infty);
2821 pandn $res_y(%rsp), %xmm0
2823 pandn $res_y+0x10(%rsp), %xmm1
2825 pand $in2_y(%rsp), %xmm2
2826 pand $in2_y+0x10(%rsp), %xmm3
2830 movdqa %xmm4, %xmm0 # copy_conditional(res_y, in1_y, in2infty);
2836 pand $in1_y(%rsp), %xmm2
2837 pand $in1_y+0x10(%rsp), %xmm3
2840 movdqu %xmm2, 0x20($r_ptr)
2841 movdqu %xmm3, 0x30($r_ptr)
2851 .size ecp_nistz256_point_add_affine$sfx,.-ecp_nistz256_point_add_affine$sfx
2854 &gen_add_affine("q");
2856 ########################################################################
2860 ########################################################################
2861 # operate in 4-5-0-1 "name space" that matches multiplication output
2863 my ($a0,$a1,$a2,$a3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
2866 .type __ecp_nistz256_add_tox,\@abi-omnipotent
2868 __ecp_nistz256_add_tox:
2870 adc 8*0($b_ptr), $a0
2871 adc 8*1($b_ptr), $a1
2873 adc 8*2($b_ptr), $a2
2874 adc 8*3($b_ptr), $a3
2889 mov $a0, 8*0($r_ptr)
2891 mov $a1, 8*1($r_ptr)
2893 mov $a2, 8*2($r_ptr)
2894 mov $a3, 8*3($r_ptr)
2897 .size __ecp_nistz256_add_tox,.-__ecp_nistz256_add_tox
2899 .type __ecp_nistz256_sub_fromx,\@abi-omnipotent
2901 __ecp_nistz256_sub_fromx:
2903 sbb 8*0($b_ptr), $a0
2904 sbb 8*1($b_ptr), $a1
2906 sbb 8*2($b_ptr), $a2
2907 sbb 8*3($b_ptr), $a3
2922 mov $a0, 8*0($r_ptr)
2924 mov $a1, 8*1($r_ptr)
2926 mov $a2, 8*2($r_ptr)
2927 mov $a3, 8*3($r_ptr)
2930 .size __ecp_nistz256_sub_fromx,.-__ecp_nistz256_sub_fromx
2932 .type __ecp_nistz256_subx,\@abi-omnipotent
2934 __ecp_nistz256_subx:
2959 .size __ecp_nistz256_subx,.-__ecp_nistz256_subx
2961 .type __ecp_nistz256_mul_by_2x,\@abi-omnipotent
2963 __ecp_nistz256_mul_by_2x:
2965 adc $a0, $a0 # a0:a3+a0:a3
2984 mov $a0, 8*0($r_ptr)
2986 mov $a1, 8*1($r_ptr)
2988 mov $a2, 8*2($r_ptr)
2989 mov $a3, 8*3($r_ptr)
2992 .size __ecp_nistz256_mul_by_2x,.-__ecp_nistz256_mul_by_2x
2997 &gen_add_affine("x");
3001 $code =~ s/\`([^\`]*)\`/eval $1/gem;