1 /* Function atan2 vectorized with SSE4.
2 Copyright (C) 2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 https://www.gnu.org/licenses/. */
20 * ALGORITHM DESCRIPTION:
21 * For 0.0 <= x <= 7.0/16.0: atan(x) = atan(0.0) + atan(s), where s=(x-0.0)/(1.0+0.0*x)
22 * For 7.0/16.0 <= x <= 11.0/16.0: atan(x) = atan(0.5) + atan(s), where s=(x-0.5)/(1.0+0.5*x)
23 * For 11.0/16.0 <= x <= 19.0/16.0: atan(x) = atan(1.0) + atan(s), where s=(x-1.0)/(1.0+1.0*x)
24 * For 19.0/16.0 <= x <= 39.0/16.0: atan(x) = atan(1.5) + atan(s), where s=(x-1.5)/(1.0+1.5*x)
25 * For 39.0/16.0 <= x <= inf : atan(x) = atan(inf) + atan(s), where s=-1.0/x
26 * Where atan(s) ~= s+s^3*Poly11(s^2) on interval |s|<7.0/0.16.
31 /* Offsets for data table __svml_datan2_data_internal
55 #define dSIGN_MASK 352
56 #define iCHK_WORK_SUB 368
57 #define iCHK_WORK_CMP 384
64 .section .text.sse4,"ax",@progbits
65 ENTRY(_ZGVbN2vv_atan2_sse4)
67 cfi_def_cfa_offset(96)
71 * #define NO_VECTOR_ZERO_ATAN2_ARGS
75 * The end of declarations
78 * Cannot be replaced by VQRCP(D, dR0, dB);
79 * Argument Absolute values
81 movups dABS_MASK+__svml_datan2_data_internal(%rip), %xmm4
90 movups dSIGN_MASK+__svml_datan2_data_internal(%rip), %xmm3
92 movups dPIO2+__svml_datan2_data_internal(%rip), %xmm5
97 * 1) If y<x then a= y, b=x, PIO2=0
98 * 2) If y>x then a=-x, b=y, PIO2=Pi/2
110 movq iCHK_WORK_SUB+__svml_datan2_data_internal(%rip), %xmm11
112 /* if x<0, dPI = Pi, else dPI =0 */
115 /* Check if y and x are on main path. */
116 pshufd $221, %xmm1, %xmm12
120 movq iCHK_WORK_CMP+__svml_datan2_data_internal(%rip), %xmm13
122 movups %xmm4, 16(%rsp)
124 pshufd $221, %xmm4, %xmm14
126 pcmpgtd %xmm13, %xmm4
127 pcmpeqd %xmm13, %xmm12
133 cmplepd dZERO+__svml_datan2_data_internal(%rip), %xmm3
135 movdqa %xmm14, %xmm15
136 pcmpeqd %xmm13, %xmm14
137 pcmpgtd %xmm13, %xmm15
139 movaps %xmm12, %xmm14
142 movaps %xmm14, %xmm15
145 movups %xmm10, (%rsp)
146 movups dA19+__svml_datan2_data_internal(%rip), %xmm10
148 movups dA18+__svml_datan2_data_internal(%rip), %xmm13
149 movups dA17+__svml_datan2_data_internal(%rip), %xmm11
150 addpd dA15+__svml_datan2_data_internal(%rip), %xmm10
154 addpd dA14+__svml_datan2_data_internal(%rip), %xmm13
155 addpd dA13+__svml_datan2_data_internal(%rip), %xmm11
156 addpd dA11+__svml_datan2_data_internal(%rip), %xmm10
160 addpd dA10+__svml_datan2_data_internal(%rip), %xmm13
161 addpd dA09+__svml_datan2_data_internal(%rip), %xmm11
162 addpd dA07+__svml_datan2_data_internal(%rip), %xmm10
166 addpd dA06+__svml_datan2_data_internal(%rip), %xmm13
167 addpd dA05+__svml_datan2_data_internal(%rip), %xmm11
168 addpd dA03+__svml_datan2_data_internal(%rip), %xmm10
172 addpd dA02+__svml_datan2_data_internal(%rip), %xmm13
173 addpd dA01+__svml_datan2_data_internal(%rip), %xmm11
177 movups dA16+__svml_datan2_data_internal(%rip), %xmm2
179 addpd dA12+__svml_datan2_data_internal(%rip), %xmm2
181 addpd dA08+__svml_datan2_data_internal(%rip), %xmm2
183 addpd dA04+__svml_datan2_data_internal(%rip), %xmm2
185 /* A00=1.0, account for it later VQFMA(D, dP4, dP4, dR8, dA00); */
192 * dP=(R+R*dP) + dPIO2
197 andps __svml_datan2_data_internal(%rip), %xmm3
201 /* Special branch for fast (vector) processing of zero arguments */
202 movups 16(%rsp), %xmm11
206 /* Go to auxilary branch */
208 # LOE rbx rbp r12 r13 r14 r15 eax edx xmm0 xmm1 xmm3 xmm4 xmm5 xmm6 xmm7 xmm8 xmm9 xmm11
210 /* Return from auxilary branch
211 * for out of main path inputs
214 L(AUX_BRANCH_RETURN):
216 * Special branch for fast (vector) processing of zero arguments
217 * The end of implementation
221 /* Go to special inputs processing branch */
222 jne L(SPECIAL_VALUES_BRANCH)
223 # LOE rbx rbp r12 r13 r14 r15 eax edx xmm0 xmm8 xmm9
226 * and exit the function
231 cfi_def_cfa_offset(8)
233 cfi_def_cfa_offset(96)
239 L(SPECIAL_VALUES_BRANCH):
240 movups %xmm8, 32(%rsp)
241 movups %xmm9, 48(%rsp)
242 movups %xmm0, 64(%rsp)
243 # LOE rbx rbp r12 r13 r14 r15 eax edx xmm0
253 # LOE rbx rbp r15 r12d r13d
262 /* Call scalar math function */
263 jc L(SCALAR_MATH_CALL)
264 # LOE rbx rbp r15 r12d r13d
270 L(SPECIAL_VALUES_LOOP):
274 /* Check bits in range mask */
275 jl L(RANGEMASK_CHECK)
276 # LOE rbx rbp r15 r12d r13d
284 movups 64(%rsp), %xmm0
291 # LOE rbx rbp r12 r13 r14 r15 xmm0
293 /* Scalar math fucntion call
294 * to process special input
299 movsd 32(%rsp,%r14,8), %xmm0
300 movsd 48(%rsp,%r14,8), %xmm1
302 # LOE rbx rbp r14 r15 r12d r13d xmm0
304 movsd %xmm0, 64(%rsp,%r14,8)
306 /* Process special inputs in loop */
307 jmp L(SPECIAL_VALUES_LOOP)
311 # LOE rbx rbp r15 r12d r13d
314 * for out of main path inputs
318 /* Check if at least on of Y or Y is zero: iAXAYZERO */
319 movups dZERO+__svml_datan2_data_internal(%rip), %xmm2
321 /* Check if both X & Y are not NaNs: iXYnotNAN */
324 cmpordpd %xmm9, %xmm12
325 cmpordpd %xmm8, %xmm10
327 cmpeqpd %xmm2, %xmm11
330 pshufd $221, %xmm1, %xmm1
331 pshufd $221, %xmm12, %xmm11
333 /* Check if at least on of Y or Y is zero and not NaN: iAXAYZEROnotNAN */
336 /* Exclude from previous callout mask zero (and not NaN) arguments */
341 * Path for zero arguments (at least one of both)
342 * Check if both args are zeros (den. is zero)
348 movmskps %xmm13, %edx
350 /* Set sPIO2 to zero if den. is zero */
356 pshufd $221, %xmm9, %xmm5
359 /* Res = sign(Y)*(X<0)?(PIO2+PI):PIO2 */
360 pshufd $221, %xmm2, %xmm7
362 pshufd $80, %xmm7, %xmm14
366 /* Merge results from main and spec path */
367 pshufd $80, %xmm1, %xmm3
375 /* Return to main vector processing path */
376 jmp L(AUX_BRANCH_RETURN)
377 # LOE rbx rbp r12 r13 r14 r15 eax edx xmm0 xmm8 xmm9
378 END(_ZGVbN2vv_atan2_sse4)
380 .section .rodata, "a"
383 #ifdef __svml_datan2_data_internal_typedef
384 typedef unsigned int VUINT32;
386 __declspec(align(16)) VUINT32 dPI[2][2];
387 __declspec(align(16)) VUINT32 dPIO2[2][2];
388 __declspec(align(16)) VUINT32 dA19[2][2];
389 __declspec(align(16)) VUINT32 dA18[2][2];
390 __declspec(align(16)) VUINT32 dA17[2][2];
391 __declspec(align(16)) VUINT32 dA16[2][2];
392 __declspec(align(16)) VUINT32 dA15[2][2];
393 __declspec(align(16)) VUINT32 dA14[2][2];
394 __declspec(align(16)) VUINT32 dA13[2][2];
395 __declspec(align(16)) VUINT32 dA12[2][2];
396 __declspec(align(16)) VUINT32 dA11[2][2];
397 __declspec(align(16)) VUINT32 dA10[2][2];
398 __declspec(align(16)) VUINT32 dA09[2][2];
399 __declspec(align(16)) VUINT32 dA08[2][2];
400 __declspec(align(16)) VUINT32 dA07[2][2];
401 __declspec(align(16)) VUINT32 dA06[2][2];
402 __declspec(align(16)) VUINT32 dA05[2][2];
403 __declspec(align(16)) VUINT32 dA04[2][2];
404 __declspec(align(16)) VUINT32 dA03[2][2];
405 __declspec(align(16)) VUINT32 dA02[2][2];
406 __declspec(align(16)) VUINT32 dA01[2][2];
407 __declspec(align(16)) VUINT32 dA00[2][2];
408 __declspec(align(16)) VUINT32 dSIGN_MASK[2][2];
409 __declspec(align(16)) VUINT32 iCHK_WORK_SUB[4][1];
410 __declspec(align(16)) VUINT32 iCHK_WORK_CMP[4][1];
411 __declspec(align(16)) VUINT32 dABS_MASK[2][2];
412 __declspec(align(16)) VUINT32 dZERO[2][2];
413 } __svml_datan2_data_internal;
415 __svml_datan2_data_internal:
416 .quad 0x400921FB54442D18, 0x400921FB54442D18 //dPI
418 .quad 0x3FF921FB54442D18, 0x3FF921FB54442D18 //dPIO2
420 .quad 0xBEF4FDB537ABC7A3, 0xBEF4FDB537ABC7A3 // dA19
422 .quad 0x3F2CED0A36665209, 0x3F2CED0A36665209 // dA18
424 .quad 0xBF52E67C93954C23, 0xBF52E67C93954C23 // dA17
426 .quad 0x3F6F5A1DAE82AFB3, 0x3F6F5A1DAE82AFB3 // dA16
428 .quad 0xBF82B2EC618E4BAD, 0xBF82B2EC618E4BAD // dA15
430 .quad 0x3F914F4C661116A5, 0x3F914F4C661116A5 // dA14
432 .quad 0xBF9A5E83B081F69C, 0xBF9A5E83B081F69C // dA13
434 .quad 0x3FA169980CB6AD4F, 0x3FA169980CB6AD4F // dA12
436 .quad 0xBFA4EFA2E563C1BC, 0xBFA4EFA2E563C1BC // dA11
438 .quad 0x3FA7EC0FBC50683B, 0x3FA7EC0FBC50683B // dA10
440 .quad 0xBFAAD261EAA09954, 0xBFAAD261EAA09954 // dA09
442 .quad 0x3FAE1749BD612DCF, 0x3FAE1749BD612DCF // dA08
444 .quad 0xBFB11084009435E0, 0xBFB11084009435E0 // dA07
446 .quad 0x3FB3B12A49295651, 0x3FB3B12A49295651 // dA06
448 .quad 0xBFB745D009BADA94, 0xBFB745D009BADA94 // dA05
450 .quad 0x3FBC71C707F7D5B5, 0x3FBC71C707F7D5B5 // dA04
452 .quad 0xBFC2492491EE55C7, 0xBFC2492491EE55C7 // dA03
454 .quad 0x3FC999999997EE34, 0x3FC999999997EE34 // dA02
456 .quad 0xBFD55555555553C5, 0xBFD55555555553C5 // dA01
458 .quad 0x3FF0000000000000, 0x3FF0000000000000 // dA00
460 .quad 0x8000000000000000, 0x8000000000000000 //dSIGN_MASK
462 .long 0x80300000, 0x80300000, 0x80300000, 0x80300000 //iCHK_WORK_SUB
464 .long 0xfdd00000, 0xfdd00000, 0xfdd00000, 0xfdd00000 //iCHK_WORK_CMP
466 .quad 0x7fffffffffffffff, 0x7fffffffffffffff //dABS_MASK
468 .quad 0x0000000000000000, 0x0000000000000000 //dZERO
470 .type __svml_datan2_data_internal,@object
471 .size __svml_datan2_data_internal,.-__svml_datan2_data_internal