1 /* Function exp10f vectorized with AVX2.
2 Copyright (C) 2021-2024 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 * ALGORITHM DESCRIPTION:
22 * exp10(x) = 2^x/log10(2) = 2^n * (1 + T[j]) * (1 + P(y))
24 * x = m*log10(2)/K + y, y in [-log10(2)/K..log10(2)/K]
25 * m = n*K + j, m, n,j - signed integer, j in [-K/2..K/2]
27 * values of 2^j/K are tabulated
29 * P(y) is a minimax polynomial approximation of exp10(x)-1
30 * on small interval [-log10(2)/K..log10(2)/K]
37 * exp10(x) = 1 for subnormals
39 * if x > 38.5318412780761720 then exp10f(x) overflow
40 * if x < -45.4555282592773440 then exp10f(x) underflow
44 /* Offsets for data table __svml_sexp10_data_internal
49 #define _sInvLg2_10hi 192
50 #define _sInvLg2_10lo 224
54 #define _iIndexMask 352
56 #define _iDomainRange 416
60 .section .text.avx2, "ax", @progbits
61 ENTRY(_ZGVdN8v_exp10f_avx2)
63 cfi_def_cfa_offset(16)
69 lea __svml_sexp10_data_internal(%rip), %rax
70 vmovups _sShifter+__svml_sexp10_data_internal(%rip), %ymm4
73 vmovups _sLg2_10+__svml_sexp10_data_internal(%rip), %ymm1
74 vmovups _iIndexMask+__svml_sexp10_data_internal(%rip), %ymm2
76 vfmadd213ps %ymm4, %ymm3, %ymm1
78 /* Index and lookup */
79 vandps %ymm2, %ymm1, %ymm7
81 /* iIndex *= sizeof(S); */
82 vpslld $2, %ymm7, %ymm10
83 vsubps %ymm4, %ymm1, %ymm0
85 /* Check for overflow\underflow */
86 vandps _iAbsMask+__svml_sexp10_data_internal(%rip), %ymm3, %ymm5
87 vpcmpgtd _iDomainRange+__svml_sexp10_data_internal(%rip), %ymm5, %ymm6
90 vextractf128 $1, %ymm10, %xmm6
91 vpextrd $1, %xmm10, %esi
92 vpextrd $2, %xmm10, %edi
93 vpextrd $3, %xmm10, %r8d
98 vmovd (%rax, %rcx), %xmm8
99 vmovd (%rax, %rsi), %xmm9
100 vmovd (%rax, %rdi), %xmm11
101 vmovd (%rax, %r8), %xmm12
102 vpunpckldq %xmm9, %xmm8, %xmm13
103 vpunpckldq %xmm12, %xmm11, %xmm14
104 vpunpcklqdq %xmm14, %xmm13, %xmm15
107 vmovups _sInvLg2_10hi+__svml_sexp10_data_internal(%rip), %ymm13
109 vfnmadd213ps %ymm3, %ymm0, %ymm13
110 vpextrd $1, %xmm6, %r10d
113 vfnmadd132ps _sInvLg2_10lo+__svml_sexp10_data_internal(%rip), %ymm13, %ymm0
114 vmovd (%rax, %r9), %xmm4
115 vmovd (%rax, %r10), %xmm5
116 vpunpckldq %xmm5, %xmm4, %xmm9
120 * exp10 = 2^N*(Tj+Tj*poly)
121 * poly(sN) = {1+later} a0+a1*sR
123 vmovups _sPC2+__svml_sexp10_data_internal(%rip), %ymm4
124 vfmadd213ps _sPC1+__svml_sexp10_data_internal(%rip), %ymm0, %ymm4
125 vpextrd $2, %xmm6, %r11d
126 vpextrd $3, %xmm6, %ecx
129 vfmadd213ps _sPC0+__svml_sexp10_data_internal(%rip), %ymm0, %ymm4
130 vmovd (%rax, %r11), %xmm7
131 vmovd (%rax, %rcx), %xmm8
132 vpunpckldq %xmm8, %xmm7, %xmm11
134 /* remove index bits */
135 vpandn %ymm1, %ymm2, %ymm0
136 vpunpcklqdq %xmm11, %xmm9, %xmm12
139 vpslld $18, %ymm0, %ymm1
140 vinsertf128 $1, %xmm12, %ymm15, %ymm14
143 vfmadd213ps %ymm14, %ymm14, %ymm4
146 vpaddd %ymm1, %ymm4, %ymm0
151 /* Go to special inputs processing branch */
152 jne L(SPECIAL_VALUES_BRANCH)
153 # LOE rbx r12 r13 r14 r15 edx ymm0 ymm3
156 * and exit the function
172 L(SPECIAL_VALUES_BRANCH):
173 vmovups %ymm3, 32(%rsp)
174 vmovups %ymm0, 64(%rsp)
175 # LOE rbx r12 r13 r14 r15 edx ymm0
178 # LOE rbx r12 r13 r14 r15 eax edx
182 /* DW_CFA_expression: r12 (r12) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -32; DW_OP_and; DW_OP_const4s: -80; DW_OP_plus) */
183 .cfi_escape 0x10, 0x0c, 0x0e, 0x38, 0x1c, 0x0d, 0xe0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0xb0, 0xff, 0xff, 0xff, 0x22
186 /* DW_CFA_expression: r13 (r13) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -32; DW_OP_and; DW_OP_const4s: -88; DW_OP_plus) */
187 .cfi_escape 0x10, 0x0d, 0x0e, 0x38, 0x1c, 0x0d, 0xe0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0xa8, 0xff, 0xff, 0xff, 0x22
190 /* DW_CFA_expression: r14 (r14) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -32; DW_OP_and; DW_OP_const4s: -96; DW_OP_plus) */
191 .cfi_escape 0x10, 0x0e, 0x0e, 0x38, 0x1c, 0x0d, 0xe0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0xa0, 0xff, 0xff, 0xff, 0x22
192 # LOE rbx r15 r12d r13d
201 /* Call scalar math function */
202 jc L(SCALAR_MATH_CALL)
203 # LOE rbx r15 r12d r13d
209 L(SPECIAL_VALUES_LOOP):
213 /* Check bits in range mask */
214 jl L(RANGEMASK_CHECK)
215 # LOE rbx r15 r12d r13d
223 vmovups 64(%rsp), %ymm0
227 /* DW_CFA_expression: r12 (r12) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -32; DW_OP_and; DW_OP_const4s: -80; DW_OP_plus) */
228 .cfi_escape 0x10, 0x0c, 0x0e, 0x38, 0x1c, 0x0d, 0xe0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0xb0, 0xff, 0xff, 0xff, 0x22
229 /* DW_CFA_expression: r13 (r13) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -32; DW_OP_and; DW_OP_const4s: -88; DW_OP_plus) */
230 .cfi_escape 0x10, 0x0d, 0x0e, 0x38, 0x1c, 0x0d, 0xe0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0xa8, 0xff, 0xff, 0xff, 0x22
231 /* DW_CFA_expression: r14 (r14) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -32; DW_OP_and; DW_OP_const4s: -96; DW_OP_plus) */
232 .cfi_escape 0x10, 0x0e, 0x0e, 0x38, 0x1c, 0x0d, 0xe0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0xa0, 0xff, 0xff, 0xff, 0x22
233 # LOE rbx r12 r13 r14 r15 ymm0
235 /* Scalar math function call
236 * to process special input
241 vmovss 32(%rsp, %r14, 4), %xmm0
243 # LOE rbx r14 r15 r12d r13d xmm0
245 vmovss %xmm0, 64(%rsp, %r14, 4)
247 /* Process special inputs in loop */
248 jmp L(SPECIAL_VALUES_LOOP)
249 # LOE rbx r15 r12d r13d
250 END(_ZGVdN8v_exp10f_avx2)
252 .section .rodata, "a"
255 #ifdef __svml_sexp10_data_internal_typedef
256 typedef unsigned int VUINT32;
258 __declspec(align(32)) VUINT32 _sT[(1<<5)][1];
259 __declspec(align(32)) VUINT32 _sLg2_10[8][1];
260 __declspec(align(32)) VUINT32 _sShifter[8][1];
261 __declspec(align(32)) VUINT32 _sInvLg2_10hi[8][1];
262 __declspec(align(32)) VUINT32 _sInvLg2_10lo[8][1];
263 __declspec(align(32)) VUINT32 _sPC0[8][1];
264 __declspec(align(32)) VUINT32 _sPC1[8][1];
265 __declspec(align(32)) VUINT32 _sPC2[8][1];
266 __declspec(align(32)) VUINT32 _iIndexMask[8][1];
267 __declspec(align(32)) VUINT32 _iAbsMask[8][1];
268 __declspec(align(32)) VUINT32 _iDomainRange[8][1];
269 } __svml_sexp10_data_internal;
271 __svml_sexp10_data_internal:
273 .long 0x3f800000 // 2^( 0 /32 )
274 .long 0x3f82cd87 // 2^( 1 /32 )
275 .long 0x3f85aac3 // 2^( 2 /32 )
276 .long 0x3f88980f // 2^( 3 /32 )
277 .long 0x3f8b95c2 // 2^( 4 /32 )
278 .long 0x3f8ea43a // 2^( 5 /32 )
279 .long 0x3f91c3d3 // 2^( 6 /32 )
280 .long 0x3f94f4f0 // 2^( 7 /32 )
281 .long 0x3f9837f0 // 2^( 8 /32 )
282 .long 0x3f9b8d3a // 2^( 9 /32 )
283 .long 0x3f9ef532 // 2^( 10/32 )
284 .long 0x3fa27043 // 2^( 11/32 )
285 .long 0x3fa5fed7 // 2^( 12/32 )
286 .long 0x3fa9a15b // 2^( 13/32 )
287 .long 0x3fad583f // 2^( 14/32 )
288 .long 0x3fb123f6 // 2^( 15/32 )
289 .long 0x3fb504f3 // 2^( 16/32 )
290 .long 0x3fb8fbaf // 2^( 17/32 )
291 .long 0x3fbd08a4 // 2^( 18/32 )
292 .long 0x3fc12c4d // 2^( 19/32 )
293 .long 0x3fc5672a // 2^( 20/32 )
294 .long 0x3fc9b9be // 2^( 21/32 )
295 .long 0x3fce248c // 2^( 22/32 )
296 .long 0x3fd2a81e // 2^( 23/32 )
297 .long 0x3fd744fd // 2^( 24/32 )
298 .long 0x3fdbfbb8 // 2^( 25/32 )
299 .long 0x3fe0ccdf // 2^( 26/32 )
300 .long 0x3fe5b907 // 2^( 27/32 )
301 .long 0x3feac0c7 // 2^( 28/32 )
302 .long 0x3fefe4ba // 2^( 29/32 )
303 .long 0x3ff5257d // 2^( 30/32 )
304 .long 0x3ffa83b3 // 2^( 31/32 )
306 .long 0x42d49a78, 0x42d49a78, 0x42d49a78, 0x42d49a78, 0x42d49a78, 0x42d49a78, 0x42d49a78, 0x42d49a78 /* _sLg2_10*2^K */
308 .long 0x4b400000, 0x4b400000, 0x4b400000, 0x4b400000, 0x4b400000, 0x4b400000, 0x4b400000, 0x4b400000 /* _sShifter) */
310 .long 0x3c1a2000, 0x3c1a2000, 0x3c1a2000, 0x3c1a2000, 0x3c1a2000, 0x3c1a2000, 0x3c1a2000, 0x3c1a2000 /* _sInvLg2_10hi/2^K hi (24-K-7) bits */
312 .long 0x341a84fc, 0x341a84fc, 0x341a84fc, 0x341a84fc, 0x341a84fc, 0x341a84fc, 0x341a84fc, 0x341a84fc /* _sInvLg2_10lo/2^K lo bits */
313 // otherwise exp10(0) won't produce exact 1.0
315 .long 0x2fecc868, 0x2fecc868, 0x2fecc868, 0x2fecc868, 0x2fecc868, 0x2fecc868, 0x2fecc868, 0x2fecc868 /* _sPC0 */
317 .long 0x40135e1b, 0x40135e1b, 0x40135e1b, 0x40135e1b, 0x40135e1b, 0x40135e1b, 0x40135e1b, 0x40135e1b /* _sPC1 */
319 .long 0x4029a8d2, 0x4029a8d2, 0x4029a8d2, 0x4029a8d2, 0x4029a8d2, 0x4029a8d2, 0x4029a8d2, 0x4029a8d2 /* _sPC2 */
321 .long 0x0000001f, 0x0000001f, 0x0000001f, 0x0000001f, 0x0000001f, 0x0000001f, 0x0000001f, 0x0000001f /* _iIndexMask =(2^K-1) */
324 .long 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff /* _iAbsMask */
326 .long 0x4217b818, 0x4217b818, 0x4217b818, 0x4217b818, 0x4217b818, 0x4217b818, 0x4217b818, 0x4217b818 /* _iDomainRange=-log10(max_denormal=0x007fffff) RZ */
328 .type __svml_sexp10_data_internal, @object
329 .size __svml_sexp10_data_internal, .-__svml_sexp10_data_internal