1 /* Function sincosf vectorized with AVX2.
2 Copyright (C) 2014-2024 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 #include "svml_s_trig_data.h"
22 .section .text.avx2, "ax", @progbits
23 ENTRY (_ZGVdN8vl4l4_sincosf_avx2)
25 ALGORITHM DESCRIPTION:
27 1) Range reduction to [-Pi/4; +Pi/4] interval
28 a) Grab sign from source argument and save it.
29 b) Remove sign using AND operation
30 c) Getting octant Y by 2/Pi multiplication
31 d) Add "Right Shifter" value
32 e) Treat obtained value as integer S for destination sign setting.
33 SS = ((S-S&1)&2)<<30; For sin part
34 SC = ((S+S&1)&2)<<30; For cos part
35 f) Change destination sign if source sign is negative
37 g) Subtract "Right Shifter" (0x4B000000) value
38 h) Subtract Y*(PI/2) from X argument, where PI/2 divided to 4 parts:
39 X = X - Y*PI1 - Y*PI2 - Y*PI3 - Y*PI4;
40 2) Polynomial (minimax for sin within [-Pi/4; +Pi/4] interval)
41 a) Calculate X^2 = X * X
42 b) Calculate 2 polynomials for sin and cos:
43 RS = X * ( A0 + X^2 * (A1 + x^2 * (A2 + x^2 * (A3))));
44 RC = B0 + X^2 * (B1 + x^2 * (B2 + x^2 * (B3 + x^2 * (B4))));
45 c) Swap RS & RC if first bit of obtained value after
46 Right Shifting is set to 1. Using And, Andnot & Or operations.
47 3) Destination sign setting
48 a) Set shifted destination sign using XOR operation:
50 R2 = XOR( RC, SC ). */
53 cfi_adjust_cfa_offset (8)
54 cfi_rel_offset (%rbp, 0)
56 cfi_def_cfa_register (%rbp)
59 movq __svml_s_trig_data@GOTPCREL(%rip), %rax
61 vmovups %ymm13, 352(%rsp)
62 vmovups __sAbsMask(%rax), %ymm2
63 vmovups __sInvPI(%rax), %ymm1
64 vmovups __sPI1_FMA(%rax), %ymm13
65 vmovups %ymm15, 288(%rsp)
67 /* Absolute argument computation */
68 vandps %ymm2, %ymm5, %ymm4
70 /* c) Getting octant Y by 2/Pi multiplication
71 d) Add "Right Shifter" value */
72 vfmadd213ps __sRShifter(%rax), %ymm4, %ymm1
74 /* e) Treat obtained value as integer S for destination sign setting */
75 vpslld $31, %ymm1, %ymm0
77 /* g) Subtract "Right Shifter" (0x4B000000) value */
78 vsubps __sRShifter(%rax), %ymm1, %ymm1
80 /* h) Subtract Y*(PI/2) from X argument, where PI/2 divided to 3 parts:
81 X = X - Y*PI1 - Y*PI2 - Y*PI3 */
83 vfnmadd231ps %ymm1, %ymm13, %ymm7
84 vfnmadd231ps __sPI2_FMA(%rax), %ymm1, %ymm7
85 vandps __sSignMask(%rax), %ymm7, %ymm15
86 vxorps __sOneHalf(%rax), %ymm15, %ymm6
88 /* Add correction term 0.5 for cos() part */
89 vaddps %ymm6, %ymm1, %ymm6
91 vfnmadd231ps %ymm6, %ymm13, %ymm3
92 vmovups __sPI3_FMA(%rax), %ymm13
93 vcmpnle_uqps __sRangeReductionVal(%rax), %ymm4, %ymm4
94 vfnmadd231ps __sPI2_FMA(%rax), %ymm6, %ymm3
95 vfnmadd213ps %ymm7, %ymm13, %ymm1
96 vfnmadd213ps %ymm3, %ymm13, %ymm6
98 /* Result sign calculations */
99 vxorps __sSignMask(%rax), %ymm15, %ymm3
100 vxorps %ymm0, %ymm3, %ymm7
101 vxorps %ymm7, %ymm6, %ymm3
102 vxorps %ymm0, %ymm1, %ymm15
103 vandnps %ymm5, %ymm2, %ymm6
104 vmovups __sA7_FMA(%rax), %ymm2
105 vmulps %ymm15, %ymm15, %ymm13
106 vmovups __sA9_FMA(%rax), %ymm7
107 vmulps %ymm3, %ymm3, %ymm1
109 /* 2) Polynomial (minimax for sin within [-Pi/4; +Pi/4] interval)
110 a) Calculate X^2 = X * X
111 b) Calculate 2 polynomials for sin and cos:
112 RS = X * ( A0 + X^2 * (A1 + x^2 * (A2 + x^2 * (A3))));
113 RC = B0 + X^2 * (B1 + x^2 * (B2 + x^2 * (B3 + x^2 * (B4)))) */
115 vfmadd231ps __sA9_FMA(%rax), %ymm13, %ymm0
116 vfmadd213ps %ymm2, %ymm1, %ymm7
117 vfmadd213ps __sA5_FMA(%rax), %ymm13, %ymm0
118 vfmadd213ps __sA5_FMA(%rax), %ymm1, %ymm7
119 vfmadd213ps __sA3(%rax), %ymm13, %ymm0
120 vfmadd213ps __sA3(%rax), %ymm1, %ymm7
121 vmulps %ymm13, %ymm0, %ymm13
122 vmulps %ymm1, %ymm7, %ymm1
123 vfmadd213ps %ymm15, %ymm15, %ymm13
124 vfmadd213ps %ymm3, %ymm3, %ymm1
125 vmovmskps %ymm4, %ecx
126 vxorps %ymm6, %ymm13, %ymm0
132 vmovups 352(%rsp), %ymm13
133 vmovups 288(%rsp), %ymm15
134 vmovups %ymm0, (%rdi)
135 vmovups %ymm1, (%rsi)
137 cfi_def_cfa_register (%rsp)
139 cfi_adjust_cfa_offset (-8)
145 vmovups %ymm5, 256(%rsp)
146 vmovups %ymm0, 320(%rsp)
147 vmovups %ymm1, 384(%rsp)
152 vmovups %ymm8, 160(%rsp)
153 vmovups %ymm9, 128(%rsp)
154 vmovups %ymm10, 96(%rsp)
155 vmovups %ymm11, 64(%rsp)
156 vmovups %ymm12, 32(%rsp)
157 vmovups %ymm14, (%rsp)
160 cfi_offset_rel_rsp (12, 232)
163 cfi_offset_rel_rsp (13, 224)
166 cfi_offset_rel_rsp (14, 216)
169 cfi_offset_rel_rsp (14, 208)
189 vmovups 160(%rsp), %ymm8
191 vmovups 128(%rsp), %ymm9
192 vmovups 96(%rsp), %ymm10
193 vmovups 64(%rsp), %ymm11
194 vmovups 32(%rsp), %ymm12
195 vmovups (%rsp), %ymm14
196 vmovups 320(%rsp), %ymm0
197 vmovups 384(%rsp), %ymm1
213 vmovss 260(%rsp,%r15,8), %xmm0
216 call JUMPTARGET(sinf)
218 vmovss %xmm0, 324(%rsp,%r15,8)
219 vmovss 260(%rsp,%r15,8), %xmm0
221 call JUMPTARGET(cosf)
223 vmovss %xmm0, 388(%rsp,%r15,8)
228 vmovss 256(%rsp,%r15,8), %xmm0
231 call JUMPTARGET(sinf)
233 vmovss %xmm0, 320(%rsp,%r15,8)
234 vmovss 256(%rsp,%r15,8), %xmm0
236 call JUMPTARGET(cosf)
238 vmovss %xmm0, 384(%rsp,%r15,8)
241 END (_ZGVdN8vl4l4_sincosf_avx2)
242 libmvec_hidden_def(_ZGVdN8vl4l4_sincosf_avx2)
244 /* vvv version implemented with wrapper to vl4l4 variant. */
245 ENTRY (_ZGVdN8vvv_sincosf_avx2)
248 cfi_adjust_cfa_offset (8)
249 cfi_rel_offset (%rbp, 0)
251 cfi_def_cfa_register (%rbp)
254 vmovdqu %ymm1, 64(%rsp)
256 vmovdqu %ymm2, 96(%rdi)
257 vmovdqu %ymm3, 128(%rdi)
258 vmovdqu %ymm4, 160(%rdi)
260 call HIDDEN_JUMPTARGET(_ZGVdN8vl4l4_sincosf_avx2)
310 cfi_def_cfa_register (%rsp)
312 cfi_adjust_cfa_offset (-8)
321 .cfi_escape 0x10,0x6,0x2,0x76,0
324 .cfi_escape 0xf,0x3,0x76,0x78,0x6
328 vmovdqa %ymm1, -112(%ebp)
329 vmovdqa %ymm2, -144(%ebp)
330 call HIDDEN_JUMPTARGET(_ZGVdN8vl4l4_sincosf_avx2)
331 vmovdqa -112(%ebp), %xmm0
333 vmovss -80(%ebp), %xmm0
335 vmovss -76(%ebp), %xmm0
338 movq -104(%ebp), %rax
339 vmovss -72(%ebp), %xmm0
341 vmovss -68(%ebp), %xmm0
345 vmovss -64(%ebp), %xmm0
347 vmovss -60(%ebp), %xmm0
351 vmovss -56(%ebp), %xmm0
353 vmovss -52(%ebp), %xmm0
356 vmovdqa -144(%ebp), %xmm0
358 vmovss -48(%ebp), %xmm0
360 vmovss -44(%ebp), %xmm0
363 movq -136(%ebp), %rax
364 vmovss -40(%ebp), %xmm0
366 vmovss -36(%ebp), %xmm0
369 movq -128(%ebp), %rax
370 vmovss -32(%ebp), %xmm0
372 vmovss -28(%ebp), %xmm0
375 movq -120(%ebp), %rax
376 vmovss -24(%ebp), %xmm0
378 vmovss -20(%ebp), %xmm0
389 END (_ZGVdN8vvv_sincosf_avx2)