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. |
4 | |
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. |
9 | |
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. |
14 | |
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/. */ |
18 | |
19 | /* |
20 | * ALGORITHM DESCRIPTION: |
21 | * |
22 | * exp10(x) = 2^x/log10(2) = 2^n * (1 + T[j]) * (1 + P(y)) |
23 | * where |
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] |
26 | * |
27 | * values of 2^j/K are tabulated |
28 | * |
29 | * P(y) is a minimax polynomial approximation of exp10(x)-1 |
30 | * on small interval [-log10(2)/K..log10(2)/K] |
31 | * |
32 | * Special cases: |
33 | * |
34 | * exp10(NaN) = NaN |
35 | * exp10(+INF) = +INF |
36 | * exp10(-INF) = 0 |
37 | * exp10(x) = 1 for subnormals |
38 | * For IEEE float |
39 | * if x > 38.5318412780761720 then exp10f(x) overflow |
40 | * if x < -45.4555282592773440 then exp10f(x) underflow |
41 | * |
42 | */ |
43 | |
44 | /* Offsets for data table __svml_sexp10_data_internal |
45 | */ |
46 | #define _sT 0 |
47 | #define _sLg2_10 128 |
48 | #define _sShifter 160 |
49 | #define _sInvLg2_10hi 192 |
50 | #define _sInvLg2_10lo 224 |
51 | #define _sPC0 256 |
52 | #define _sPC1 288 |
53 | #define _sPC2 320 |
54 | #define _iIndexMask 352 |
55 | #define _iAbsMask 384 |
56 | #define _iDomainRange 416 |
57 | |
58 | #include <sysdep.h> |
59 | |
60 | .section .text.avx2, "ax" , @progbits |
61 | ENTRY(_ZGVdN8v_exp10f_avx2) |
62 | pushq %rbp |
63 | cfi_def_cfa_offset(16) |
64 | movq %rsp, %rbp |
65 | cfi_def_cfa(6, 16) |
66 | cfi_offset(6, -16) |
67 | andq $-32, %rsp |
68 | subq $96, %rsp |
69 | lea __svml_sexp10_data_internal(%rip), %rax |
70 | vmovups _sShifter+__svml_sexp10_data_internal(%rip), %ymm4 |
71 | |
72 | /* Load argument */ |
73 | vmovups _sLg2_10+__svml_sexp10_data_internal(%rip), %ymm1 |
74 | vmovups _iIndexMask+__svml_sexp10_data_internal(%rip), %ymm2 |
75 | vmovaps %ymm0, %ymm3 |
76 | vfmadd213ps %ymm4, %ymm3, %ymm1 |
77 | |
78 | /* Index and lookup */ |
79 | vandps %ymm2, %ymm1, %ymm7 |
80 | |
81 | /* iIndex *= sizeof(S); */ |
82 | vpslld $2, %ymm7, %ymm10 |
83 | vsubps %ymm4, %ymm1, %ymm0 |
84 | |
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 |
88 | vmovmskps %ymm6, %edx |
89 | vmovd %xmm10, %ecx |
90 | vextractf128 $1, %ymm10, %xmm6 |
91 | vpextrd $1, %xmm10, %esi |
92 | vpextrd $2, %xmm10, %edi |
93 | vpextrd $3, %xmm10, %r8d |
94 | movslq %ecx, %rcx |
95 | movslq %esi, %rsi |
96 | movslq %edi, %rdi |
97 | movslq %r8d, %r8 |
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 |
105 | |
106 | /* R */ |
107 | vmovups _sInvLg2_10hi+__svml_sexp10_data_internal(%rip), %ymm13 |
108 | vmovd %xmm6, %r9d |
109 | vfnmadd213ps %ymm3, %ymm0, %ymm13 |
110 | vpextrd $1, %xmm6, %r10d |
111 | movslq %r9d, %r9 |
112 | movslq %r10d, %r10 |
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 |
117 | |
118 | /* |
119 | * Polynomial |
120 | * exp10 = 2^N*(Tj+Tj*poly) |
121 | * poly(sN) = {1+later} a0+a1*sR |
122 | */ |
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 |
127 | movslq %r11d, %r11 |
128 | movslq %ecx, %rcx |
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 |
133 | |
134 | /* remove index bits */ |
135 | vpandn %ymm1, %ymm2, %ymm0 |
136 | vpunpcklqdq %xmm11, %xmm9, %xmm12 |
137 | |
138 | /* 2^N */ |
139 | vpslld $18, %ymm0, %ymm1 |
140 | vinsertf128 $1, %xmm12, %ymm15, %ymm14 |
141 | |
142 | /* Tj_l+Tj_h*poly */ |
143 | vfmadd213ps %ymm14, %ymm14, %ymm4 |
144 | |
145 | /* quick mul 2^N */ |
146 | vpaddd %ymm1, %ymm4, %ymm0 |
147 | |
148 | /* Finish */ |
149 | testl %edx, %edx |
150 | |
151 | /* Go to special inputs processing branch */ |
152 | jne L(SPECIAL_VALUES_BRANCH) |
153 | # LOE rbx r12 r13 r14 r15 edx ymm0 ymm3 |
154 | |
155 | /* Restore registers |
156 | * and exit the function |
157 | */ |
158 | |
159 | L(EXIT): |
160 | movq %rbp, %rsp |
161 | popq %rbp |
162 | cfi_def_cfa(7, 8) |
163 | cfi_restore(6) |
164 | ret |
165 | cfi_def_cfa(6, 16) |
166 | cfi_offset(6, -16) |
167 | |
168 | /* Branch to process |
169 | * special inputs |
170 | */ |
171 | |
172 | L(SPECIAL_VALUES_BRANCH): |
173 | vmovups %ymm3, 32(%rsp) |
174 | vmovups %ymm0, 64(%rsp) |
175 | # LOE rbx r12 r13 r14 r15 edx ymm0 |
176 | |
177 | xorl %eax, %eax |
178 | # LOE rbx r12 r13 r14 r15 eax edx |
179 | |
180 | vzeroupper |
181 | movq %r12, 16(%rsp) |
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 |
184 | movl %eax, %r12d |
185 | movq %r13, 8(%rsp) |
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 |
188 | movl %edx, %r13d |
189 | movq %r14, (%rsp) |
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 |
193 | |
194 | /* Range mask |
195 | * bits check |
196 | */ |
197 | |
198 | L(RANGEMASK_CHECK): |
199 | btl %r12d, %r13d |
200 | |
201 | /* Call scalar math function */ |
202 | jc L(SCALAR_MATH_CALL) |
203 | # LOE rbx r15 r12d r13d |
204 | |
205 | /* Special inputs |
206 | * processing loop |
207 | */ |
208 | |
209 | L(SPECIAL_VALUES_LOOP): |
210 | incl %r12d |
211 | cmpl $8, %r12d |
212 | |
213 | /* Check bits in range mask */ |
214 | jl L(RANGEMASK_CHECK) |
215 | # LOE rbx r15 r12d r13d |
216 | |
217 | movq 16(%rsp), %r12 |
218 | cfi_restore(12) |
219 | movq 8(%rsp), %r13 |
220 | cfi_restore(13) |
221 | movq (%rsp), %r14 |
222 | cfi_restore(14) |
223 | vmovups 64(%rsp), %ymm0 |
224 | |
225 | /* Go to exit */ |
226 | jmp L(EXIT) |
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 |
234 | |
235 | /* Scalar math function call |
236 | * to process special input |
237 | */ |
238 | |
239 | L(SCALAR_MATH_CALL): |
240 | movl %r12d, %r14d |
241 | vmovss 32(%rsp, %r14, 4), %xmm0 |
242 | call exp10f@PLT |
243 | # LOE rbx r14 r15 r12d r13d xmm0 |
244 | |
245 | vmovss %xmm0, 64(%rsp, %r14, 4) |
246 | |
247 | /* Process special inputs in loop */ |
248 | jmp L(SPECIAL_VALUES_LOOP) |
249 | # LOE rbx r15 r12d r13d |
250 | END(_ZGVdN8v_exp10f_avx2) |
251 | |
252 | .section .rodata, "a" |
253 | .align 32 |
254 | |
255 | #ifdef __svml_sexp10_data_internal_typedef |
256 | typedef unsigned int VUINT32; |
257 | typedef struct { |
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; |
270 | #endif |
271 | __svml_sexp10_data_internal: |
272 | /* _sT */ |
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 ) |
305 | .align 32 |
306 | .long 0x42d49a78, 0x42d49a78, 0x42d49a78, 0x42d49a78, 0x42d49a78, 0x42d49a78, 0x42d49a78, 0x42d49a78 /* _sLg2_10*2^K */ |
307 | .align 32 |
308 | .long 0x4b400000, 0x4b400000, 0x4b400000, 0x4b400000, 0x4b400000, 0x4b400000, 0x4b400000, 0x4b400000 /* _sShifter) */ |
309 | .align 32 |
310 | .long 0x3c1a2000, 0x3c1a2000, 0x3c1a2000, 0x3c1a2000, 0x3c1a2000, 0x3c1a2000, 0x3c1a2000, 0x3c1a2000 /* _sInvLg2_10hi/2^K hi (24-K-7) bits */ |
311 | .align 32 |
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 |
314 | .align 32 |
315 | .long 0x2fecc868, 0x2fecc868, 0x2fecc868, 0x2fecc868, 0x2fecc868, 0x2fecc868, 0x2fecc868, 0x2fecc868 /* _sPC0 */ |
316 | .align 32 |
317 | .long 0x40135e1b, 0x40135e1b, 0x40135e1b, 0x40135e1b, 0x40135e1b, 0x40135e1b, 0x40135e1b, 0x40135e1b /* _sPC1 */ |
318 | .align 32 |
319 | .long 0x4029a8d2, 0x4029a8d2, 0x4029a8d2, 0x4029a8d2, 0x4029a8d2, 0x4029a8d2, 0x4029a8d2, 0x4029a8d2 /* _sPC2 */ |
320 | .align 32 |
321 | .long 0x0000001f, 0x0000001f, 0x0000001f, 0x0000001f, 0x0000001f, 0x0000001f, 0x0000001f, 0x0000001f /* _iIndexMask =(2^K-1) */ |
322 | //common |
323 | .align 32 |
324 | .long 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff /* _iAbsMask */ |
325 | .align 32 |
326 | .long 0x4217b818, 0x4217b818, 0x4217b818, 0x4217b818, 0x4217b818, 0x4217b818, 0x4217b818, 0x4217b818 /* _iDomainRange=-log10(max_denormal=0x007fffff) RZ */ |
327 | .align 32 |
328 | .type __svml_sexp10_data_internal, @object |
329 | .size __svml_sexp10_data_internal, .-__svml_sexp10_data_internal |
330 | |