1 /* Function expf vectorized with AVX-512. KNL and SKX versions.
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_s_expf_data.h"
21 #include "svml_s_wrapper_impl.h"
24 ENTRY (_ZGVeN16v_expf_knl)
26 ALGORITHM DESCRIPTION:
28 Argument representation:
29 M = rint(X*2^k/ln2) = 2^k*N+j
30 X = M*ln2/2^k + r = N*ln2 + ln2*(j/2^k) + r
31 then -ln2/2^(k+1) < r < ln2/2^(k+1)
37 exp(X) = exp(N*ln2 + ln2*(j/2^k) + r)
38 = 2^N * 2^(j/2^k) * exp(r)
39 2^N is calculated by bit manipulation
40 2^(j/2^k) is computed from table lookup
41 exp(r) is approximated by polynomial
43 The table lookup is skipped if k = 0.
44 For low accuracy approximation, exp(r) ~ 1 or 1+r. */
47 cfi_adjust_cfa_offset (8)
48 cfi_rel_offset (%rbp, 0)
50 cfi_def_cfa_register (%rbp)
53 movq __svml_sexp_data@GOTPCREL(%rip), %rax
55 /* r = x-n*ln2_hi/2^k */
58 /* compare against threshold */
60 vmovups __sInvLn2(%rax), %zmm3
61 vmovups __sLn2hi(%rax), %zmm5
63 /* m = x*2^k/ln2 + shifter */
64 vfmadd213ps __sShifter(%rax), %zmm0, %zmm3
65 vmovups __sPC5(%rax), %zmm9
67 /* n = m - shifter = rint(x*2^k/ln2) */
68 vsubps __sShifter(%rax), %zmm3, %zmm7
70 /* remove sign of x by "and" operation */
71 vpandd __iAbsMask(%rax), %zmm0, %zmm1
72 vpaddd __iBias(%rax), %zmm3, %zmm4
73 vpcmpgtd __iDomainRange(%rax), %zmm1, %k1
75 /* compute 2^N with "shift" */
76 vpslld $23, %zmm4, %zmm8
77 vfnmadd231ps %zmm7, %zmm5, %zmm6
78 vpbroadcastd %ecx, %zmm2{%k1}{z}
80 /* r = r-n*ln2_lo/2^k = x - n*ln2/2^k */
81 vfnmadd132ps __sLn2lo(%rax), %zmm6, %zmm7
83 /* set mask for overflow/underflow */
84 vptestmd %zmm2, %zmm2, %k0
88 vfmadd213ps __sPC4(%rax), %zmm7, %zmm9
91 vfmadd213ps __sPC3(%rax), %zmm7, %zmm9
93 /* ((c5*r+c4)*r+c3)*r+c2 */
94 vfmadd213ps __sPC2(%rax), %zmm7, %zmm9
96 /* (((c5*r+c4)*r+c3)*r+c2)*r+c1 */
97 vfmadd213ps __sPC1(%rax), %zmm7, %zmm9
99 /* exp(r) = ((((c5*r+c4)*r+c3)*r+c2)*r+c1)*r+c0 */
100 vfmadd213ps __sPC0(%rax), %zmm7, %zmm9
103 vmulps %zmm9, %zmm8, %zmm1
111 cfi_def_cfa_register (%rsp)
113 cfi_adjust_cfa_offset (-8)
119 vmovups %zmm0, 1152(%rsp)
120 vmovups %zmm1, 1216(%rsp)
124 kmovw %k4, 1048(%rsp)
126 kmovw %k5, 1040(%rsp)
127 kmovw %k6, 1032(%rsp)
128 kmovw %k7, 1024(%rsp)
129 vmovups %zmm16, 960(%rsp)
130 vmovups %zmm17, 896(%rsp)
131 vmovups %zmm18, 832(%rsp)
132 vmovups %zmm19, 768(%rsp)
133 vmovups %zmm20, 704(%rsp)
134 vmovups %zmm21, 640(%rsp)
135 vmovups %zmm22, 576(%rsp)
136 vmovups %zmm23, 512(%rsp)
137 vmovups %zmm24, 448(%rsp)
138 vmovups %zmm25, 384(%rsp)
139 vmovups %zmm26, 320(%rsp)
140 vmovups %zmm27, 256(%rsp)
141 vmovups %zmm28, 192(%rsp)
142 vmovups %zmm29, 128(%rsp)
143 vmovups %zmm30, 64(%rsp)
144 vmovups %zmm31, (%rsp)
145 movq %rsi, 1064(%rsp)
146 movq %rdi, 1056(%rsp)
147 movq %r12, 1096(%rsp)
148 cfi_offset_rel_rsp (12, 1096)
150 movq %r13, 1088(%rsp)
151 cfi_offset_rel_rsp (13, 1088)
153 movq %r14, 1080(%rsp)
154 cfi_offset_rel_rsp (14, 1080)
156 movq %r15, 1072(%rsp)
157 cfi_offset_rel_rsp (15, 1072)
175 kmovw 1048(%rsp), %k4
176 movq 1064(%rsp), %rsi
177 kmovw 1040(%rsp), %k5
178 movq 1056(%rsp), %rdi
179 kmovw 1032(%rsp), %k6
180 movq 1096(%rsp), %r12
182 movq 1088(%rsp), %r13
184 kmovw 1024(%rsp), %k7
185 vmovups 960(%rsp), %zmm16
186 vmovups 896(%rsp), %zmm17
187 vmovups 832(%rsp), %zmm18
188 vmovups 768(%rsp), %zmm19
189 vmovups 704(%rsp), %zmm20
190 vmovups 640(%rsp), %zmm21
191 vmovups 576(%rsp), %zmm22
192 vmovups 512(%rsp), %zmm23
193 vmovups 448(%rsp), %zmm24
194 vmovups 384(%rsp), %zmm25
195 vmovups 320(%rsp), %zmm26
196 vmovups 256(%rsp), %zmm27
197 vmovups 192(%rsp), %zmm28
198 vmovups 128(%rsp), %zmm29
199 vmovups 64(%rsp), %zmm30
200 vmovups (%rsp), %zmm31
201 movq 1080(%rsp), %r14
203 movq 1072(%rsp), %r15
205 vmovups 1216(%rsp), %zmm1
211 vmovss 1156(%rsp,%r15,8), %xmm0
212 call JUMPTARGET(expf)
213 vmovss %xmm0, 1220(%rsp,%r15,8)
218 vmovss 1152(%rsp,%r15,8), %xmm0
219 call JUMPTARGET(expf)
220 vmovss %xmm0, 1216(%rsp,%r15,8)
223 END (_ZGVeN16v_expf_knl)
225 ENTRY (_ZGVeN16v_expf_skx)
227 ALGORITHM DESCRIPTION:
229 Argument representation:
230 M = rint(X*2^k/ln2) = 2^k*N+j
231 X = M*ln2/2^k + r = N*ln2 + ln2*(j/2^k) + r
232 then -ln2/2^(k+1) < r < ln2/2^(k+1)
238 exp(X) = exp(N*ln2 + ln2*(j/2^k) + r)
239 = 2^N * 2^(j/2^k) * exp(r)
240 2^N is calculated by bit manipulation
241 2^(j/2^k) is computed from table lookup
242 exp(r) is approximated by polynomial
244 The table lookup is skipped if k = 0.
245 For low accuracy approximation, exp(r) ~ 1 or 1+r. */
248 cfi_adjust_cfa_offset (8)
249 cfi_rel_offset (%rbp, 0)
251 cfi_def_cfa_register (%rbp)
254 movq __svml_sexp_data@GOTPCREL(%rip), %rax
256 /* r = x-n*ln2_hi/2^k */
259 /* compare against threshold */
260 vpternlogd $0xff, %zmm3, %zmm3, %zmm3
261 vmovups __sInvLn2(%rax), %zmm4
262 vmovups __sShifter(%rax), %zmm1
263 vmovups __sLn2hi(%rax), %zmm6
264 vmovups __sPC5(%rax), %zmm10
266 /* m = x*2^k/ln2 + shifter */
267 vfmadd213ps %zmm1, %zmm0, %zmm4
269 /* n = m - shifter = rint(x*2^k/ln2) */
270 vsubps %zmm1, %zmm4, %zmm8
271 vpaddd __iBias(%rax), %zmm4, %zmm5
272 vfnmadd231ps %zmm8, %zmm6, %zmm7
274 /* compute 2^N with "shift" */
275 vpslld $23, %zmm5, %zmm9
277 /* r = r-n*ln2_lo/2^k = x - n*ln2/2^k */
278 vfnmadd132ps __sLn2lo(%rax), %zmm7, %zmm8
281 vfmadd213ps __sPC4(%rax), %zmm8, %zmm10
284 vfmadd213ps __sPC3(%rax), %zmm8, %zmm10
286 /* ((c5*r+c4)*r+c3)*r+c2 */
287 vfmadd213ps __sPC2(%rax), %zmm8, %zmm10
289 /* (((c5*r+c4)*r+c3)*r+c2)*r+c1 */
290 vfmadd213ps __sPC1(%rax), %zmm8, %zmm10
292 /* exp(r) = ((((c5*r+c4)*r+c3)*r+c2)*r+c1)*r+c0 */
293 vfmadd213ps __sPC0(%rax), %zmm8, %zmm10
296 vmulps %zmm10, %zmm9, %zmm1
298 /* remove sign of x by "and" operation */
299 vpandd __iAbsMask(%rax), %zmm0, %zmm2
300 vpcmpd $2, __iDomainRange(%rax), %zmm2, %k1
301 vpandnd %zmm2, %zmm2, %zmm3{%k1}
303 /* set mask for overflow/underflow */
304 vptestmd %zmm3, %zmm3, %k0
313 cfi_def_cfa_register (%rsp)
315 cfi_adjust_cfa_offset (-8)
321 vmovups %zmm0, 1152(%rsp)
322 vmovups %zmm1, 1216(%rsp)
327 kmovw %k4, 1048(%rsp)
328 kmovw %k5, 1040(%rsp)
329 kmovw %k6, 1032(%rsp)
330 kmovw %k7, 1024(%rsp)
331 vmovups %zmm16, 960(%rsp)
332 vmovups %zmm17, 896(%rsp)
333 vmovups %zmm18, 832(%rsp)
334 vmovups %zmm19, 768(%rsp)
335 vmovups %zmm20, 704(%rsp)
336 vmovups %zmm21, 640(%rsp)
337 vmovups %zmm22, 576(%rsp)
338 vmovups %zmm23, 512(%rsp)
339 vmovups %zmm24, 448(%rsp)
340 vmovups %zmm25, 384(%rsp)
341 vmovups %zmm26, 320(%rsp)
342 vmovups %zmm27, 256(%rsp)
343 vmovups %zmm28, 192(%rsp)
344 vmovups %zmm29, 128(%rsp)
345 vmovups %zmm30, 64(%rsp)
346 vmovups %zmm31, (%rsp)
347 movq %rsi, 1064(%rsp)
348 movq %rdi, 1056(%rsp)
349 movq %r12, 1096(%rsp)
350 cfi_offset_rel_rsp (12, 1096)
352 movq %r13, 1088(%rsp)
353 cfi_offset_rel_rsp (13, 1088)
355 movq %r14, 1080(%rsp)
356 cfi_offset_rel_rsp (14, 1080)
358 movq %r15, 1072(%rsp)
359 cfi_offset_rel_rsp (15, 1072)
378 kmovw 1048(%rsp), %k4
379 kmovw 1040(%rsp), %k5
380 kmovw 1032(%rsp), %k6
381 kmovw 1024(%rsp), %k7
382 vmovups 960(%rsp), %zmm16
383 vmovups 896(%rsp), %zmm17
384 vmovups 832(%rsp), %zmm18
385 vmovups 768(%rsp), %zmm19
386 vmovups 704(%rsp), %zmm20
387 vmovups 640(%rsp), %zmm21
388 vmovups 576(%rsp), %zmm22
389 vmovups 512(%rsp), %zmm23
390 vmovups 448(%rsp), %zmm24
391 vmovups 384(%rsp), %zmm25
392 vmovups 320(%rsp), %zmm26
393 vmovups 256(%rsp), %zmm27
394 vmovups 192(%rsp), %zmm28
395 vmovups 128(%rsp), %zmm29
396 vmovups 64(%rsp), %zmm30
397 vmovups (%rsp), %zmm31
398 vmovups 1216(%rsp), %zmm1
399 movq 1064(%rsp), %rsi
400 movq 1056(%rsp), %rdi
401 movq 1096(%rsp), %r12
403 movq 1088(%rsp), %r13
405 movq 1080(%rsp), %r14
407 movq 1072(%rsp), %r15
414 vmovss 1156(%rsp,%r15,8), %xmm0
416 vmovss 1156(%rsp,%r15,8), %xmm0
418 call JUMPTARGET(expf)
420 vmovss %xmm0, 1220(%rsp,%r15,8)
425 vmovss 1152(%rsp,%r15,8), %xmm0
427 vmovss 1152(%rsp,%r15,8), %xmm0
429 call JUMPTARGET(expf)
431 vmovss %xmm0, 1216(%rsp,%r15,8)
434 END (_ZGVeN16v_expf_skx)