1 /* Function cos vectorized with SSE4.
2 Copyright (C) 2014-2019 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_d_trig_data.h"
23 ENTRY (_ZGVbN2v_cos_sse4)
24 /* ALGORITHM DESCRIPTION:
26 ( low accuracy ( < 4ulp ) or enhanced performance
27 ( half of correct mantissa ) implementation )
29 Argument representation:
30 arg + Pi/2 = (N*Pi + R)
33 cos(arg) = sin(arg+Pi/2) = sin(N*Pi + R) = (-1)^N * sin(R)
34 sin(R) is approximated by corresponding polynomial
37 cfi_adjust_cfa_offset (8)
38 cfi_rel_offset (%rbp, 0)
40 cfi_def_cfa_register (%rbp)
44 movq __svml_d_trig_data@GOTPCREL(%rip), %rax
45 movups __dHalfPI(%rax), %xmm2
47 /* ARGUMENT RANGE REDUCTION:
48 Add Pi/2 to argument: X' = X+Pi/2
51 movups __dInvPI(%rax), %xmm5
52 movups __dAbsMask(%rax), %xmm4
54 /* Get absolute argument value: X' = |X'| */
57 /* Y = X'*InvPi + RS : right shifter add */
60 /* Check for large arguments path */
61 cmpnlepd __dRangeVal(%rax), %xmm4
62 movups __dRShifter(%rax), %xmm6
66 /* N = Y - RS : right shifter sub */
69 /* SignRes = Y<<63 : shift LSB to MSB place for result sign */
74 subpd __dOneHalf(%rax), %xmm1
75 movups __dPI1(%rax), %xmm7
79 movups __dPI2(%rax), %xmm4
84 movups __dPI3(%rax), %xmm5
91 movups __dPI4(%rax), %xmm6
96 /* POLYNOMIAL APPROXIMATION: R2 = R*R */
99 movups __dC7(%rax), %xmm1
101 addpd __dC6(%rax), %xmm1
103 addpd __dC5(%rax), %xmm1
105 addpd __dC4(%rax), %xmm1
107 /* Poly = C3+R2*(C4+R2*(C5+R2*(C6+R2*C7))) */
109 addpd __dC3(%rax), %xmm1
111 /* Poly = R+R*(R2*(C1+R2*(C2+R2*Poly))) */
113 addpd __dC2(%rax), %xmm1
115 addpd __dC1(%rax), %xmm1
121 Final sign setting: Res = Poly^SignRes */
129 cfi_def_cfa_register (%rsp)
131 cfi_adjust_cfa_offset (-8)
137 movups %xmm3, 192(%rsp)
138 movups %xmm0, 256(%rsp)
143 movups %xmm8, 112(%rsp)
144 movups %xmm9, 96(%rsp)
145 movups %xmm10, 80(%rsp)
146 movups %xmm11, 64(%rsp)
147 movups %xmm12, 48(%rsp)
148 movups %xmm13, 32(%rsp)
149 movups %xmm14, 16(%rsp)
150 movups %xmm15, (%rsp)
154 cfi_offset_rel_rsp (12, 168)
157 cfi_offset_rel_rsp (13, 160)
160 cfi_offset_rel_rsp (14, 152)
163 cfi_offset_rel_rsp (15, 144)
181 movups 112(%rsp), %xmm8
182 movups 96(%rsp), %xmm9
183 movups 80(%rsp), %xmm10
184 movups 64(%rsp), %xmm11
185 movups 48(%rsp), %xmm12
186 movups 32(%rsp), %xmm13
187 movups 16(%rsp), %xmm14
188 movups (%rsp), %xmm15
199 movups 256(%rsp), %xmm0
206 movsd 200(%rsp,%r15), %xmm0
210 movsd %xmm0, 264(%rsp,%r15)
216 movsd 192(%rsp,%r15), %xmm0
220 movsd %xmm0, 256(%rsp,%r15)
223 END (_ZGVbN2v_cos_sse4)