1 /* Function pow vectorized with SSE4.
2 Copyright (C) 2014-2023 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_pow_data.h"
22 .section .text.sse4, "ax", @progbits
23 ENTRY (_ZGVbN2vv_pow_sse4)
25 ALGORITHM DESCRIPTION:
27 1) Calculating log2|x|
28 Here we use the following formula.
29 Let |x|=2^k1*X1, where k1 is integer, 1<=X1<2.
31 Rcp1 ~= 1/X1, X2=Rcp1*X1,
32 Rcp2 ~= 1/X2, X3=Rcp2*X2,
33 Rcp3 ~= 1/X3, Rcp3C ~= C/X3.
35 log2|x| = k1 + log2(1/Rcp1) + log2(1/Rcp2) + log2(C/Rcp3C) +
36 log2(X1*Rcp1*Rcp2*Rcp3C/C),
37 where X1*Rcp1*Rcp2*Rcp3C = C*(1+q), q is very small.
39 The values of Rcp1, log2(1/Rcp1), Rcp2, log2(1/Rcp2),
40 Rcp3C, log2(C/Rcp3C) are taken from tables.
41 Values of Rcp1, Rcp2, Rcp3C are such that RcpC=Rcp1*Rcp2*Rcp3C
42 is exactly represented in target precision.
44 log2(X1*Rcp1*Rcp2*Rcp3C/C) = log2(1+q) = ln(1+q)/ln2 =
45 = 1/(ln2)*q - 1/(2ln2)*q^2 + 1/(3ln2)*q^3 - ... =
46 = 1/(C*ln2)*cq - 1/(2*C^2*ln2)*cq^2 + 1/(3*C^3*ln2)*cq^3 - ... =
47 = (1 + a1)*cq + a2*cq^2 + a3*cq^3 + ...,
48 where cq = X1*Rcp1*Rcp2*Rcp3C-C,
49 a1=1/(C*ln(2))-1 is small,
53 We get 3 parts of log2 result: HH+HL+HLL ~= log2|x|.
55 2) Calculation of y*(HH+HL+HLL).
57 Get high PH and medium PL parts of y*log2|x|.
58 Get low PLL part of y*log2|x|.
59 Now we have PH+PL+PLL ~= y*log2|x|.
61 3) Calculation of 2^(PH+PL+PLL).
62 Mathematical idea of computing 2^(PH+PL+PLL) is the following.
63 Let's represent PH+PL+PLL in the form N + j/2^expK + Z,
64 where expK=7 in this implementation, N and j are integers,
65 0<=j<=2^expK-1, |Z|<2^(-expK-1).
66 Hence 2^(PH+PL+PLL) ~= 2^N * 2^(j/2^expK) * 2^Z,
67 where 2^(j/2^expK) is stored in a table, and
68 2^Z ~= 1 + B1*Z + B2*Z^2 ... + B5*Z^5.
70 We compute 2^(PH+PL+PLL) as follows.
71 Break PH into PHH + PHL, where PHH = N + j/2^expK.
73 Exp2Poly = B1*Z + B2*Z^2 ... + B5*Z^5
74 Get 2^(j/2^expK) from table in the form THI+TLO.
75 Now we have 2^(PH+PL+PLL) ~= 2^N * (THI + TLO) * (1 + Exp2Poly).
77 Get significand of 2^(PH+PL+PLL) in the form ResHi+ResLo:
79 ResLo := THI * Exp2Poly + TLO
81 Get exponent ERes of the result:
83 Result := ex(Res) + N. */
86 cfi_adjust_cfa_offset (8)
87 cfi_rel_offset (%rbp, 0)
89 cfi_def_cfa_register (%rbp)
92 movq __svml_dpow_data@GOTPCREL(%rip), %rdx
93 movups %xmm14, 80(%rsp)
94 movups %xmm9, 176(%rsp)
96 pshufd $221, %xmm0, %xmm1
97 movq _iIndexMask(%rdx), %xmm14
98 movq _iIndexAdd(%rdx), %xmm6
100 /* i = (((Hi(x) & 0x000ffe00) + 0x00000200) >> 10); -> i = (b1..b11 + 1) / 2 */
104 movups %xmm13, 96(%rsp)
106 /* Index for reciprocal table */
107 movdqa %xmm14, %xmm13
110 /* Index for log2 table */
113 movups %xmm10, 160(%rsp)
114 movups _iMantissaMask(%rdx), %xmm10
117 /* x1 = x; Hi(x1) = (Hi(x1)&0x000fffff)|0x3ff00000 */
119 pextrd $1, %xmm13, %ecx
124 /* k = Hi(x); k = k - 0x3fe7fe00; k = k >> 20 */
125 movq _i3fe7fe00(%rdx), %xmm6
127 movups _iHighMask(%rdx), %xmm6
129 movups %xmm15, 48(%rsp)
130 movups %xmm12, 112(%rsp)
131 orps _dbOne(%rdx), %xmm10
132 movsd 11712(%rdx,%rax), %xmm12
134 movq _i2p20_2p19(%rdx), %xmm15
135 movhpd 11712(%rdx,%rcx), %xmm12
137 pextrd $1, %xmm14, %r9d
139 /* x1Hi=x1; Lo(x1Hi)&=0xf8000000; x1Lo = x1-x1Hi */
142 movaps %xmm10, %xmm15
148 /* E = -r1+__fence(x1Hi*rcp1) */
154 pshufd $80, %xmm0, %xmm0
156 andps _iffffffff00000000(%rdx), %xmm0
157 subpd _db2p20_2p19(%rdx), %xmm0
161 /* T_Rh_Eh = T_Rh + E */
162 movaps %xmm14, %xmm15
163 movups %xmm8, 208(%rsp)
164 movups 19968(%rdx,%r8), %xmm8
165 movups %xmm11, 144(%rsp)
169 movups _LHN(%rdx), %xmm13
170 movhpd 19968(%rdx,%r9), %xmm11
177 movaps %xmm13, %xmm12
181 /* Rl = T-T_Rh; -> -Rh */
184 /* HLL = T_Rh - T_Rh_Eh; -> -Eh */
198 unpckhpd 19968(%rdx,%r9), %xmm8
200 /* T_Rh_Eh_HLLhi = T_Rh_Eh + HLL */
201 movaps %xmm15, %xmm14
205 movups _clv_2(%rdx), %xmm11
207 /* HH = T_Rh_Eh_HLLhi; Lo(HH)&=0xf8000000 */
210 /* HLL = HLL + (((((((a7)*cq+a6)*cq+a5)*cq+a4)*cq+a3)*cq+a2)*cq+a1)*cq */
212 addpd _clv_3(%rdx), %xmm11
214 addpd _clv_4(%rdx), %xmm11
216 addpd _clv_5(%rdx), %xmm11
218 addpd _clv_6(%rdx), %xmm11
220 addpd _clv_7(%rdx), %xmm11
226 2^(y*(HH+HL+HLL)) starts here:
227 yH = y; Lo(yH)&=0xf8000000
236 /* HLLhi = T_Rh_Eh_HLLhi - T_Rh_Eh */
237 movaps %xmm14, %xmm10
239 /* HL = T_Rh_Eh_HLLhi-HH; */
242 movq _HIDELTA(%rdx), %xmm2
246 movq _LORANGE(%rdx), %xmm3
250 /* pL=yL*HL+yH*HL; pL+=yL*HH; */
258 /* HLL = HLL - HLLhi */
264 movups _db2p45_2p44(%rdx), %xmm11
266 /* pHH = pH + *(double*)&db2p45_2p44 */
267 movaps %xmm11, %xmm12
270 /* t=pL+pLL; t+=pHL */
272 movq _ABSMASK(%rdx), %xmm5
273 pshufd $221, %xmm9, %xmm4
275 movq _INF(%rdx), %xmm7
279 pshufd $136, %xmm12, %xmm7
282 /* pHH = pHH - *(double*)&db2p45_2p44 */
284 pshufd $221, %xmm13, %xmm10
287 /* pHL = pH - pHH; */
290 movq _DOMAINRANGE(%rdx), %xmm5
294 pcmpeqd %xmm5, %xmm10
296 movq _jIndexMask(%rdx), %xmm6
300 /* j = Lo(pHH)&0x0000007f */
302 movq _iOne(%rdx), %xmm3
305 _n = _n & 0xffffff80;
307 Hi(_2n) = (0x3ff+_n)<<20; Lo(_2n) = 0; -> 2^n
312 movups _cev_1(%rdx), %xmm3
316 /* T1 = ((double*)exp2_tbl)[ 2*j ] */
318 pshufd $80, %xmm7, %xmm0
319 andps _ifff0000000000000(%rdx), %xmm0
320 addpd _cev_2(%rdx), %xmm3
322 addpd _cev_3(%rdx), %xmm3
326 pextrd $1, %xmm6, %r11d
328 addpd _cev_4(%rdx), %xmm3
329 movsd 36416(%rdx,%r10), %xmm2
330 movhpd 36416(%rdx,%r11), %xmm2
334 addpd _cev_5(%rdx), %xmm13
341 movups 208(%rsp), %xmm8
342 movups 176(%rsp), %xmm9
343 movups 160(%rsp), %xmm10
344 movups 144(%rsp), %xmm11
345 movups 112(%rsp), %xmm12
346 movups 96(%rsp), %xmm13
347 movups 80(%rsp), %xmm14
348 movups 48(%rsp), %xmm15
350 cfi_def_cfa_register (%rsp)
352 cfi_adjust_cfa_offset (-8)
359 movups %xmm1, 64(%rsp)
360 movups %xmm9, 128(%rsp)
361 movups %xmm0, 192(%rsp)
369 cfi_offset_rel_rsp (12, 40)
372 cfi_offset_rel_rsp (13, 32)
375 cfi_offset_rel_rsp (14, 24)
378 cfi_offset_rel_rsp (15, 16)
406 movups 192(%rsp), %xmm0
413 movsd 72(%rsp,%r15), %xmm0
414 movsd 136(%rsp,%r15), %xmm1
418 movsd %xmm0, 200(%rsp,%r15)
424 movsd 64(%rsp,%r15), %xmm0
425 movsd 128(%rsp,%r15), %xmm1
429 movsd %xmm0, 192(%rsp,%r15)
432 END (_ZGVbN2vv_pow_sse4)