Debian Codegraph @

debian/rust-vendor/openssl-src/openssl/crypto/bn/asm/rsaz-4k-avxifma.pl

raw
1 # Copyright 2024-2026 The OpenSSL Project Authors. All Rights Reserved.
2 # Copyright (c) 2024, Intel Corporation. All Rights Reserved.
3 #
4 # Licensed under the Apache License 2.0 (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
8 #
9 # Written by Zhiguo Zhou <[email protected]> and Wangyang Guo <[email protected]>.
10 # Special thanks to Tomasz Kantecki <[email protected]> for his valuable suggestions.
11 #
12 # October 2024
13 #
14 # Initial release.
15 #
16
17 # $output is the last argument if it looks like a file (it has an extension)
18 # $flavour is the first argument if it doesn't look like a file
19 $output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
20 $flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
21
22 $win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
23 $avxifma=0;
24
25 $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
26 ( $xlate="${dir}x86_64-xlate.pl" and -f $xlate ) or
27 ( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
28 die "can't locate x86_64-xlate.pl";
29
30 if (`$ENV{CC} -Wa,-v -c -o /dev/null -x assembler /dev/null 2>&1`
31 =~ /GNU assembler version ([2-9]\.[0-9]+)/) {
32 $avxifma = ($1>=2.40);
33 }
34
35 if (!$avxifma && `$ENV{CC} -v 2>&1`
36 =~ /\s*((?:clang|LLVM) version|.*based on LLVM) ([0-9]+)\.([0-9]+)\.([0-9]+)?/) {
37 my $ver = $2 + $3/100.0 + $4/10000.0; # 3.1.0->3.01, 3.10.1->3.1001
38 $avxifma = ($ver>=16.0);
39 }
40
41 if ($win64 && ($flavour =~ /nasm/ || $ENV{ASM} =~ /nasm/) &&
42 `nasm -v 2>&1` =~ /NASM version ([2-9]\.[0-9]+)(?:\.([0-9]+))?(rc[0-9]+)?/) {
43 $avxifma = ($1>2.16) + ($1==2.16 && ((!defined($2) && !defined($3)) || (defined($2))));
44 }
45
46 open OUT,"| \"$^X\" \"$xlate\" $flavour \"$output\""
47 or die "can't call $xlate: $!";
48 *STDOUT=*OUT;
49
50 if ($avxifma>0) {{{
51 @_6_args_universal_ABI = ("%rdi","%rsi","%rdx","%rcx","%r8","%r9");
52
53 ###############################################################################
54 # Almost Montgomery Multiplication (AMM) for 40-digit number in radix 2^52.
55 #
56 # AMM is defined as presented in the paper [1].
57 #
58 # The input and output are presented in 2^52 radix domain, i.e.
59 # |res|, |a|, |b|, |m| are arrays of 40 64-bit qwords with 12 high bits zeroed.
60 # |k0| is a Montgomery coefficient, which is here k0 = -1/m mod 2^64
61 #
62 # NB: the AMM implementation does not perform "conditional" subtraction step
63 # specified in the original algorithm as according to the Lemma 1 from the paper
64 # [2], the result will be always < 2*m and can be used as a direct input to
65 # the next AMM iteration. This post-condition is true, provided the correct
66 # parameter |s| (notion of the Lemma 1 from [2]) is chosen, i.e. s >= n + 2 * k,
67 # which matches our case: 2080 > 2048 + 2 * 1.
68 #
69 # [1] Gueron, S. Efficient software implementations of modular exponentiation.
70 # DOI: 10.1007/s13389-012-0031-5
71 # [2] Gueron, S. Enhanced Montgomery Multiplication.
72 # DOI: 10.1007/3-540-36400-5_5
73 #
74 # void ossl_rsaz_amm52x40_x1_avxifma256(BN_ULONG *res,
75 # const BN_ULONG *a,
76 # const BN_ULONG *b,
77 # const BN_ULONG *m,
78 # BN_ULONG k0);
79 ###############################################################################
80 {
81 # input parameters ("%rdi","%rsi","%rdx","%rcx","%r8")
82 my ($res,$a,$b,$m,$k0) = @_6_args_universal_ABI;
83
84 my $mask52 = "%rax";
85 my $acc0_0 = "%r9";
86 my $acc0_0_low = "%r9d";
87 my $b_ptr = "%r11";
88
89 my $iter = "%ebx";
90
91 my $zero = "%ymm0";
92 my $zero_xmm = "%xmm0";
93 my $Bi = "%ymm1";
94 my $Bi_xmm = "%xmm1";
95 my $Yi = "%ymm2";
96 my $Yi_xmm = "%xmm2";
97 my $tmp = "%ymm13";
98 my $tmp2 = "%ymm14";
99 my ($R0_0,$R0_0h,$R1_0,$R1_0h,$R2_0,$R2_0h,$R3_0,$R3_0h,$R4_0,$R4_0h) = map("%ymm$_",(3..12));
100
101 sub amm52x40_x1() {
102 # _data_offset - offset in the |a| or |m| arrays pointing to the beginning
103 # of data for corresponding AMM operation;
104 # _b_offset - offset in the |b| array pointing to the next qword digit;
105 my ($_data_offset,$_b_offset,$_acc,$_R0,$_R0h,$_R1,$_R1h,$_R2,$_R2h,$_R3,$_R3h,$_R4,$_R4h,$_k0) = @_;
106 $code.=<<___;
107 movq $_b_offset($b_ptr), %r13 # b[i]
108
109 vpbroadcastq $_b_offset($b_ptr),$Bi # broadcast b[i]
110 movq $_data_offset($a), %rdx
111 mulx %r13, %r13, %r12 # a[0]*b[i] = (t0,t2)
112 addq %r13, $_acc # acc += t0
113 movq %r12, %r10
114 adcq \$0, %r10 # t2 += CF
115
116 movq $_k0, %r13
117 imulq $_acc, %r13 # acc * k0
118 andq $mask52, %r13 # yi = (acc * k0) & mask52
119
120 vmovq %r13, $Yi_xmm
121 vpbroadcastq $Yi_xmm, $Yi # broadcast y[i]
122 movq $_data_offset($m), %rdx
123 mulx %r13, %r13, %r12 # yi * m[0] = (t0,t1)
124 addq %r13, $_acc # acc += t0
125 adcq %r12, %r10 # t2 += (t1 + CF)
126
127 shrq \$52, $_acc
128 salq \$12, %r10
129 or %r10, $_acc # acc = ((acc >> 52) | (t2 << 12))
130
131 lea -328(%rsp), %rsp
132
133 {vex} vpmadd52luq `$_data_offset`($a), $Bi, $_R0
134 {vex} vpmadd52luq `$_data_offset+32`($a), $Bi, $_R0h
135 {vex} vpmadd52luq `$_data_offset+64*1`($a), $Bi, $_R1
136 {vex} vpmadd52luq `$_data_offset+64*1+32`($a), $Bi, $_R1h
137 {vex} vpmadd52luq `$_data_offset+64*2`($a), $Bi, $_R2
138 {vex} vpmadd52luq `$_data_offset+64*2+32`($a), $Bi, $_R2h
139 {vex} vpmadd52luq `$_data_offset+64*3`($a), $Bi, $_R3
140 {vex} vpmadd52luq `$_data_offset+64*3+32`($a), $Bi, $_R3h
141 {vex} vpmadd52luq `$_data_offset+64*4`($a), $Bi, $_R4
142 {vex} vpmadd52luq `$_data_offset+64*4+32`($a), $Bi, $_R4h
143
144 {vex} vpmadd52luq `$_data_offset`($m), $Yi, $_R0
145 {vex} vpmadd52luq `$_data_offset+32`($m), $Yi, $_R0h
146 {vex} vpmadd52luq `$_data_offset+64*1`($m), $Yi, $_R1
147 {vex} vpmadd52luq `$_data_offset+64*1+32`($m), $Yi, $_R1h
148 {vex} vpmadd52luq `$_data_offset+64*2`($m), $Yi, $_R2
149 {vex} vpmadd52luq `$_data_offset+64*2+32`($m), $Yi, $_R2h
150 {vex} vpmadd52luq `$_data_offset+64*3`($m), $Yi, $_R3
151 {vex} vpmadd52luq `$_data_offset+64*3+32`($m), $Yi, $_R3h
152 {vex} vpmadd52luq `$_data_offset+64*4`($m), $Yi, $_R4
153 {vex} vpmadd52luq `$_data_offset+64*4+32`($m), $Yi, $_R4h
154 vmovdqu $_R0, `32*0`(%rsp)
155 vmovdqu $_R0h, `32*1`(%rsp)
156 vmovdqu $_R1, `32*2`(%rsp)
157 vmovdqu $_R1h, `32*3`(%rsp)
158 vmovdqu $_R2, `32*4`(%rsp)
159 vmovdqu $_R2h, `32*5`(%rsp)
160 vmovdqu $_R3, `32*6`(%rsp)
161 vmovdqu $_R3h, `32*7`(%rsp)
162 vmovdqu $_R4, `32*8`(%rsp)
163 vmovdqu $_R4h, `32*9`(%rsp)
164 movq \$0, `32*10`(%rsp)
165
166 vmovdqu `32*0 + 8`(%rsp), $_R0
167 vmovdqu `32*1 + 8`(%rsp), $_R0h
168 vmovdqu `32*2 + 8`(%rsp), $_R1
169 vmovdqu `32*3 + 8`(%rsp), $_R1h
170 vmovdqu `32*4 + 8`(%rsp), $_R2
171 vmovdqu `32*5 + 8`(%rsp), $_R2h
172 vmovdqu `32*6 + 8`(%rsp), $_R3
173 vmovdqu `32*7 + 8`(%rsp), $_R3h
174 vmovdqu `32*8 + 8`(%rsp), $_R4
175 vmovdqu `32*9 + 8`(%rsp), $_R4h
176
177 addq 8(%rsp), $_acc # acc += R0[0]
178
179 {vex} vpmadd52huq `$_data_offset`($a), $Bi, $_R0
180 {vex} vpmadd52huq `$_data_offset+32`($a), $Bi, $_R0h
181 {vex} vpmadd52huq `$_data_offset+64*1`($a), $Bi, $_R1
182 {vex} vpmadd52huq `$_data_offset+64*1+32`($a), $Bi, $_R1h
183 {vex} vpmadd52huq `$_data_offset+64*2`($a), $Bi, $_R2
184 {vex} vpmadd52huq `$_data_offset+64*2+32`($a), $Bi, $_R2h
185 {vex} vpmadd52huq `$_data_offset+64*3`($a), $Bi, $_R3
186 {vex} vpmadd52huq `$_data_offset+64*3+32`($a), $Bi, $_R3h
187 {vex} vpmadd52huq `$_data_offset+64*4`($a), $Bi, $_R4
188 {vex} vpmadd52huq `$_data_offset+64*4+32`($a), $Bi, $_R4h
189
190 {vex} vpmadd52huq `$_data_offset`($m), $Yi, $_R0
191 {vex} vpmadd52huq `$_data_offset+32`($m), $Yi, $_R0h
192 {vex} vpmadd52huq `$_data_offset+64*1`($m), $Yi, $_R1
193 {vex} vpmadd52huq `$_data_offset+64*1+32`($m), $Yi, $_R1h
194 {vex} vpmadd52huq `$_data_offset+64*2`($m), $Yi, $_R2
195 {vex} vpmadd52huq `$_data_offset+64*2+32`($m), $Yi, $_R2h
196 {vex} vpmadd52huq `$_data_offset+64*3`($m), $Yi, $_R3
197 {vex} vpmadd52huq `$_data_offset+64*3+32`($m), $Yi, $_R3h
198 {vex} vpmadd52huq `$_data_offset+64*4`($m), $Yi, $_R4
199 {vex} vpmadd52huq `$_data_offset+64*4+32`($m), $Yi, $_R4h
200 lea 328(%rsp),%rsp
201 ___
202 }
203
204 # Normalization routine: handles carry bits and gets bignum qwords to normalized
205 # 2^52 representation.
206 #
207 # Uses %r8-14,%e[abcd]x
208 sub amm52x40_x1_norm {
209 my ($_acc,$_R0,$_R0h,$_R1,$_R1h,$_R2,$_R2h,$_R3,$_R3h,$_R4,$_R4h) = @_;
210 $code.=<<___;
211 # Put accumulator to low qword in R0
212 vmovq $_acc, $zero_xmm
213 vpbroadcastq $zero_xmm, $zero
214 vpblendd \$3, $zero, $_R0, $_R0
215
216 lea -640(%rsp),%rsp
217 vmovupd $_R0, `0*32`(%rsp)
218 vmovupd $_R0h, `1*32`(%rsp)
219 vmovupd $_R1, `2*32`(%rsp)
220 vmovupd $_R1h, `3*32`(%rsp)
221 vmovupd $_R2, `4*32`(%rsp)
222 vmovupd $_R2h, `5*32`(%rsp)
223 vmovupd $_R3, `6*32`(%rsp)
224 vmovupd $_R3h, `7*32`(%rsp)
225 vmovupd $_R4, `8*32`(%rsp)
226 vmovupd $_R4h, `9*32`(%rsp)
227
228 # Extract "carries" (12 high bits) from each QW of the bignum
229 # Save them to LSB of QWs in T0..Tn
230 vpsrlq \$52, $_R0, $_R0
231 vpsrlq \$52, $_R0h, $_R0h
232 vpsrlq \$52, $_R1, $_R1
233 vpsrlq \$52, $_R1h, $_R1h
234 vpsrlq \$52, $_R2, $_R2
235 vpsrlq \$52, $_R2h, $_R2h
236 vpsrlq \$52, $_R3, $_R3
237 vpsrlq \$52, $_R3h, $_R3h
238 vpsrlq \$52, $_R4, $_R4
239 vpsrlq \$52, $_R4h, $_R4h
240
241 # "Shift left" _R0.._Rn by 1 QW
242 vpermq \$144, $_R4h, $_R4h
243 vpermq \$3, $_R4, $tmp
244 vblendpd \$1, $tmp, $_R4h, $_R4h
245
246 vpermq \$144, $_R4, $_R4
247 vpermq \$3, $_R3h, $tmp
248 vblendpd \$1, $tmp, $_R4, $_R4
249
250 vpermq \$144, $_R3h, $_R3h
251 vpermq \$3, $_R3, $tmp
252 vblendpd \$1, $tmp, $_R3h, $_R3h
253
254 vpermq \$144, $_R3, $_R3
255 vpermq \$3, $_R2h, $tmp
256 vblendpd \$1, $tmp, $_R3, $_R3
257
258 vpermq \$144, $_R2h, $_R2h
259 vpermq \$3, $_R2, $tmp
260 vblendpd \$1, $tmp, $_R2h, $_R2h
261
262 vpermq \$144, $_R2, $_R2
263 vpermq \$3, $_R1h, $tmp
264 vblendpd \$1, $tmp, $_R2, $_R2
265
266 vpermq \$144, $_R1h, $_R1h
267 vpermq \$3, $_R1, $tmp
268 vblendpd \$1, $tmp, $_R1h, $_R1h
269
270 vpermq \$144, $_R1, $_R1
271 vpermq \$3, $_R0h, $tmp
272 vblendpd \$1, $tmp, $_R1, $_R1
273
274 vpermq \$144, $_R0h, $_R0h
275 vpermq \$3, $_R0, $tmp
276 vblendpd \$1, $tmp, $_R0h, $_R0h
277
278 vpermq \$144, $_R0, $_R0
279 vpand .Lhigh64x3(%rip), $_R0, $_R0
280
281 vmovupd $_R0, `10*32`(%rsp)
282 vmovupd $_R0h, `11*32`(%rsp)
283 vmovupd $_R1, `12*32`(%rsp)
284 vmovupd $_R1h, `13*32`(%rsp)
285 vmovupd $_R2, `14*32`(%rsp)
286 vmovupd $_R2h, `15*32`(%rsp)
287 vmovupd $_R3, `16*32`(%rsp)
288 vmovupd $_R3h, `17*32`(%rsp)
289 vmovupd $_R4, `18*32`(%rsp)
290 vmovupd $_R4h, `19*32`(%rsp)
291
292 vmovupd `0*32`(%rsp), $_R0
293 vmovupd `1*32`(%rsp), $_R0h
294 vmovupd `2*32`(%rsp), $_R1
295 vmovupd `3*32`(%rsp), $_R1h
296 vmovupd `4*32`(%rsp), $_R2
297 vmovupd `5*32`(%rsp), $_R2h
298 vmovupd `6*32`(%rsp), $_R3
299 vmovupd `7*32`(%rsp), $_R3h
300 vmovupd `8*32`(%rsp), $_R4
301 vmovupd `9*32`(%rsp), $_R4h
302
303 # Drop "carries" from R0..Rn QWs
304 vpand .Lmask52x4(%rip), $_R0, $_R0
305 vpand .Lmask52x4(%rip), $_R0h, $_R0h
306 vpand .Lmask52x4(%rip), $_R1, $_R1
307 vpand .Lmask52x4(%rip), $_R1h, $_R1h
308 vpand .Lmask52x4(%rip), $_R2, $_R2
309 vpand .Lmask52x4(%rip), $_R2h, $_R2h
310 vpand .Lmask52x4(%rip), $_R3, $_R3
311 vpand .Lmask52x4(%rip), $_R3h, $_R3h
312 vpand .Lmask52x4(%rip), $_R4, $_R4
313 vpand .Lmask52x4(%rip), $_R4h, $_R4h
314
315 # Sum R0..Rn with corresponding adjusted carries
316 vpaddq `10*32`(%rsp), $_R0, $_R0
317 vpaddq `11*32`(%rsp), $_R0h, $_R0h
318 vpaddq `12*32`(%rsp), $_R1, $_R1
319 vpaddq `13*32`(%rsp), $_R1h, $_R1h
320 vpaddq `14*32`(%rsp), $_R2, $_R2
321 vpaddq `15*32`(%rsp), $_R2h, $_R2h
322 vpaddq `16*32`(%rsp), $_R3, $_R3
323 vpaddq `17*32`(%rsp), $_R3h, $_R3h
324 vpaddq `18*32`(%rsp), $_R4, $_R4
325 vpaddq `19*32`(%rsp), $_R4h, $_R4h
326
327 lea 640(%rsp),%rsp
328
329 # Now handle carry bits from this addition
330 # Get mask of QWs whose 52-bit parts overflow
331 vpcmpgtq .Lmask52x4(%rip),${_R0},$tmp # OP=nle (i.e. gt)
332 vmovmskpd $tmp,%r14d
333 vpcmpgtq .Lmask52x4(%rip),${_R0h},$tmp
334 vmovmskpd $tmp,%r13d
335 shl \$4,%r13b
336 or %r13b,%r14b
337
338 vpcmpgtq .Lmask52x4(%rip),${_R1},$tmp # OP=nle (i.e. gt)
339 vmovmskpd $tmp,%r13d
340 vpcmpgtq .Lmask52x4(%rip),${_R1h},$tmp
341 vmovmskpd $tmp,%r12d
342 shl \$4,%r12b
343 or %r12b,%r13b
344
345 vpcmpgtq .Lmask52x4(%rip),${_R2},$tmp # OP=nle (i.e. gt)
346 vmovmskpd $tmp,%r12d
347 vpcmpgtq .Lmask52x4(%rip),${_R2h},$tmp
348 vmovmskpd $tmp,%r11d
349 shl \$4,%r11b
350 or %r11b,%r12b
351
352 vpcmpgtq .Lmask52x4(%rip),${_R3},$tmp # OP=nle (i.e. gt)
353 vmovmskpd $tmp,%r11d
354 vpcmpgtq .Lmask52x4(%rip),${_R3h},$tmp
355 vmovmskpd $tmp,%r10d
356 shl \$4,%r10b
357 or %r10b,%r11b
358
359 vpcmpgtq .Lmask52x4(%rip),${_R4},$tmp # OP=nle (i.e. gt)
360 vmovmskpd $tmp,%r10d
361 vpcmpgtq .Lmask52x4(%rip),${_R4h},$tmp
362 vmovmskpd $tmp,%r9d
363 shl \$4,%r9b
364 or %r9b,%r10b
365
366 addb %r14b,%r14b
367 adcb %r13b,%r13b
368 adcb %r12b,%r12b
369 adcb %r11b,%r11b
370 adcb %r10b,%r10b
371
372 # Get mask of QWs whose 52-bit parts saturated
373 vpcmpeqq .Lmask52x4(%rip),${_R0},$tmp # OP=nle (i.e. gt)
374 vmovmskpd $tmp,%r9d
375 vpcmpeqq .Lmask52x4(%rip),${_R0h},$tmp
376 vmovmskpd $tmp,%r8d
377 shl \$4,%r8b
378 or %r8b,%r9b
379
380 vpcmpeqq .Lmask52x4(%rip),${_R1},$tmp # OP=nle (i.e. gt)
381 vmovmskpd $tmp,%r8d
382 vpcmpeqq .Lmask52x4(%rip),${_R1h},$tmp
383 vmovmskpd $tmp,%edx
384 shl \$4,%dl
385 or %dl,%r8b
386
387 vpcmpeqq .Lmask52x4(%rip),${_R2},$tmp # OP=nle (i.e. gt)
388 vmovmskpd $tmp,%edx
389 vpcmpeqq .Lmask52x4(%rip),${_R2h},$tmp
390 vmovmskpd $tmp,%ecx
391 shl \$4,%cl
392 or %cl,%dl
393
394 vpcmpeqq .Lmask52x4(%rip),${_R3},$tmp # OP=nle (i.e. gt)
395 vmovmskpd $tmp,%ecx
396 vpcmpeqq .Lmask52x4(%rip),${_R3h},$tmp
397 vmovmskpd $tmp,%ebx
398 shl \$4,%bl
399 or %bl,%cl
400
401 vpcmpeqq .Lmask52x4(%rip),${_R4},$tmp # OP=nle (i.e. gt)
402 vmovmskpd $tmp,%ebx
403 vpcmpeqq .Lmask52x4(%rip),${_R4h},$tmp
404 vmovmskpd $tmp,%eax
405 shl \$4,%al
406 or %al,%bl
407
408 addb %r9b,%r14b
409 adcb %r8b,%r13b
410 adcb %dl,%r12b
411 adcb %cl,%r11b
412 adcb %bl,%r10b
413
414 xor %r9b,%r14b
415 xor %r8b,%r13b
416 xor %dl,%r12b
417 xor %cl,%r11b
418 xor %bl,%r10b
419
420 push %r9
421 push %r8
422
423 lea .Lkmasklut(%rip), %r8
424
425 movb %r14b,%r9b
426 and \$0xf, %r14
427 vpsubq .Lmask52x4(%rip), $_R0, $tmp
428 shl \$5, %r14
429 vmovapd (%r8,%r14), $tmp2
430 vblendvpd $tmp2, $tmp, $_R0, $_R0
431
432 shr \$4, %r9b
433 and \$0xf, %r9
434 vpsubq .Lmask52x4(%rip), $_R0h, $tmp
435 shl \$5, %r9
436 vmovapd (%r8,%r9), $tmp2
437 vblendvpd $tmp2, $tmp, $_R0h, $_R0h
438
439 movb %r13b,%r9b
440 and \$0xf, %r13
441 vpsubq .Lmask52x4(%rip), $_R1, $tmp
442 shl \$5, %r13
443 vmovapd (%r8,%r13), $tmp2
444 vblendvpd $tmp2, $tmp, $_R1, $_R1
445
446 shr \$4, %r9b
447 and \$0xf, %r9
448 vpsubq .Lmask52x4(%rip), $_R1h, $tmp
449 shl \$5, %r9
450 vmovapd (%r8,%r9), $tmp2
451 vblendvpd $tmp2, $tmp, $_R1h, $_R1h
452
453 movb %r12b,%r9b
454 and \$0xf, %r12
455 vpsubq .Lmask52x4(%rip), $_R2, $tmp
456 shl \$5, %r12
457 vmovapd (%r8,%r12), $tmp2
458 vblendvpd $tmp2, $tmp, $_R2, $_R2
459
460 shr \$4, %r9b
461 and \$0xf, %r9
462 vpsubq .Lmask52x4(%rip), $_R2h, $tmp
463 shl \$5, %r9
464 vmovapd (%r8,%r9), $tmp2
465 vblendvpd $tmp2, $tmp, $_R2h, $_R2h
466
467 movb %r11b,%r9b
468 and \$0xf, %r11
469 vpsubq .Lmask52x4(%rip), $_R3, $tmp
470 shl \$5, %r11
471 vmovapd (%r8,%r11), $tmp2
472 vblendvpd $tmp2, $tmp, $_R3, $_R3
473
474 shr \$4, %r9b
475 and \$0xf, %r9
476 vpsubq .Lmask52x4(%rip), $_R3h, $tmp
477 shl \$5, %r9
478 vmovapd (%r8,%r9), $tmp2
479 vblendvpd $tmp2, $tmp, $_R3h, $_R3h
480
481 movb %r10b,%r9b
482 and \$0xf, %r10
483 vpsubq .Lmask52x4(%rip), $_R4, $tmp
484 shl \$5, %r10
485 vmovapd (%r8,%r10), $tmp2
486 vblendvpd $tmp2, $tmp, $_R4, $_R4
487
488 shr \$4, %r9b
489 and \$0xf, %r9
490 vpsubq .Lmask52x4(%rip), $_R4h, $tmp
491 shl \$5, %r9
492 vmovapd (%r8,%r9), $tmp2
493 vblendvpd $tmp2, $tmp, $_R4h, $_R4h
494
495 pop %r8
496 pop %r9
497
498 vpand .Lmask52x4(%rip), $_R0, $_R0
499 vpand .Lmask52x4(%rip), $_R0h, $_R0h
500 vpand .Lmask52x4(%rip), $_R1, $_R1
501 vpand .Lmask52x4(%rip), $_R1h, $_R1h
502 vpand .Lmask52x4(%rip), $_R2, $_R2
503 vpand .Lmask52x4(%rip), $_R2h, $_R2h
504 vpand .Lmask52x4(%rip), $_R3, $_R3
505
506 vpand .Lmask52x4(%rip), $_R3h, $_R3h
507 vpand .Lmask52x4(%rip), $_R4, $_R4
508 vpand .Lmask52x4(%rip), $_R4h, $_R4h
509 ___
510 }
511
512 $code.=<<___;
513 .text
514
515 .globl ossl_rsaz_amm52x40_x1_avxifma256
516 .type ossl_rsaz_amm52x40_x1_avxifma256,\@function,5
517 .align 32
518 ossl_rsaz_amm52x40_x1_avxifma256:
519 .cfi_startproc
520 endbranch
521 push %rbx
522 .cfi_push %rbx
523 push %rbp
524 .cfi_push %rbp
525 push %r12
526 .cfi_push %r12
527 push %r13
528 .cfi_push %r13
529 push %r14
530 .cfi_push %r14
531 push %r15
532 .cfi_push %r15
533 ___
534 $code.=<<___ if ($win64);
535 lea -168(%rsp),%rsp # 16*10 + (8 bytes to get correct 16-byte SIMD alignment)
536 vmovapd %xmm6, `0*16`(%rsp) # save non-volatile registers
537 vmovapd %xmm7, `1*16`(%rsp)
538 vmovapd %xmm8, `2*16`(%rsp)
539 vmovapd %xmm9, `3*16`(%rsp)
540 vmovapd %xmm10,`4*16`(%rsp)
541 vmovapd %xmm11,`5*16`(%rsp)
542 vmovapd %xmm12,`6*16`(%rsp)
543 vmovapd %xmm13,`7*16`(%rsp)
544 vmovapd %xmm14,`8*16`(%rsp)
545 vmovapd %xmm15,`9*16`(%rsp)
546 .Lossl_rsaz_amm52x40_x1_avxifma256_body:
547 ___
548 $code.=<<___;
549 # Zeroing accumulators
550 vpxor $zero, $zero, $zero
551 vmovapd $zero, $R0_0
552 vmovapd $zero, $R0_0h
553 vmovapd $zero, $R1_0
554 vmovapd $zero, $R1_0h
555 vmovapd $zero, $R2_0
556 vmovapd $zero, $R2_0h
557 vmovapd $zero, $R3_0
558 vmovapd $zero, $R3_0h
559 vmovapd $zero, $R4_0
560 vmovapd $zero, $R4_0h
561
562 xorl $acc0_0_low, $acc0_0_low
563
564 movq $b, $b_ptr # backup address of b
565 movq \$0xfffffffffffff, $mask52 # 52-bit mask
566
567 # Loop over 40 digits unrolled by 4
568 mov \$10, $iter
569
570 .align 32
571 .Lloop10:
572 ___
573 foreach my $idx (0..3) {
574 &amm52x40_x1(0,8*$idx,$acc0_0,$R0_0,$R0_0h,$R1_0,$R1_0h,$R2_0,$R2_0h,$R3_0,$R3_0h,$R4_0,$R4_0h,$k0);
575 }
576 $code.=<<___;
577 lea `4*8`($b_ptr), $b_ptr
578 dec $iter
579 jne .Lloop10
580 ___
581 &amm52x40_x1_norm($acc0_0,$R0_0,$R0_0h,$R1_0,$R1_0h,$R2_0,$R2_0h,$R3_0,$R3_0h,$R4_0,$R4_0h);
582 $code.=<<___;
583
584 vmovdqu $R0_0, `0*32`($res)
585 vmovdqu $R0_0h, `1*32`($res)
586 vmovdqu $R1_0, `2*32`($res)
587 vmovdqu $R1_0h, `3*32`($res)
588 vmovdqu $R2_0, `4*32`($res)
589 vmovdqu $R2_0h, `5*32`($res)
590 vmovdqu $R3_0, `6*32`($res)
591 vmovdqu $R3_0h, `7*32`($res)
592 vmovdqu $R4_0, `8*32`($res)
593 vmovdqu $R4_0h, `9*32`($res)
594
595 vzeroupper
596 lea (%rsp),%rax
597 .cfi_def_cfa_register %rax
598 ___
599 $code.=<<___ if ($win64);
600 vmovapd `0*16`(%rax),%xmm6
601 vmovapd `1*16`(%rax),%xmm7
602 vmovapd `2*16`(%rax),%xmm8
603 vmovapd `3*16`(%rax),%xmm9
604 vmovapd `4*16`(%rax),%xmm10
605 vmovapd `5*16`(%rax),%xmm11
606 vmovapd `6*16`(%rax),%xmm12
607 vmovapd `7*16`(%rax),%xmm13
608 vmovapd `8*16`(%rax),%xmm14
609 vmovapd `9*16`(%rax),%xmm15
610 lea 168(%rsp),%rax
611 ___
612 $code.=<<___;
613 mov 0(%rax),%r15
614 .cfi_restore %r15
615 mov 8(%rax),%r14
616 .cfi_restore %r14
617 mov 16(%rax),%r13
618 .cfi_restore %r13
619 mov 24(%rax),%r12
620 .cfi_restore %r12
621 mov 32(%rax),%rbp
622 .cfi_restore %rbp
623 mov 40(%rax),%rbx
624 .cfi_restore %rbx
625 lea 48(%rax),%rsp # restore rsp
626 .cfi_def_cfa %rsp,8
627 .Lossl_rsaz_amm52x40_x1_avxifma256_epilogue:
628
629 ret
630 .cfi_endproc
631 .size ossl_rsaz_amm52x40_x1_avxifma256, .-ossl_rsaz_amm52x40_x1_avxifma256
632 ___
633
634 $code.=<<___;
635 .section .rodata align=32
636 .align 32
637 .Lmask52x4:
638 .quad 0xfffffffffffff
639 .quad 0xfffffffffffff
640 .quad 0xfffffffffffff
641 .quad 0xfffffffffffff
642 .Lhigh64x3:
643 .quad 0x0
644 .quad 0xffffffffffffffff
645 .quad 0xffffffffffffffff
646 .quad 0xffffffffffffffff
647 .Lkmasklut:
648 #0000
649 .quad 0x0
650 .quad 0x0
651 .quad 0x0
652 .quad 0x0
653 #0001
654 .quad 0xffffffffffffffff
655 .quad 0x0
656 .quad 0x0
657 .quad 0x0
658 #0010
659 .quad 0x0
660 .quad 0xffffffffffffffff
661 .quad 0x0
662 .quad 0x0
663 #0011
664 .quad 0xffffffffffffffff
665 .quad 0xffffffffffffffff
666 .quad 0x0
667 .quad 0x0
668 #0100
669 .quad 0x0
670 .quad 0x0
671 .quad 0xffffffffffffffff
672 .quad 0x0
673 #0101
674 .quad 0xffffffffffffffff
675 .quad 0x0
676 .quad 0xffffffffffffffff
677 .quad 0x0
678 #0110
679 .quad 0x0
680 .quad 0xffffffffffffffff
681 .quad 0xffffffffffffffff
682 .quad 0x0
683 #0111
684 .quad 0xffffffffffffffff
685 .quad 0xffffffffffffffff
686 .quad 0xffffffffffffffff
687 .quad 0x0
688 #1000
689 .quad 0x0
690 .quad 0x0
691 .quad 0x0
692 .quad 0xffffffffffffffff
693 #1001
694 .quad 0xffffffffffffffff
695 .quad 0x0
696 .quad 0x0
697 .quad 0xffffffffffffffff
698 #1010
699 .quad 0x0
700 .quad 0xffffffffffffffff
701 .quad 0x0
702 .quad 0xffffffffffffffff
703 #1011
704 .quad 0xffffffffffffffff
705 .quad 0xffffffffffffffff
706 .quad 0x0
707 .quad 0xffffffffffffffff
708 #1100
709 .quad 0x0
710 .quad 0x0
711 .quad 0xffffffffffffffff
712 .quad 0xffffffffffffffff
713 #1101
714 .quad 0xffffffffffffffff
715 .quad 0x0
716 .quad 0xffffffffffffffff
717 .quad 0xffffffffffffffff
718 #1110
719 .quad 0x0
720 .quad 0xffffffffffffffff
721 .quad 0xffffffffffffffff
722 .quad 0xffffffffffffffff
723 #1111
724 .quad 0xffffffffffffffff
725 .quad 0xffffffffffffffff
726 .quad 0xffffffffffffffff
727 .quad 0xffffffffffffffff
728 ___
729
730 ###############################################################################
731 # Dual Almost Montgomery Multiplication for 40-digit number in radix 2^52
732 #
733 # See description of ossl_rsaz_amm52x40_x1_ifma256() above for details about Almost
734 # Montgomery Multiplication algorithm and function input parameters description.
735 #
736 # This function does two AMMs for two independent inputs, hence dual.
737 #
738 # void ossl_rsaz_amm52x40_x2_avxifma256(BN_ULONG out[2][40],
739 # const BN_ULONG a[2][40],
740 # const BN_ULONG b[2][40],
741 # const BN_ULONG m[2][40],
742 # const BN_ULONG k0[2]);
743 ###############################################################################
744
745 $code.=<<___;
746 .text
747
748 .globl ossl_rsaz_amm52x40_x2_avxifma256
749 .type ossl_rsaz_amm52x40_x2_avxifma256,\@function,5
750 .align 32
751 ossl_rsaz_amm52x40_x2_avxifma256:
752 .cfi_startproc
753 endbranch
754 push %rbx
755 .cfi_push %rbx
756 push %rbp
757 .cfi_push %rbp
758 push %r12
759 .cfi_push %r12
760 push %r13
761 .cfi_push %r13
762 push %r14
763 .cfi_push %r14
764 push %r15
765 .cfi_push %r15
766 ___
767 $code.=<<___ if ($win64);
768 lea -168(%rsp),%rsp
769 vmovapd %xmm6, `0*16`(%rsp) # save non-volatile registers
770 vmovapd %xmm7, `1*16`(%rsp)
771 vmovapd %xmm8, `2*16`(%rsp)
772 vmovapd %xmm9, `3*16`(%rsp)
773 vmovapd %xmm10,`4*16`(%rsp)
774 vmovapd %xmm11,`5*16`(%rsp)
775 vmovapd %xmm12,`6*16`(%rsp)
776 vmovapd %xmm13,`7*16`(%rsp)
777 vmovapd %xmm14,`8*16`(%rsp)
778 vmovapd %xmm15,`9*16`(%rsp)
779 .Lossl_rsaz_amm52x40_x2_avxifma256_body:
780 ___
781 $code.=<<___;
782 # Zeroing accumulators
783 vpxor $zero, $zero, $zero
784 vmovapd $zero, $R0_0
785 vmovapd $zero, $R0_0h
786 vmovapd $zero, $R1_0
787 vmovapd $zero, $R1_0h
788 vmovapd $zero, $R2_0
789 vmovapd $zero, $R2_0h
790 vmovapd $zero, $R3_0
791 vmovapd $zero, $R3_0h
792 vmovapd $zero, $R4_0
793 vmovapd $zero, $R4_0h
794
795 xorl $acc0_0_low, $acc0_0_low
796
797 movq $b, $b_ptr # backup address of b
798 movq \$0xfffffffffffff, $mask52 # 52-bit mask
799
800 mov \$40, $iter
801
802 .align 32
803 .Lloop40:
804 ___
805 &amm52x40_x1( 0, 0,$acc0_0,$R0_0,$R0_0h,$R1_0,$R1_0h,$R2_0,$R2_0h,$R3_0,$R3_0h,$R4_0,$R4_0h,"($k0)");
806 $code.=<<___;
807 lea 8($b_ptr), $b_ptr
808 dec $iter
809 jne .Lloop40
810
811 push $b_ptr
812 push $a
813 push $m
814 push $k0
815 ___
816 &amm52x40_x1_norm($acc0_0,$R0_0,$R0_0h,$R1_0,$R1_0h,$R2_0,$R2_0h,$R3_0,$R3_0h,$R4_0,$R4_0h);
817 $code.=<<___;
818
819 pop $k0
820 pop $m
821 pop $a
822 pop $b_ptr
823
824 vmovdqu $R0_0, `0*32`($res)
825 vmovdqu $R0_0h, `1*32`($res)
826 vmovdqu $R1_0, `2*32`($res)
827 vmovdqu $R1_0h, `3*32`($res)
828 vmovdqu $R2_0, `4*32`($res)
829 vmovdqu $R2_0h, `5*32`($res)
830 vmovdqu $R3_0, `6*32`($res)
831 vmovdqu $R3_0h, `7*32`($res)
832 vmovdqu $R4_0, `8*32`($res)
833 vmovdqu $R4_0h, `9*32`($res)
834
835 xorl $acc0_0_low, $acc0_0_low
836
837 movq \$0xfffffffffffff, $mask52
838
839 mov \$40, $iter
840
841 vpxor $zero, $zero, $zero
842 vmovapd $zero, $R0_0
843 vmovapd $zero, $R0_0h
844 vmovapd $zero, $R1_0
845 vmovapd $zero, $R1_0h
846 vmovapd $zero, $R2_0
847 vmovapd $zero, $R2_0h
848 vmovapd $zero, $R3_0
849 vmovapd $zero, $R3_0h
850 vmovapd $zero, $R4_0
851 vmovapd $zero, $R4_0h
852 .align 32
853 .Lloop40_1:
854 ___
855 # 40*8 = offset of the next dimension in two-dimension array
856 &amm52x40_x1(40*8, 0,$acc0_0,$R0_0,$R0_0h,$R1_0,$R1_0h,$R2_0,$R2_0h,$R3_0,$R3_0h,$R4_0,$R4_0h,"8($k0)");
857 $code.=<<___;
858 lea 8($b_ptr), $b_ptr
859 dec $iter
860 jne .Lloop40_1
861 ___
862 &amm52x40_x1_norm($acc0_0,$R0_0,$R0_0h,$R1_0,$R1_0h,$R2_0,$R2_0h,$R3_0,$R3_0h,$R4_0,$R4_0h);
863 $code.=<<___;
864
865 vmovdqu $R0_0, `10*32`($res)
866 vmovdqu $R0_0h, `11*32`($res)
867 vmovdqu $R1_0, `12*32`($res)
868 vmovdqu $R1_0h, `13*32`($res)
869 vmovdqu $R2_0, `14*32`($res)
870 vmovdqu $R2_0h, `15*32`($res)
871 vmovdqu $R3_0, `16*32`($res)
872 vmovdqu $R3_0h, `17*32`($res)
873 vmovdqu $R4_0, `18*32`($res)
874 vmovdqu $R4_0h, `19*32`($res)
875
876 vzeroupper
877 lea (%rsp),%rax
878 .cfi_def_cfa_register %rax
879 ___
880 $code.=<<___ if ($win64);
881 vmovapd `0*16`(%rax),%xmm6
882 vmovapd `1*16`(%rax),%xmm7
883 vmovapd `2*16`(%rax),%xmm8
884 vmovapd `3*16`(%rax),%xmm9
885 vmovapd `4*16`(%rax),%xmm10
886 vmovapd `5*16`(%rax),%xmm11
887 vmovapd `6*16`(%rax),%xmm12
888 vmovapd `7*16`(%rax),%xmm13
889 vmovapd `8*16`(%rax),%xmm14
890 vmovapd `9*16`(%rax),%xmm15
891 lea 168(%rsp),%rax
892 ___
893 $code.=<<___;
894 mov 0(%rax),%r15
895 .cfi_restore %r15
896 mov 8(%rax),%r14
897 .cfi_restore %r14
898 mov 16(%rax),%r13
899 .cfi_restore %r13
900 mov 24(%rax),%r12
901 .cfi_restore %r12
902 mov 32(%rax),%rbp
903 .cfi_restore %rbp
904 mov 40(%rax),%rbx
905 .cfi_restore %rbx
906 lea 48(%rax),%rsp
907 .cfi_def_cfa %rsp,8
908 .Lossl_rsaz_amm52x40_x2_avxifma256_epilogue:
909 ret
910 .cfi_endproc
911 .size ossl_rsaz_amm52x40_x2_avxifma256, .-ossl_rsaz_amm52x40_x2_avxifma256
912 ___
913 }
914
915 ###############################################################################
916 # Constant time extraction from the precomputed table of powers base^i, where
917 # i = 0..2^EXP_WIN_SIZE-1
918 #
919 # The input |red_table| contains precomputations for two independent base values.
920 # |red_table_idx1| and |red_table_idx2| are corresponding power indexes.
921 #
922 # Extracted value (output) is 2 40 digits numbers in 2^52 radix.
923 #
924 # void ossl_extract_multiplier_2x40_win5_avx(BN_ULONG *red_Y,
925 # const BN_ULONG red_table[1 << EXP_WIN_SIZE][2][40],
926 # int red_table_idx1, int red_table_idx2);
927 #
928 # EXP_WIN_SIZE = 5
929 ###############################################################################
930 {
931 # input parameters
932 my ($out,$red_tbl,$red_tbl_idx1,$red_tbl_idx2)=$win64 ? ("%rcx","%rdx","%r8", "%r9") : # Win64 order
933 ("%rdi","%rsi","%rdx","%rcx"); # Unix order
934
935 my ($t0,$t1,$t2,$t3,$t4,$t5) = map("%ymm$_", (0..5));
936 my ($t6,$t7,$t8,$t9) = map("%ymm$_", (6..9));
937 my ($tmp,$cur_idx,$idx1,$idx2,$ones,$mask) = map("%ymm$_", (10..15));
938 my $tmp_xmm = "%xmm10";
939
940 my @t = ($t0,$t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9);
941 my $t0xmm = $t0;
942 $t0xmm =~ s/%y/%x/;
943
944 sub get_table_value_consttime() {
945 my ($_idx,$_offset) = @_;
946 $code.=<<___;
947 vpxor $cur_idx, $cur_idx, $cur_idx
948 .align 32
949 .Lloop_$_offset:
950 vpcmpeqq $cur_idx, $_idx, $mask # mask of (idx == cur_idx)
951 ___
952 foreach (0..9) {
953 $code.=<<___;
954 vmovdqu `$_offset+${_}*32`($red_tbl), $tmp # load data from red_tbl
955 #vpblendmq $tmp, $t[$_], ${t[$_]}{%k1} # extract data when mask is not zero
956 vblendvpd $mask, $tmp, $t[$_], ${t[$_]} # extract data when mask is not zero
957 ___
958 }
959 $code.=<<___;
960 vpaddq $ones, $cur_idx, $cur_idx # increment cur_idx
961 addq \$`2*40*8`, $red_tbl
962 cmpq $red_tbl, %rax
963 jne .Lloop_$_offset
964 ___
965 }
966
967 $code.=<<___;
968 .text
969
970 .align 32
971 .globl ossl_extract_multiplier_2x40_win5_avx
972 .type ossl_extract_multiplier_2x40_win5_avx,\@abi-omnipotent
973 ossl_extract_multiplier_2x40_win5_avx:
974 .cfi_startproc
975 endbranch
976 ___
977 $code.=<<___ if ($win64);
978 push %rsi # save non-volatile registers
979 push %rdi
980 lea -168(%rsp), %rsp # 16*10 + (8 bytes to get correct 16-byte SIMD alignment)
981 vmovapd %xmm6, `16*0`(%rsp)
982 vmovapd %xmm7, `16*1`(%rsp)
983 vmovapd %xmm8, `16*2`(%rsp)
984 vmovapd %xmm9, `16*3`(%rsp)
985 vmovapd %xmm10, `16*4`(%rsp)
986 vmovapd %xmm11, `16*5`(%rsp)
987 vmovapd %xmm12, `16*6`(%rsp)
988 vmovapd %xmm13, `16*7`(%rsp)
989 vmovapd %xmm14, `16*8`(%rsp)
990 vmovapd %xmm15, `16*9`(%rsp)
991 ___
992 $code.=<<___;
993 vmovapd .Lones(%rip), $ones # broadcast ones
994 vmovq $red_tbl_idx1, $tmp_xmm
995 vpbroadcastq $tmp_xmm, $idx1
996 vmovq $red_tbl_idx2, $tmp_xmm
997 vpbroadcastq $tmp_xmm, $idx2
998 leaq `(1<<5)*2*40*8`($red_tbl), %rax # holds end of the tbl
999
1000 # backup red_tbl address
1001 movq $red_tbl, %r10
1002
1003 # zeroing t0..n, cur_idx
1004 vpxor $t0xmm, $t0xmm, $t0xmm
1005 ___
1006 foreach (1..9) {
1007 $code.="vmovapd $t0, $t[$_] \n";
1008 }
1009
1010 &get_table_value_consttime($idx1, 0);
1011 foreach (0..9) {
1012 $code.="vmovdqu $t[$_], `(0+$_)*32`($out) \n";
1013 }
1014 $code.="movq %r10, $red_tbl \n";
1015 &get_table_value_consttime($idx2, 40*8);
1016 foreach (0..9) {
1017 $code.="vmovdqu $t[$_], `(10+$_)*32`($out) \n";
1018 }
1019 $code.=<<___;
1020 vzeroupper
1021 ___
1022 $code.=<<___ if ($win64);
1023 vmovapd `16*0`(%rsp), %xmm6
1024 vmovapd `16*1`(%rsp), %xmm7
1025 vmovapd `16*2`(%rsp), %xmm8
1026 vmovapd `16*3`(%rsp), %xmm9
1027 vmovapd `16*4`(%rsp), %xmm10
1028 vmovapd `16*5`(%rsp), %xmm11
1029 vmovapd `16*6`(%rsp), %xmm12
1030 vmovapd `16*7`(%rsp), %xmm13
1031 vmovapd `16*8`(%rsp), %xmm14
1032 vmovapd `16*9`(%rsp), %xmm15
1033 lea 168(%rsp), %rsp
1034 pop %rdi
1035 pop %rsi
1036 ___
1037 $code.=<<___;
1038
1039 ret
1040 .cfi_endproc
1041 .size ossl_extract_multiplier_2x40_win5_avx, .-ossl_extract_multiplier_2x40_win5_avx
1042 ___
1043 $code.=<<___;
1044 .section .rodata align=32
1045 .align 32
1046 .Lones:
1047 .quad 1,1,1,1
1048 .Lzeros:
1049 .quad 0,0,0,0
1050 ___
1051 }
1052
1053 if ($win64) {
1054 $rec="%rcx";
1055 $frame="%rdx";
1056 $context="%r8";
1057 $disp="%r9";
1058
1059 $code.=<<___;
1060 .extern __imp_RtlVirtualUnwind
1061 .type rsaz_avx_handler,\@abi-omnipotent
1062 .align 16
1063 rsaz_avx_handler:
1064 push %rsi
1065 push %rdi
1066 push %rbx
1067 push %rbp
1068 push %r12
1069 push %r13
1070 push %r14
1071 push %r15
1072 pushfq
1073 sub \$64,%rsp
1074
1075 mov 120($context),%rax # pull context->Rax
1076 mov 248($context),%rbx # pull context->Rip
1077
1078 mov 8($disp),%rsi # disp->ImageBase
1079 mov 56($disp),%r11 # disp->HandlerData
1080
1081 mov 0(%r11),%r10d # HandlerData[0]
1082 lea (%rsi,%r10),%r10 # prologue label
1083 cmp %r10,%rbx # context->Rip<.Lprologue
1084 jb .Lcommon_seh_tail
1085
1086 mov 4(%r11),%r10d # HandlerData[1]
1087 lea (%rsi,%r10),%r10 # epilogue label
1088 cmp %r10,%rbx # context->Rip>=.Lepilogue
1089 jae .Lcommon_seh_tail
1090
1091 mov 152($context),%rax # pull context->Rsp
1092
1093 lea (%rax),%rsi # %xmm save area
1094 lea 512($context),%rdi # & context.Xmm6
1095 mov \$20,%ecx # 10*sizeof(%xmm0)/sizeof(%rax)
1096 .long 0xa548f3fc # cld; rep movsq
1097
1098 lea `48+168`(%rax),%rax
1099
1100 mov -8(%rax),%rbx
1101 mov -16(%rax),%rbp
1102 mov -24(%rax),%r12
1103 mov -32(%rax),%r13
1104 mov -40(%rax),%r14
1105 mov -48(%rax),%r15
1106 mov %rbx,144($context) # restore context->Rbx
1107 mov %rbp,160($context) # restore context->Rbp
1108 mov %r12,216($context) # restore context->R12
1109 mov %r13,224($context) # restore context->R13
1110 mov %r14,232($context) # restore context->R14
1111 mov %r15,240($context) # restore context->R14
1112
1113 .Lcommon_seh_tail:
1114 mov 8(%rax),%rdi
1115 mov 16(%rax),%rsi
1116 mov %rax,152($context) # restore context->Rsp
1117 mov %rsi,168($context) # restore context->Rsi
1118 mov %rdi,176($context) # restore context->Rdi
1119
1120 mov 40($disp),%rdi # disp->ContextRecord
1121 mov $context,%rsi # context
1122 mov \$154,%ecx # sizeof(CONTEXT)
1123 .long 0xa548f3fc # cld; rep movsq
1124
1125 mov $disp,%rsi
1126 xor %rcx,%rcx # arg1, UNW_FLAG_NHANDLER
1127 mov 8(%rsi),%rdx # arg2, disp->ImageBase
1128 mov 0(%rsi),%r8 # arg3, disp->ControlPc
1129 mov 16(%rsi),%r9 # arg4, disp->FunctionEntry
1130 mov 40(%rsi),%r10 # disp->ContextRecord
1131 lea 56(%rsi),%r11 # &disp->HandlerData
1132 lea 24(%rsi),%r12 # &disp->EstablisherFrame
1133 mov %r10,32(%rsp) # arg5
1134 mov %r11,40(%rsp) # arg6
1135 mov %r12,48(%rsp) # arg7
1136 mov %rcx,56(%rsp) # arg8, (NULL)
1137 call *__imp_RtlVirtualUnwind(%rip)
1138
1139 mov \$1,%eax # ExceptionContinueSearch
1140 add \$64,%rsp
1141 popfq
1142 pop %r15
1143 pop %r14
1144 pop %r13
1145 pop %r12
1146 pop %rbp
1147 pop %rbx
1148 pop %rdi
1149 pop %rsi
1150 ret
1151 .size rsaz_avx_handler,.-rsaz_avx_handler
1152
1153 .section .pdata
1154 .align 4
1155 .rva .LSEH_begin_ossl_rsaz_amm52x40_x1_avxifma256
1156 .rva .LSEH_end_ossl_rsaz_amm52x40_x1_avxifma256
1157 .rva .LSEH_info_ossl_rsaz_amm52x40_x1_avxifma256
1158
1159 .rva .LSEH_begin_ossl_rsaz_amm52x40_x2_avxifma256
1160 .rva .LSEH_end_ossl_rsaz_amm52x40_x2_avxifma256
1161 .rva .LSEH_info_ossl_rsaz_amm52x40_x2_avxifma256
1162
1163 .section .xdata
1164 .align 8
1165 .LSEH_info_ossl_rsaz_amm52x40_x1_avxifma256:
1166 .byte 9,0,0,0
1167 .rva rsaz_avx_handler
1168 .rva .Lossl_rsaz_amm52x40_x1_avxifma256_body,.Lossl_rsaz_amm52x40_x1_avxifma256_epilogue
1169 .LSEH_info_ossl_rsaz_amm52x40_x2_avxifma256:
1170 .byte 9,0,0,0
1171 .rva rsaz_avx_handler
1172 .rva .Lossl_rsaz_amm52x40_x2_avxifma256_body,.Lossl_rsaz_amm52x40_x2_avxifma256_epilogue
1173 ___
1174 }
1175 }}} else {{{ # fallback for old assembler
1176 $code.=<<___;
1177 .text
1178
1179 .globl ossl_rsaz_amm52x40_x1_avxifma256
1180 .globl ossl_rsaz_amm52x40_x2_avxifma256
1181 .globl ossl_extract_multiplier_2x40_win5_avx
1182 .type ossl_rsaz_amm52x40_x1_avxifma256,\@abi-omnipotent
1183 ossl_rsaz_amm52x40_x1_avxifma256:
1184 ossl_rsaz_amm52x40_x2_avxifma256:
1185 ossl_extract_multiplier_2x40_win5_avx:
1186 .byte 0x0f,0x0b # ud2
1187 ret
1188 .size ossl_rsaz_amm52x40_x1_avxifma256, .-ossl_rsaz_amm52x40_x1_avxifma256
1189 ___
1190 }}}
1191
1192 $code =~ s/\`([^\`]*)\`/eval $1/gem;
1193 print $code;
1194 close STDOUT or die "error closing STDOUT: $!";