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)
25 #ifndef HAVE_AVX512DQ_ASM_SUPPORT
26 WRAPPER_IMPL_AVX512 _ZGVdN8v_expf
29 ALGORITHM DESCRIPTION:
31 Argument representation:
32 M = rint(X*2^k/ln2) = 2^k*N+j
33 X = M*ln2/2^k + r = N*ln2 + ln2*(j/2^k) + r
34 then -ln2/2^(k+1) < r < ln2/2^(k+1)
40 exp(X) = exp(N*ln2 + ln2*(j/2^k) + r)
41 = 2^N * 2^(j/2^k) * exp(r)
42 2^N is calculated by bit manipulation
43 2^(j/2^k) is computed from table lookup
44 exp(r) is approximated by polynomial
46 The table lookup is skipped if k = 0.
47 For low accuracy approximation, exp(r) ~ 1 or 1+r. */
50 cfi_adjust_cfa_offset (8)
51 cfi_rel_offset (%rbp, 0)
53 cfi_def_cfa_register (%rbp)
56 movq __svml_sexp_data@GOTPCREL(%rip), %rax
58 /* r = x-n*ln2_hi/2^k */
61 /* compare against threshold */
63 vmovups __sInvLn2(%rax), %zmm3
64 vmovups __sLn2hi(%rax), %zmm5
66 /* m = x*2^k/ln2 + shifter */
67 vfmadd213ps __sShifter(%rax), %zmm0, %zmm3
68 vmovups __sPC5(%rax), %zmm9
70 /* n = m - shifter = rint(x*2^k/ln2) */
71 vsubps __sShifter(%rax), %zmm3, %zmm7
73 /* remove sign of x by "and" operation */
74 vpandd __iAbsMask(%rax), %zmm0, %zmm1
75 vpaddd __iBias(%rax), %zmm3, %zmm4
76 vpcmpgtd __iDomainRange(%rax), %zmm1, %k1
78 /* compute 2^N with "shift" */
79 vpslld $23, %zmm4, %zmm8
80 vfnmadd231ps %zmm7, %zmm5, %zmm6
81 vpbroadcastd %ecx, %zmm2{%k1}{z}
83 /* r = r-n*ln2_lo/2^k = x - n*ln2/2^k */
84 vfnmadd132ps __sLn2lo(%rax), %zmm6, %zmm7
86 /* set mask for overflow/underflow */
87 vptestmd %zmm2, %zmm2, %k0
91 vfmadd213ps __sPC4(%rax), %zmm7, %zmm9
94 vfmadd213ps __sPC3(%rax), %zmm7, %zmm9
96 /* ((c5*r+c4)*r+c3)*r+c2 */
97 vfmadd213ps __sPC2(%rax), %zmm7, %zmm9
99 /* (((c5*r+c4)*r+c3)*r+c2)*r+c1 */
100 vfmadd213ps __sPC1(%rax), %zmm7, %zmm9
102 /* exp(r) = ((((c5*r+c4)*r+c3)*r+c2)*r+c1)*r+c0 */
103 vfmadd213ps __sPC0(%rax), %zmm7, %zmm9
106 vmulps %zmm9, %zmm8, %zmm1
114 cfi_def_cfa_register (%rsp)
116 cfi_adjust_cfa_offset (-8)
122 vmovups %zmm0, 1152(%rsp)
123 vmovups %zmm1, 1216(%rsp)
127 kmovw %k4, 1048(%rsp)
129 kmovw %k5, 1040(%rsp)
130 kmovw %k6, 1032(%rsp)
131 kmovw %k7, 1024(%rsp)
132 vmovups %zmm16, 960(%rsp)
133 vmovups %zmm17, 896(%rsp)
134 vmovups %zmm18, 832(%rsp)
135 vmovups %zmm19, 768(%rsp)
136 vmovups %zmm20, 704(%rsp)
137 vmovups %zmm21, 640(%rsp)
138 vmovups %zmm22, 576(%rsp)
139 vmovups %zmm23, 512(%rsp)
140 vmovups %zmm24, 448(%rsp)
141 vmovups %zmm25, 384(%rsp)
142 vmovups %zmm26, 320(%rsp)
143 vmovups %zmm27, 256(%rsp)
144 vmovups %zmm28, 192(%rsp)
145 vmovups %zmm29, 128(%rsp)
146 vmovups %zmm30, 64(%rsp)
147 vmovups %zmm31, (%rsp)
148 movq %rsi, 1064(%rsp)
149 movq %rdi, 1056(%rsp)
150 movq %r12, 1096(%rsp)
151 cfi_offset_rel_rsp (12, 1096)
153 movq %r13, 1088(%rsp)
154 cfi_offset_rel_rsp (13, 1088)
156 movq %r14, 1080(%rsp)
157 cfi_offset_rel_rsp (14, 1080)
159 movq %r15, 1072(%rsp)
160 cfi_offset_rel_rsp (15, 1072)
178 kmovw 1048(%rsp), %k4
179 movq 1064(%rsp), %rsi
180 kmovw 1040(%rsp), %k5
181 movq 1056(%rsp), %rdi
182 kmovw 1032(%rsp), %k6
183 movq 1096(%rsp), %r12
185 movq 1088(%rsp), %r13
187 kmovw 1024(%rsp), %k7
188 vmovups 960(%rsp), %zmm16
189 vmovups 896(%rsp), %zmm17
190 vmovups 832(%rsp), %zmm18
191 vmovups 768(%rsp), %zmm19
192 vmovups 704(%rsp), %zmm20
193 vmovups 640(%rsp), %zmm21
194 vmovups 576(%rsp), %zmm22
195 vmovups 512(%rsp), %zmm23
196 vmovups 448(%rsp), %zmm24
197 vmovups 384(%rsp), %zmm25
198 vmovups 320(%rsp), %zmm26
199 vmovups 256(%rsp), %zmm27
200 vmovups 192(%rsp), %zmm28
201 vmovups 128(%rsp), %zmm29
202 vmovups 64(%rsp), %zmm30
203 vmovups (%rsp), %zmm31
204 movq 1080(%rsp), %r14
206 movq 1072(%rsp), %r15
208 vmovups 1216(%rsp), %zmm1
214 vmovss 1156(%rsp,%r15,8), %xmm0
215 call JUMPTARGET(expf)
216 vmovss %xmm0, 1220(%rsp,%r15,8)
221 vmovss 1152(%rsp,%r15,8), %xmm0
222 call JUMPTARGET(expf)
223 vmovss %xmm0, 1216(%rsp,%r15,8)
227 END (_ZGVeN16v_expf_knl)
229 ENTRY (_ZGVeN16v_expf_skx)
230 #ifndef HAVE_AVX512DQ_ASM_SUPPORT
231 WRAPPER_IMPL_AVX512 _ZGVdN8v_expf
234 ALGORITHM DESCRIPTION:
236 Argument representation:
237 M = rint(X*2^k/ln2) = 2^k*N+j
238 X = M*ln2/2^k + r = N*ln2 + ln2*(j/2^k) + r
239 then -ln2/2^(k+1) < r < ln2/2^(k+1)
245 exp(X) = exp(N*ln2 + ln2*(j/2^k) + r)
246 = 2^N * 2^(j/2^k) * exp(r)
247 2^N is calculated by bit manipulation
248 2^(j/2^k) is computed from table lookup
249 exp(r) is approximated by polynomial
251 The table lookup is skipped if k = 0.
252 For low accuracy approximation, exp(r) ~ 1 or 1+r. */
255 cfi_adjust_cfa_offset (8)
256 cfi_rel_offset (%rbp, 0)
258 cfi_def_cfa_register (%rbp)
261 movq __svml_sexp_data@GOTPCREL(%rip), %rax
263 /* r = x-n*ln2_hi/2^k */
266 /* compare against threshold */
267 vmovups .L_2il0floatpacket.13(%rip), %zmm3
268 vmovups __sInvLn2(%rax), %zmm4
269 vmovups __sShifter(%rax), %zmm1
270 vmovups __sLn2hi(%rax), %zmm6
271 vmovups __sPC5(%rax), %zmm10
273 /* m = x*2^k/ln2 + shifter */
274 vfmadd213ps %zmm1, %zmm0, %zmm4
276 /* n = m - shifter = rint(x*2^k/ln2) */
277 vsubps %zmm1, %zmm4, %zmm8
278 vpaddd __iBias(%rax), %zmm4, %zmm5
279 vfnmadd231ps %zmm8, %zmm6, %zmm7
281 /* compute 2^N with "shift" */
282 vpslld $23, %zmm5, %zmm9
284 /* r = r-n*ln2_lo/2^k = x - n*ln2/2^k */
285 vfnmadd132ps __sLn2lo(%rax), %zmm7, %zmm8
288 vfmadd213ps __sPC4(%rax), %zmm8, %zmm10
291 vfmadd213ps __sPC3(%rax), %zmm8, %zmm10
293 /* ((c5*r+c4)*r+c3)*r+c2 */
294 vfmadd213ps __sPC2(%rax), %zmm8, %zmm10
296 /* (((c5*r+c4)*r+c3)*r+c2)*r+c1 */
297 vfmadd213ps __sPC1(%rax), %zmm8, %zmm10
299 /* exp(r) = ((((c5*r+c4)*r+c3)*r+c2)*r+c1)*r+c0 */
300 vfmadd213ps __sPC0(%rax), %zmm8, %zmm10
303 vmulps %zmm10, %zmm9, %zmm1
305 /* remove sign of x by "and" operation */
306 vpandd __iAbsMask(%rax), %zmm0, %zmm2
307 vpcmpd $2, __iDomainRange(%rax), %zmm2, %k1
308 vpandnd %zmm2, %zmm2, %zmm3{%k1}
310 /* set mask for overflow/underflow */
311 vptestmd %zmm3, %zmm3, %k0
320 cfi_def_cfa_register (%rsp)
322 cfi_adjust_cfa_offset (-8)
328 vmovups %zmm0, 1152(%rsp)
329 vmovups %zmm1, 1216(%rsp)
334 kmovw %k4, 1048(%rsp)
335 kmovw %k5, 1040(%rsp)
336 kmovw %k6, 1032(%rsp)
337 kmovw %k7, 1024(%rsp)
338 vmovups %zmm16, 960(%rsp)
339 vmovups %zmm17, 896(%rsp)
340 vmovups %zmm18, 832(%rsp)
341 vmovups %zmm19, 768(%rsp)
342 vmovups %zmm20, 704(%rsp)
343 vmovups %zmm21, 640(%rsp)
344 vmovups %zmm22, 576(%rsp)
345 vmovups %zmm23, 512(%rsp)
346 vmovups %zmm24, 448(%rsp)
347 vmovups %zmm25, 384(%rsp)
348 vmovups %zmm26, 320(%rsp)
349 vmovups %zmm27, 256(%rsp)
350 vmovups %zmm28, 192(%rsp)
351 vmovups %zmm29, 128(%rsp)
352 vmovups %zmm30, 64(%rsp)
353 vmovups %zmm31, (%rsp)
354 movq %rsi, 1064(%rsp)
355 movq %rdi, 1056(%rsp)
356 movq %r12, 1096(%rsp)
357 cfi_offset_rel_rsp (12, 1096)
359 movq %r13, 1088(%rsp)
360 cfi_offset_rel_rsp (13, 1088)
362 movq %r14, 1080(%rsp)
363 cfi_offset_rel_rsp (14, 1080)
365 movq %r15, 1072(%rsp)
366 cfi_offset_rel_rsp (15, 1072)
385 kmovw 1048(%rsp), %k4
386 kmovw 1040(%rsp), %k5
387 kmovw 1032(%rsp), %k6
388 kmovw 1024(%rsp), %k7
389 vmovups 960(%rsp), %zmm16
390 vmovups 896(%rsp), %zmm17
391 vmovups 832(%rsp), %zmm18
392 vmovups 768(%rsp), %zmm19
393 vmovups 704(%rsp), %zmm20
394 vmovups 640(%rsp), %zmm21
395 vmovups 576(%rsp), %zmm22
396 vmovups 512(%rsp), %zmm23
397 vmovups 448(%rsp), %zmm24
398 vmovups 384(%rsp), %zmm25
399 vmovups 320(%rsp), %zmm26
400 vmovups 256(%rsp), %zmm27
401 vmovups 192(%rsp), %zmm28
402 vmovups 128(%rsp), %zmm29
403 vmovups 64(%rsp), %zmm30
404 vmovups (%rsp), %zmm31
405 vmovups 1216(%rsp), %zmm1
406 movq 1064(%rsp), %rsi
407 movq 1056(%rsp), %rdi
408 movq 1096(%rsp), %r12
410 movq 1088(%rsp), %r13
412 movq 1080(%rsp), %r14
414 movq 1072(%rsp), %r15
421 vmovss 1156(%rsp,%r15,8), %xmm0
423 vmovss 1156(%rsp,%r15,8), %xmm0
425 call JUMPTARGET(expf)
427 vmovss %xmm0, 1220(%rsp,%r15,8)
432 vmovss 1152(%rsp,%r15,8), %xmm0
434 vmovss 1152(%rsp,%r15,8), %xmm0
436 call JUMPTARGET(expf)
438 vmovss %xmm0, 1216(%rsp,%r15,8)
442 END (_ZGVeN16v_expf_skx)
444 .section .rodata, "a"
445 .L_2il0floatpacket.13:
446 .long 0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff
447 .type .L_2il0floatpacket.13,@object