1 /* Function exp vectorized with AVX2.
2 Copyright (C) 2014-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 #include "svml_d_exp_data.h"
23 ENTRY (_ZGVdN4v_exp_avx2)
25 ALGORITHM DESCRIPTION:
27 Argument representation:
28 N = rint(X*2^k/ln2) = 2^k*M+j
29 X = N*ln2/2^k + r = M*ln2 + ln2*(j/2^k) + r
30 then -ln2/2^(k+1) < r < ln2/2^(k+1)
36 exp(X) = exp(M*ln2 + ln2*(j/2^k) + r)
37 = 2^M * 2^(j/2^k) * exp(r)
38 2^M is calculated by bit manipulation
39 2^(j/2^k) is stored in table
40 exp(r) is approximated by polynomial
42 The table lookup is skipped if k = 0. */
45 cfi_adjust_cfa_offset (8)
46 cfi_rel_offset (%rbp, 0)
48 cfi_def_cfa_register (%rbp)
51 movq __svml_dexp_data@GOTPCREL(%rip), %rax
53 vmovupd __dbInvLn2(%rax), %ymm3
54 vmovupd __dbShifter(%rax), %ymm1
55 vmovupd __lIndexMask(%rax), %ymm4
57 /* dM = X*dbInvLn2+dbShifter, dbInvLn2 = 2^k/Ln2 */
58 vfmadd213pd %ymm1, %ymm2, %ymm3
60 /* iAbsX = (int)(lX>>32), lX = *(longlong*)&X */
61 vextracti128 $1, %ymm2, %xmm5
62 vshufps $221, %xmm5, %xmm2, %xmm6
64 /* iAbsX = iAbsX&iAbsMask */
65 vandps __iAbsMask(%rax), %xmm6, %xmm7
67 /* dN = dM-dbShifter, dN = rint(X*2^k/Ln2) */
68 vsubpd %ymm1, %ymm3, %ymm6
70 /* iRangeMask = (iAbsX>iDomainRange) */
71 vpcmpgtd __iDomainRange(%rax), %xmm7, %xmm0
72 vmovupd __dbLn2hi(%rax), %ymm1
73 vmovupd __dPC0(%rax), %ymm7
75 /* Mask = iRangeMask?1:0, set mask for overflow/underflow */
77 vmovupd __dPC2(%rax), %ymm0
79 /* dR = X - dN*dbLn2hi, dbLn2hi is 52-8-k hi bits of ln2/2^k */
81 vfnmadd231pd %ymm6, %ymm1, %ymm5
83 /* dR = dR - dN*dbLn2lo, dbLn2lo is 40..94 bits of lo part of ln2/2^k */
84 vfnmadd132pd __dbLn2lo(%rax), %ymm5, %ymm6
86 /* exp(r) = b0+r*(b0+r*(b1+r*b2)) */
87 vfmadd213pd __dPC1(%rax), %ymm6, %ymm0
88 vfmadd213pd %ymm7, %ymm6, %ymm0
89 vfmadd213pd %ymm7, %ymm6, %ymm0
91 /* lIndex = (*(longlong*)&dM)&lIndexMask, lIndex is the lower K bits of lM */
92 vandps %ymm4, %ymm3, %ymm1
94 /* table lookup for dT[j] = 2^(j/2^k) */
95 vxorpd %ymm6, %ymm6, %ymm6
96 vpcmpeqd %ymm5, %ymm5, %ymm5
97 vgatherqpd %ymm5, (%rax,%ymm1,8), %ymm6
99 /* lM = (*(longlong*)&dM)&(~lIndexMask) */
100 vpandn %ymm3, %ymm4, %ymm3
102 /* 2^(j/2^k) * exp(r) */
103 vmulpd %ymm0, %ymm6, %ymm0
105 /* lM = lM<<(52-K), 2^M */
106 vpsllq $42, %ymm3, %ymm4
108 /* multiply by 2^M through integer add */
109 vpaddq %ymm4, %ymm0, %ymm0
116 cfi_def_cfa_register (%rsp)
118 cfi_adjust_cfa_offset (-8)
124 vmovupd %ymm2, 320(%rsp)
125 vmovupd %ymm0, 384(%rsp)
130 vmovups %ymm8, 224(%rsp)
131 vmovups %ymm9, 192(%rsp)
132 vmovups %ymm10, 160(%rsp)
133 vmovups %ymm11, 128(%rsp)
134 vmovups %ymm12, 96(%rsp)
135 vmovups %ymm13, 64(%rsp)
136 vmovups %ymm14, 32(%rsp)
137 vmovups %ymm15, (%rsp)
141 cfi_offset_rel_rsp (12, 296)
144 cfi_offset_rel_rsp (13, 288)
147 cfi_offset_rel_rsp (14, 280)
150 cfi_offset_rel_rsp (15, 272)
168 vmovups 224(%rsp), %ymm8
169 vmovups 192(%rsp), %ymm9
170 vmovups 160(%rsp), %ymm10
171 vmovups 128(%rsp), %ymm11
172 vmovups 96(%rsp), %ymm12
173 vmovups 64(%rsp), %ymm13
174 vmovups 32(%rsp), %ymm14
175 vmovups (%rsp), %ymm15
176 vmovupd 384(%rsp), %ymm0
193 vmovsd 328(%rsp,%r15), %xmm0
198 vmovsd %xmm0, 392(%rsp,%r15)
204 vmovsd 320(%rsp,%r15), %xmm0
209 vmovsd %xmm0, 384(%rsp,%r15)
212 END (_ZGVdN4v_exp_avx2)