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 .Lpoint_double_shortcut$x:
2005 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$a_ptr.x
2006 mov $a_ptr, $b_ptr # backup copy
2007 movdqu 0x10($a_ptr), %xmm1
2008 mov 0x20+8*0($a_ptr), $acc4 # load in_y in "5-4-0-1" order
2009 mov 0x20+8*1($a_ptr), $acc5
2010 mov 0x20+8*2($a_ptr), $acc0
2011 mov 0x20+8*3($a_ptr), $acc1
2012 mov .Lpoly+8*1(%rip), $poly1
2013 mov .Lpoly+8*3(%rip), $poly3
2014 movdqa %xmm0, $in_x(%rsp)
2015 movdqa %xmm1, $in_x+0x10(%rsp)
2016 lea 0x20($r_ptr), $acc2
2017 lea 0x40($r_ptr), $acc3
2022 lea $S(%rsp), $r_ptr
2023 call __ecp_nistz256_mul_by_2$x # p256_mul_by_2(S, in_y);
2025 mov 0x40+8*0($a_ptr), $src0
2026 mov 0x40+8*1($a_ptr), $acc6
2027 mov 0x40+8*2($a_ptr), $acc7
2028 mov 0x40+8*3($a_ptr), $acc0
2029 lea 0x40-$bias($a_ptr), $a_ptr
2030 lea $Zsqr(%rsp), $r_ptr
2031 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Zsqr, in_z);
2033 `&load_for_sqr("$S(%rsp)", "$src0")`
2034 lea $S(%rsp), $r_ptr
2035 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(S, S);
2037 mov 0x20($b_ptr), $src0 # $b_ptr is still valid
2038 mov 0x40+8*0($b_ptr), $acc1
2039 mov 0x40+8*1($b_ptr), $acc2
2040 mov 0x40+8*2($b_ptr), $acc3
2041 mov 0x40+8*3($b_ptr), $acc4
2042 lea 0x40-$bias($b_ptr), $a_ptr
2043 lea 0x20($b_ptr), $b_ptr
2045 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, in_z, in_y);
2046 call __ecp_nistz256_mul_by_2$x # p256_mul_by_2(res_z, res_z);
2048 mov $in_x+8*0(%rsp), $acc4 # "5-4-0-1" order
2049 mov $in_x+8*1(%rsp), $acc5
2050 lea $Zsqr(%rsp), $b_ptr
2051 mov $in_x+8*2(%rsp), $acc0
2052 mov $in_x+8*3(%rsp), $acc1
2053 lea $M(%rsp), $r_ptr
2054 call __ecp_nistz256_add_to$x # p256_add(M, in_x, Zsqr);
2056 mov $in_x+8*0(%rsp), $acc4 # "5-4-0-1" order
2057 mov $in_x+8*1(%rsp), $acc5
2058 lea $Zsqr(%rsp), $b_ptr
2059 mov $in_x+8*2(%rsp), $acc0
2060 mov $in_x+8*3(%rsp), $acc1
2061 lea $Zsqr(%rsp), $r_ptr
2062 call __ecp_nistz256_sub_from$x # p256_sub(Zsqr, in_x, Zsqr);
2064 `&load_for_sqr("$S(%rsp)", "$src0")`
2066 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(res_y, S);
2069 ######## ecp_nistz256_div_by_2(res_y, res_y); ##########################
2070 # operate in 4-5-6-7 "name space" that matches squaring output
2072 my ($poly1,$poly3)=($a_ptr,$t1);
2073 my ($a0,$a1,$a2,$a3,$t3,$t4,$t1)=($acc4,$acc5,$acc6,$acc7,$acc0,$acc1,$acc2);
2086 xor $a_ptr, $a_ptr # borrow $a_ptr
2095 mov $a1, $t0 # a0:a3>>1
2106 mov $a0, 8*0($r_ptr)
2108 mov $a1, 8*1($r_ptr)
2112 mov $a2, 8*2($r_ptr)
2113 mov $a3, 8*3($r_ptr)
2117 `&load_for_mul("$M(%rsp)", "$Zsqr(%rsp)", "$src0")`
2118 lea $M(%rsp), $r_ptr
2119 call __ecp_nistz256_mul_mont$x # p256_mul_mont(M, M, Zsqr);
2121 lea $tmp0(%rsp), $r_ptr
2122 call __ecp_nistz256_mul_by_2$x
2124 lea $M(%rsp), $b_ptr
2125 lea $M(%rsp), $r_ptr
2126 call __ecp_nistz256_add_to$x # p256_mul_by_3(M, M);
2128 `&load_for_mul("$S(%rsp)", "$in_x(%rsp)", "$src0")`
2129 lea $S(%rsp), $r_ptr
2130 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S, S, in_x);
2132 lea $tmp0(%rsp), $r_ptr
2133 call __ecp_nistz256_mul_by_2$x # p256_mul_by_2(tmp0, S);
2135 `&load_for_sqr("$M(%rsp)", "$src0")`
2137 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(res_x, M);
2139 lea $tmp0(%rsp), $b_ptr
2140 mov $acc6, $acc0 # harmonize sqr output and sub input
2144 call __ecp_nistz256_sub_from$x # p256_sub(res_x, res_x, tmp0);
2146 mov $S+8*0(%rsp), $t0
2147 mov $S+8*1(%rsp), $t1
2148 mov $S+8*2(%rsp), $t2
2149 mov $S+8*3(%rsp), $acc2 # "4-5-0-1" order
2150 lea $S(%rsp), $r_ptr
2151 call __ecp_nistz256_sub$x # p256_sub(S, S, res_x);
2154 lea $M(%rsp), $b_ptr
2155 mov $acc4, $acc6 # harmonize sub output and mul input
2157 mov $acc4, $S+8*0(%rsp) # have to save:-(
2159 mov $acc5, $S+8*1(%rsp)
2161 mov $acc0, $S+8*2(%rsp)
2162 lea $S-$bias(%rsp), $a_ptr
2164 mov $acc1, $S+8*3(%rsp)
2166 lea $S(%rsp), $r_ptr
2167 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S, S, M);
2171 call __ecp_nistz256_sub_from$x # p256_sub(res_y, S, res_y);
2181 .size ecp_nistz256_point_double$sfx,.-ecp_nistz256_point_double$sfx
2188 my ($src0,$sfx,$bias);
2189 my ($H,$Hsqr,$R,$Rsqr,$Hcub,
2191 $res_x,$res_y,$res_z,
2192 $in1_x,$in1_y,$in1_z,
2193 $in2_x,$in2_y,$in2_z)=map(32*$_,(0..17));
2194 my ($Z1sqr, $Z2sqr) = ($Hsqr, $Rsqr);
2202 .globl ecp_nistz256_point_add
2203 .type ecp_nistz256_point_add,\@function,3
2205 ecp_nistz256_point_add:
2207 $code.=<<___ if ($addx);
2209 and OPENSSL_ia32cap_P+8(%rip), %ecx
2219 .type ecp_nistz256_point_addx,\@function,3
2221 ecp_nistz256_point_addx:
2234 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$a_ptr
2235 movdqu 0x10($a_ptr), %xmm1
2236 movdqu 0x20($a_ptr), %xmm2
2237 movdqu 0x30($a_ptr), %xmm3
2238 movdqu 0x40($a_ptr), %xmm4
2239 movdqu 0x50($a_ptr), %xmm5
2240 mov $a_ptr, $b_ptr # reassign
2241 mov $b_org, $a_ptr # reassign
2242 movdqa %xmm0, $in1_x(%rsp)
2243 movdqa %xmm1, $in1_x+0x10(%rsp)
2245 movdqa %xmm2, $in1_y(%rsp)
2246 movdqa %xmm3, $in1_y+0x10(%rsp)
2248 movdqa %xmm4, $in1_z(%rsp)
2249 movdqa %xmm5, $in1_z+0x10(%rsp)
2252 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$b_ptr
2253 pshufd \$0xb1, %xmm3, %xmm5
2254 movdqu 0x10($a_ptr), %xmm1
2255 movdqu 0x20($a_ptr), %xmm2
2257 movdqu 0x30($a_ptr), %xmm3
2258 mov 0x40+8*0($a_ptr), $src0 # load original in2_z
2259 mov 0x40+8*1($a_ptr), $acc6
2260 mov 0x40+8*2($a_ptr), $acc7
2261 mov 0x40+8*3($a_ptr), $acc0
2262 movdqa %xmm0, $in2_x(%rsp)
2263 pshufd \$0x1e, %xmm5, %xmm4
2264 movdqa %xmm1, $in2_x+0x10(%rsp)
2266 movq $r_ptr, %xmm0 # save $r_ptr
2267 movdqa %xmm2, $in2_y(%rsp)
2268 movdqa %xmm3, $in2_y+0x10(%rsp)
2274 lea 0x40-$bias($a_ptr), $a_ptr # $a_ptr is still valid
2275 mov $src0, $in2_z+8*0(%rsp) # make in2_z copy
2276 mov $acc6, $in2_z+8*1(%rsp)
2277 mov $acc7, $in2_z+8*2(%rsp)
2278 mov $acc0, $in2_z+8*3(%rsp)
2279 lea $Z2sqr(%rsp), $r_ptr # Z2^2
2280 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Z2sqr, in2_z);
2282 pcmpeqd %xmm4, %xmm5
2283 pshufd \$0xb1, %xmm3, %xmm4
2285 pshufd \$0, %xmm5, %xmm5 # in1infty
2286 pshufd \$0x1e, %xmm4, %xmm3
2289 pcmpeqd %xmm3, %xmm4
2290 pshufd \$0, %xmm4, %xmm4 # in2infty
2291 mov 0x40+8*0($b_ptr), $src0 # load original in1_z
2292 mov 0x40+8*1($b_ptr), $acc6
2293 mov 0x40+8*2($b_ptr), $acc7
2294 mov 0x40+8*3($b_ptr), $acc0
2297 lea 0x40-$bias($b_ptr), $a_ptr
2298 lea $Z1sqr(%rsp), $r_ptr # Z1^2
2299 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Z1sqr, in1_z);
2301 `&load_for_mul("$Z2sqr(%rsp)", "$in2_z(%rsp)", "$src0")`
2302 lea $S1(%rsp), $r_ptr # S1 = Z2^3
2303 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S1, Z2sqr, in2_z);
2305 `&load_for_mul("$Z1sqr(%rsp)", "$in1_z(%rsp)", "$src0")`
2306 lea $S2(%rsp), $r_ptr # S2 = Z1^3
2307 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, Z1sqr, in1_z);
2309 `&load_for_mul("$S1(%rsp)", "$in1_y(%rsp)", "$src0")`
2310 lea $S1(%rsp), $r_ptr # S1 = Y1*Z2^3
2311 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S1, S1, in1_y);
2313 `&load_for_mul("$S2(%rsp)", "$in2_y(%rsp)", "$src0")`
2314 lea $S2(%rsp), $r_ptr # S2 = Y2*Z1^3
2315 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, S2, in2_y);
2317 lea $S1(%rsp), $b_ptr
2318 lea $R(%rsp), $r_ptr # R = S2 - S1
2319 call __ecp_nistz256_sub_from$x # p256_sub(R, S2, S1);
2321 or $acc5, $acc4 # see if result is zero
2325 por %xmm5, %xmm2 # in1infty || in2infty
2328 `&load_for_mul("$Z2sqr(%rsp)", "$in1_x(%rsp)", "$src0")`
2329 lea $U1(%rsp), $r_ptr # U1 = X1*Z2^2
2330 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U1, in1_x, Z2sqr);
2332 `&load_for_mul("$Z1sqr(%rsp)", "$in2_x(%rsp)", "$src0")`
2333 lea $U2(%rsp), $r_ptr # U2 = X2*Z1^2
2334 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, in2_x, Z1sqr);
2336 lea $U1(%rsp), $b_ptr
2337 lea $H(%rsp), $r_ptr # H = U2 - U1
2338 call __ecp_nistz256_sub_from$x # p256_sub(H, U2, U1);
2340 or $acc5, $acc4 # see if result is zero
2344 .byte 0x3e # predict taken
2345 jnz .Ladd_proceed$x # is_equal(U1,U2)?
2349 jnz .Ladd_proceed$x # (in1infty || in2infty)?
2351 jz .Ladd_double$x # is_equal(S1,S2)?
2353 movq %xmm0, $r_ptr # restore $r_ptr
2355 movdqu %xmm0, 0x00($r_ptr)
2356 movdqu %xmm0, 0x10($r_ptr)
2357 movdqu %xmm0, 0x20($r_ptr)
2358 movdqu %xmm0, 0x30($r_ptr)
2359 movdqu %xmm0, 0x40($r_ptr)
2360 movdqu %xmm0, 0x50($r_ptr)
2365 movq %xmm1, $a_ptr # restore $a_ptr
2366 movq %xmm0, $r_ptr # restore $r_ptr
2367 add \$`32*(18-5)`, %rsp # difference in frame sizes
2368 jmp .Lpoint_double_shortcut$x
2372 `&load_for_sqr("$R(%rsp)", "$src0")`
2373 lea $Rsqr(%rsp), $r_ptr # R^2
2374 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Rsqr, R);
2376 `&load_for_mul("$H(%rsp)", "$in1_z(%rsp)", "$src0")`
2377 lea $res_z(%rsp), $r_ptr # Z3 = H*Z1*Z2
2378 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, H, in1_z);
2380 `&load_for_sqr("$H(%rsp)", "$src0")`
2381 lea $Hsqr(%rsp), $r_ptr # H^2
2382 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Hsqr, H);
2384 `&load_for_mul("$res_z(%rsp)", "$in2_z(%rsp)", "$src0")`
2385 lea $res_z(%rsp), $r_ptr # Z3 = H*Z1*Z2
2386 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, res_z, in2_z);
2388 `&load_for_mul("$Hsqr(%rsp)", "$H(%rsp)", "$src0")`
2389 lea $Hcub(%rsp), $r_ptr # H^3
2390 call __ecp_nistz256_mul_mont$x # p256_mul_mont(Hcub, Hsqr, H);
2392 `&load_for_mul("$Hsqr(%rsp)", "$U1(%rsp)", "$src0")`
2393 lea $U2(%rsp), $r_ptr # U1*H^2
2394 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, U1, Hsqr);
2397 #######################################################################
2398 # operate in 4-5-0-1 "name space" that matches multiplication output
2400 my ($acc0,$acc1,$acc2,$acc3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
2401 my ($poly1, $poly3)=($acc6,$acc7);
2404 #lea $U2(%rsp), $a_ptr
2405 #lea $Hsqr(%rsp), $r_ptr # 2*U1*H^2
2406 #call __ecp_nistz256_mul_by_2 # ecp_nistz256_mul_by_2(Hsqr, U2);
2408 add $acc0, $acc0 # a0:a3+a0:a3
2409 lea $Rsqr(%rsp), $a_ptr
2426 mov 8*0($a_ptr), $t0
2428 mov 8*1($a_ptr), $t1
2430 mov 8*2($a_ptr), $t2
2432 mov 8*3($a_ptr), $t3
2434 call __ecp_nistz256_sub$x # p256_sub(res_x, Rsqr, Hsqr);
2436 lea $Hcub(%rsp), $b_ptr
2437 lea $res_x(%rsp), $r_ptr
2438 call __ecp_nistz256_sub_from$x # p256_sub(res_x, res_x, Hcub);
2440 mov $U2+8*0(%rsp), $t0
2441 mov $U2+8*1(%rsp), $t1
2442 mov $U2+8*2(%rsp), $t2
2443 mov $U2+8*3(%rsp), $t3
2444 lea $res_y(%rsp), $r_ptr
2446 call __ecp_nistz256_sub$x # p256_sub(res_y, U2, res_x);
2448 mov $acc0, 8*0($r_ptr) # save the result, as
2449 mov $acc1, 8*1($r_ptr) # __ecp_nistz256_sub doesn't
2450 mov $acc2, 8*2($r_ptr)
2451 mov $acc3, 8*3($r_ptr)
2455 `&load_for_mul("$S1(%rsp)", "$Hcub(%rsp)", "$src0")`
2456 lea $S2(%rsp), $r_ptr
2457 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, S1, Hcub);
2459 `&load_for_mul("$R(%rsp)", "$res_y(%rsp)", "$src0")`
2460 lea $res_y(%rsp), $r_ptr
2461 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_y, R, res_y);
2463 lea $S2(%rsp), $b_ptr
2464 lea $res_y(%rsp), $r_ptr
2465 call __ecp_nistz256_sub_from$x # p256_sub(res_y, res_y, S2);
2467 movq %xmm0, $r_ptr # restore $r_ptr
2469 movdqa %xmm5, %xmm0 # copy_conditional(res_z, in2_z, in1infty);
2471 pandn $res_z(%rsp), %xmm0
2473 pandn $res_z+0x10(%rsp), %xmm1
2475 pand $in2_z(%rsp), %xmm2
2476 pand $in2_z+0x10(%rsp), %xmm3
2480 movdqa %xmm4, %xmm0 # copy_conditional(res_z, in1_z, in2infty);
2486 pand $in1_z(%rsp), %xmm2
2487 pand $in1_z+0x10(%rsp), %xmm3
2490 movdqu %xmm2, 0x40($r_ptr)
2491 movdqu %xmm3, 0x50($r_ptr)
2493 movdqa %xmm5, %xmm0 # copy_conditional(res_x, in2_x, in1infty);
2495 pandn $res_x(%rsp), %xmm0
2497 pandn $res_x+0x10(%rsp), %xmm1
2499 pand $in2_x(%rsp), %xmm2
2500 pand $in2_x+0x10(%rsp), %xmm3
2504 movdqa %xmm4, %xmm0 # copy_conditional(res_x, in1_x, in2infty);
2510 pand $in1_x(%rsp), %xmm2
2511 pand $in1_x+0x10(%rsp), %xmm3
2514 movdqu %xmm2, 0x00($r_ptr)
2515 movdqu %xmm3, 0x10($r_ptr)
2517 movdqa %xmm5, %xmm0 # copy_conditional(res_y, in2_y, in1infty);
2519 pandn $res_y(%rsp), %xmm0
2521 pandn $res_y+0x10(%rsp), %xmm1
2523 pand $in2_y(%rsp), %xmm2
2524 pand $in2_y+0x10(%rsp), %xmm3
2528 movdqa %xmm4, %xmm0 # copy_conditional(res_y, in1_y, in2infty);
2534 pand $in1_y(%rsp), %xmm2
2535 pand $in1_y+0x10(%rsp), %xmm3
2538 movdqu %xmm2, 0x20($r_ptr)
2539 movdqu %xmm3, 0x30($r_ptr)
2550 .size ecp_nistz256_point_add$sfx,.-ecp_nistz256_point_add$sfx
2555 sub gen_add_affine () {
2557 my ($src0,$sfx,$bias);
2558 my ($U2,$S2,$H,$R,$Hsqr,$Hcub,$Rsqr,
2559 $res_x,$res_y,$res_z,
2560 $in1_x,$in1_y,$in1_z,
2561 $in2_x,$in2_y)=map(32*$_,(0..14));
2570 .globl ecp_nistz256_point_add_affine
2571 .type ecp_nistz256_point_add_affine,\@function,3
2573 ecp_nistz256_point_add_affine:
2575 $code.=<<___ if ($addx);
2577 and OPENSSL_ia32cap_P+8(%rip), %ecx
2579 je .Lpoint_add_affinex
2587 .type ecp_nistz256_point_add_affinex,\@function,3
2589 ecp_nistz256_point_add_affinex:
2590 .Lpoint_add_affinex:
2602 movdqu 0x00($a_ptr), %xmm0 # copy *(P256_POINT *)$a_ptr
2603 mov $b_org, $b_ptr # reassign
2604 movdqu 0x10($a_ptr), %xmm1
2605 movdqu 0x20($a_ptr), %xmm2
2606 movdqu 0x30($a_ptr), %xmm3
2607 movdqu 0x40($a_ptr), %xmm4
2608 movdqu 0x50($a_ptr), %xmm5
2609 mov 0x40+8*0($a_ptr), $src0 # load original in1_z
2610 mov 0x40+8*1($a_ptr), $acc6
2611 mov 0x40+8*2($a_ptr), $acc7
2612 mov 0x40+8*3($a_ptr), $acc0
2613 movdqa %xmm0, $in1_x(%rsp)
2614 movdqa %xmm1, $in1_x+0x10(%rsp)
2616 movdqa %xmm2, $in1_y(%rsp)
2617 movdqa %xmm3, $in1_y+0x10(%rsp)
2619 movdqa %xmm4, $in1_z(%rsp)
2620 movdqa %xmm5, $in1_z+0x10(%rsp)
2623 movdqu 0x00($b_ptr), %xmm0 # copy *(P256_POINT_AFFINE *)$b_ptr
2624 pshufd \$0xb1, %xmm3, %xmm5
2625 movdqu 0x10($b_ptr), %xmm1
2626 movdqu 0x20($b_ptr), %xmm2
2628 movdqu 0x30($b_ptr), %xmm3
2629 movdqa %xmm0, $in2_x(%rsp)
2630 pshufd \$0x1e, %xmm5, %xmm4
2631 movdqa %xmm1, $in2_x+0x10(%rsp)
2633 movq $r_ptr, %xmm0 # save $r_ptr
2634 movdqa %xmm2, $in2_y(%rsp)
2635 movdqa %xmm3, $in2_y+0x10(%rsp)
2641 lea 0x40-$bias($a_ptr), $a_ptr # $a_ptr is still valid
2642 lea $Z1sqr(%rsp), $r_ptr # Z1^2
2643 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Z1sqr, in1_z);
2645 pcmpeqd %xmm4, %xmm5
2646 pshufd \$0xb1, %xmm3, %xmm4
2647 mov 0x00($b_ptr), $src0 # $b_ptr is still valid
2648 #lea 0x00($b_ptr), $b_ptr
2649 mov $acc4, $acc1 # harmonize sqr output and mul input
2651 pshufd \$0, %xmm5, %xmm5 # in1infty
2652 pshufd \$0x1e, %xmm4, %xmm3
2657 pcmpeqd %xmm3, %xmm4
2658 pshufd \$0, %xmm4, %xmm4 # in2infty
2660 lea $Z1sqr-$bias(%rsp), $a_ptr
2662 lea $U2(%rsp), $r_ptr # U2 = X2*Z1^2
2663 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, Z1sqr, in2_x);
2665 lea $in1_x(%rsp), $b_ptr
2666 lea $H(%rsp), $r_ptr # H = U2 - U1
2667 call __ecp_nistz256_sub_from$x # p256_sub(H, U2, in1_x);
2669 `&load_for_mul("$Z1sqr(%rsp)", "$in1_z(%rsp)", "$src0")`
2670 lea $S2(%rsp), $r_ptr # S2 = Z1^3
2671 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, Z1sqr, in1_z);
2673 `&load_for_mul("$H(%rsp)", "$in1_z(%rsp)", "$src0")`
2674 lea $res_z(%rsp), $r_ptr # Z3 = H*Z1*Z2
2675 call __ecp_nistz256_mul_mont$x # p256_mul_mont(res_z, H, in1_z);
2677 `&load_for_mul("$S2(%rsp)", "$in2_y(%rsp)", "$src0")`
2678 lea $S2(%rsp), $r_ptr # S2 = Y2*Z1^3
2679 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, S2, in2_y);
2681 lea $in1_y(%rsp), $b_ptr
2682 lea $R(%rsp), $r_ptr # R = S2 - S1
2683 call __ecp_nistz256_sub_from$x # p256_sub(R, S2, in1_y);
2685 `&load_for_sqr("$H(%rsp)", "$src0")`
2686 lea $Hsqr(%rsp), $r_ptr # H^2
2687 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Hsqr, H);
2689 `&load_for_sqr("$R(%rsp)", "$src0")`
2690 lea $Rsqr(%rsp), $r_ptr # R^2
2691 call __ecp_nistz256_sqr_mont$x # p256_sqr_mont(Rsqr, R);
2693 `&load_for_mul("$H(%rsp)", "$Hsqr(%rsp)", "$src0")`
2694 lea $Hcub(%rsp), $r_ptr # H^3
2695 call __ecp_nistz256_mul_mont$x # p256_mul_mont(Hcub, Hsqr, H);
2697 `&load_for_mul("$Hsqr(%rsp)", "$in1_x(%rsp)", "$src0")`
2698 lea $U2(%rsp), $r_ptr # U1*H^2
2699 call __ecp_nistz256_mul_mont$x # p256_mul_mont(U2, in1_x, Hsqr);
2702 #######################################################################
2703 # operate in 4-5-0-1 "name space" that matches multiplication output
2705 my ($acc0,$acc1,$acc2,$acc3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
2706 my ($poly1, $poly3)=($acc6,$acc7);
2709 #lea $U2(%rsp), $a_ptr
2710 #lea $Hsqr(%rsp), $r_ptr # 2*U1*H^2
2711 #call __ecp_nistz256_mul_by_2 # ecp_nistz256_mul_by_2(Hsqr, U2);
2713 add $acc0, $acc0 # a0:a3+a0:a3
2714 lea $Rsqr(%rsp), $a_ptr
2731 mov 8*0($a_ptr), $t0
2733 mov 8*1($a_ptr), $t1
2735 mov 8*2($a_ptr), $t2
2737 mov 8*3($a_ptr), $t3
2739 call __ecp_nistz256_sub$x # p256_sub(res_x, Rsqr, Hsqr);
2741 lea $Hcub(%rsp), $b_ptr
2742 lea $res_x(%rsp), $r_ptr
2743 call __ecp_nistz256_sub_from$x # p256_sub(res_x, res_x, Hcub);
2745 mov $U2+8*0(%rsp), $t0
2746 mov $U2+8*1(%rsp), $t1
2747 mov $U2+8*2(%rsp), $t2
2748 mov $U2+8*3(%rsp), $t3
2749 lea $H(%rsp), $r_ptr
2751 call __ecp_nistz256_sub$x # p256_sub(H, U2, res_x);
2753 mov $acc0, 8*0($r_ptr) # save the result, as
2754 mov $acc1, 8*1($r_ptr) # __ecp_nistz256_sub doesn't
2755 mov $acc2, 8*2($r_ptr)
2756 mov $acc3, 8*3($r_ptr)
2760 `&load_for_mul("$Hcub(%rsp)", "$in1_y(%rsp)", "$src0")`
2761 lea $S2(%rsp), $r_ptr
2762 call __ecp_nistz256_mul_mont$x # p256_mul_mont(S2, Hcub, in1_y);
2764 `&load_for_mul("$H(%rsp)", "$R(%rsp)", "$src0")`
2765 lea $H(%rsp), $r_ptr
2766 call __ecp_nistz256_mul_mont$x # p256_mul_mont(H, H, R);
2768 lea $S2(%rsp), $b_ptr
2769 lea $res_y(%rsp), $r_ptr
2770 call __ecp_nistz256_sub_from$x # p256_sub(res_y, H, S2);
2772 movq %xmm0, $r_ptr # restore $r_ptr
2774 movdqa %xmm5, %xmm0 # copy_conditional(res_z, ONE, in1infty);
2776 pandn $res_z(%rsp), %xmm0
2778 pandn $res_z+0x10(%rsp), %xmm1
2780 pand .LONE_mont(%rip), %xmm2
2781 pand .LONE_mont+0x10(%rip), %xmm3
2785 movdqa %xmm4, %xmm0 # copy_conditional(res_z, in1_z, in2infty);
2791 pand $in1_z(%rsp), %xmm2
2792 pand $in1_z+0x10(%rsp), %xmm3
2795 movdqu %xmm2, 0x40($r_ptr)
2796 movdqu %xmm3, 0x50($r_ptr)
2798 movdqa %xmm5, %xmm0 # copy_conditional(res_x, in2_x, in1infty);
2800 pandn $res_x(%rsp), %xmm0
2802 pandn $res_x+0x10(%rsp), %xmm1
2804 pand $in2_x(%rsp), %xmm2
2805 pand $in2_x+0x10(%rsp), %xmm3
2809 movdqa %xmm4, %xmm0 # copy_conditional(res_x, in1_x, in2infty);
2815 pand $in1_x(%rsp), %xmm2
2816 pand $in1_x+0x10(%rsp), %xmm3
2819 movdqu %xmm2, 0x00($r_ptr)
2820 movdqu %xmm3, 0x10($r_ptr)
2822 movdqa %xmm5, %xmm0 # copy_conditional(res_y, in2_y, in1infty);
2824 pandn $res_y(%rsp), %xmm0
2826 pandn $res_y+0x10(%rsp), %xmm1
2828 pand $in2_y(%rsp), %xmm2
2829 pand $in2_y+0x10(%rsp), %xmm3
2833 movdqa %xmm4, %xmm0 # copy_conditional(res_y, in1_y, in2infty);
2839 pand $in1_y(%rsp), %xmm2
2840 pand $in1_y+0x10(%rsp), %xmm3
2843 movdqu %xmm2, 0x20($r_ptr)
2844 movdqu %xmm3, 0x30($r_ptr)
2854 .size ecp_nistz256_point_add_affine$sfx,.-ecp_nistz256_point_add_affine$sfx
2857 &gen_add_affine("q");
2859 ########################################################################
2863 ########################################################################
2864 # operate in 4-5-0-1 "name space" that matches multiplication output
2866 my ($a0,$a1,$a2,$a3,$t3,$t4)=($acc4,$acc5,$acc0,$acc1,$acc2,$acc3);
2869 .type __ecp_nistz256_add_tox,\@abi-omnipotent
2871 __ecp_nistz256_add_tox:
2873 adc 8*0($b_ptr), $a0
2874 adc 8*1($b_ptr), $a1
2876 adc 8*2($b_ptr), $a2
2877 adc 8*3($b_ptr), $a3
2892 mov $a0, 8*0($r_ptr)
2894 mov $a1, 8*1($r_ptr)
2896 mov $a2, 8*2($r_ptr)
2897 mov $a3, 8*3($r_ptr)
2900 .size __ecp_nistz256_add_tox,.-__ecp_nistz256_add_tox
2902 .type __ecp_nistz256_sub_fromx,\@abi-omnipotent
2904 __ecp_nistz256_sub_fromx:
2906 sbb 8*0($b_ptr), $a0
2907 sbb 8*1($b_ptr), $a1
2909 sbb 8*2($b_ptr), $a2
2910 sbb 8*3($b_ptr), $a3
2925 mov $a0, 8*0($r_ptr)
2927 mov $a1, 8*1($r_ptr)
2929 mov $a2, 8*2($r_ptr)
2930 mov $a3, 8*3($r_ptr)
2933 .size __ecp_nistz256_sub_fromx,.-__ecp_nistz256_sub_fromx
2935 .type __ecp_nistz256_subx,\@abi-omnipotent
2937 __ecp_nistz256_subx:
2962 .size __ecp_nistz256_subx,.-__ecp_nistz256_subx
2964 .type __ecp_nistz256_mul_by_2x,\@abi-omnipotent
2966 __ecp_nistz256_mul_by_2x:
2968 adc $a0, $a0 # a0:a3+a0:a3
2987 mov $a0, 8*0($r_ptr)
2989 mov $a1, 8*1($r_ptr)
2991 mov $a2, 8*2($r_ptr)
2992 mov $a3, 8*3($r_ptr)
2995 .size __ecp_nistz256_mul_by_2x,.-__ecp_nistz256_mul_by_2x
3000 &gen_add_affine("x");
3004 $code =~ s/\`([^\`]*)\`/eval $1/gem;