]>
Commit | Line | Data |
---|---|---|
774488f8 | 1 | /* Function logf vectorized with AVX-512. KNL and SKX versions. |
2b778ceb | 2 | Copyright (C) 2014-2021 Free Software Foundation, Inc. |
774488f8 AS |
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 | |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
774488f8 AS |
18 | |
19 | #include <sysdep.h> | |
20 | #include "svml_s_logf_data.h" | |
21 | #include "svml_s_wrapper_impl.h" | |
22 | ||
23 | .text | |
24 | ENTRY (_ZGVeN16v_logf_knl) | |
f43cb35c | 25 | #ifndef HAVE_AVX512DQ_ASM_SUPPORT |
774488f8 AS |
26 | WRAPPER_IMPL_AVX512 _ZGVdN8v_logf |
27 | #else | |
28 | /* | |
29 | ALGORITHM DESCRIPTION: | |
30 | ||
31 | log(x) = exponent_x*log(2) + log(mantissa_x), if mantissa_x<4/3 | |
32 | log(x) = (exponent_x+1)*log(2) + log(0.5*mantissa_x), if mantissa_x>4/3 | |
33 | ||
34 | R = mantissa_x - 1, if mantissa_x<4/3 | |
35 | R = 0.5*mantissa_x - 1, if mantissa_x>4/3 | |
36 | |R|< 1/3 | |
37 | ||
38 | log(1+R) is approximated as a polynomial: degree 9 for 1-ulp, | |
39 | degree 7 for 4-ulp, degree 3 for half-precision. */ | |
40 | ||
41 | pushq %rbp | |
42 | cfi_adjust_cfa_offset (8) | |
43 | cfi_rel_offset (%rbp, 0) | |
44 | movq %rsp, %rbp | |
45 | cfi_def_cfa_register (%rbp) | |
46 | andq $-64, %rsp | |
47 | subq $1280, %rsp | |
48 | movq __svml_slog_data@GOTPCREL(%rip), %rax | |
49 | movl $-1, %ecx | |
50 | ||
51 | /* reduction: compute r,n */ | |
52 | vpsubd _iBrkValue(%rax), %zmm0, %zmm2 | |
53 | vmovups _sPoly_7(%rax), %zmm7 | |
54 | vpandd _iOffExpoMask(%rax), %zmm2, %zmm3 | |
55 | ||
56 | /* exponent_x (mantissa_x<4/3) or exponent_x+1 (mantissa_x>4/3) */ | |
57 | vpsrad $23, %zmm2, %zmm4 | |
58 | ||
59 | /* check for working range, | |
60 | set special argument mask (denormals/zero/Inf/NaN) | |
61 | */ | |
62 | vpaddd _iHiDelta(%rax), %zmm0, %zmm1 | |
63 | ||
64 | /* mantissa_x (mantissa_x<4/3), or 0.5*mantissa_x (mantissa_x>4/3) */ | |
65 | vpaddd _iBrkValue(%rax), %zmm3, %zmm6 | |
66 | vpcmpd $1, _iLoRange(%rax), %zmm1, %k1 | |
67 | vcvtdq2ps {rn-sae}, %zmm4, %zmm1 | |
68 | ||
69 | /* reduced argument R */ | |
70 | vsubps _sOne(%rax), %zmm6, %zmm8 | |
71 | vpbroadcastd %ecx, %zmm5{%k1}{z} | |
72 | ||
73 | /* polynomial evaluation starts here */ | |
74 | vfmadd213ps _sPoly_6(%rax), %zmm8, %zmm7 | |
75 | vptestmd %zmm5, %zmm5, %k0 | |
76 | kmovw %k0, %ecx | |
77 | vfmadd213ps _sPoly_5(%rax), %zmm8, %zmm7 | |
78 | vfmadd213ps _sPoly_4(%rax), %zmm8, %zmm7 | |
79 | vfmadd213ps _sPoly_3(%rax), %zmm8, %zmm7 | |
80 | vfmadd213ps _sPoly_2(%rax), %zmm8, %zmm7 | |
81 | vfmadd213ps _sPoly_1(%rax), %zmm8, %zmm7 | |
82 | vmulps %zmm8, %zmm7, %zmm9 | |
83 | ||
84 | /* polynomial evaluation end */ | |
85 | vfmadd213ps %zmm8, %zmm8, %zmm9 | |
86 | ||
87 | /* | |
88 | final reconstruction: | |
89 | add exponent_value*log2 to polynomial result | |
90 | */ | |
91 | vfmadd132ps _sLn2(%rax), %zmm9, %zmm1 | |
92 | testl %ecx, %ecx | |
93 | jne .LBL_1_3 | |
94 | ||
95 | .LBL_1_2: | |
96 | cfi_remember_state | |
97 | vmovaps %zmm1, %zmm0 | |
98 | movq %rbp, %rsp | |
99 | cfi_def_cfa_register (%rsp) | |
100 | popq %rbp | |
101 | cfi_adjust_cfa_offset (-8) | |
102 | cfi_restore (%rbp) | |
103 | ret | |
104 | ||
105 | .LBL_1_3: | |
106 | cfi_restore_state | |
107 | vmovups %zmm0, 1152(%rsp) | |
108 | vmovups %zmm1, 1216(%rsp) | |
109 | je .LBL_1_2 | |
110 | ||
111 | xorb %dl, %dl | |
112 | kmovw %k4, 1048(%rsp) | |
113 | xorl %eax, %eax | |
114 | kmovw %k5, 1040(%rsp) | |
115 | kmovw %k6, 1032(%rsp) | |
116 | kmovw %k7, 1024(%rsp) | |
117 | vmovups %zmm16, 960(%rsp) | |
118 | vmovups %zmm17, 896(%rsp) | |
119 | vmovups %zmm18, 832(%rsp) | |
120 | vmovups %zmm19, 768(%rsp) | |
121 | vmovups %zmm20, 704(%rsp) | |
122 | vmovups %zmm21, 640(%rsp) | |
123 | vmovups %zmm22, 576(%rsp) | |
124 | vmovups %zmm23, 512(%rsp) | |
125 | vmovups %zmm24, 448(%rsp) | |
126 | vmovups %zmm25, 384(%rsp) | |
127 | vmovups %zmm26, 320(%rsp) | |
128 | vmovups %zmm27, 256(%rsp) | |
129 | vmovups %zmm28, 192(%rsp) | |
130 | vmovups %zmm29, 128(%rsp) | |
131 | vmovups %zmm30, 64(%rsp) | |
132 | vmovups %zmm31, (%rsp) | |
133 | movq %rsi, 1064(%rsp) | |
134 | movq %rdi, 1056(%rsp) | |
135 | movq %r12, 1096(%rsp) | |
136 | cfi_offset_rel_rsp (12, 1096) | |
137 | movb %dl, %r12b | |
138 | movq %r13, 1088(%rsp) | |
139 | cfi_offset_rel_rsp (13, 1088) | |
140 | movl %ecx, %r13d | |
141 | movq %r14, 1080(%rsp) | |
142 | cfi_offset_rel_rsp (14, 1080) | |
143 | movl %eax, %r14d | |
144 | movq %r15, 1072(%rsp) | |
145 | cfi_offset_rel_rsp (15, 1072) | |
146 | cfi_remember_state | |
147 | ||
148 | .LBL_1_6: | |
149 | btl %r14d, %r13d | |
150 | jc .LBL_1_12 | |
151 | ||
152 | .LBL_1_7: | |
153 | lea 1(%r14), %esi | |
154 | btl %esi, %r13d | |
155 | jc .LBL_1_10 | |
156 | ||
157 | .LBL_1_8: | |
158 | addb $1, %r12b | |
159 | addl $2, %r14d | |
160 | cmpb $16, %r12b | |
161 | jb .LBL_1_6 | |
162 | ||
163 | kmovw 1048(%rsp), %k4 | |
164 | movq 1064(%rsp), %rsi | |
165 | kmovw 1040(%rsp), %k5 | |
166 | movq 1056(%rsp), %rdi | |
167 | kmovw 1032(%rsp), %k6 | |
168 | movq 1096(%rsp), %r12 | |
169 | cfi_restore (%r12) | |
170 | movq 1088(%rsp), %r13 | |
171 | cfi_restore (%r13) | |
172 | kmovw 1024(%rsp), %k7 | |
173 | vmovups 960(%rsp), %zmm16 | |
174 | vmovups 896(%rsp), %zmm17 | |
175 | vmovups 832(%rsp), %zmm18 | |
176 | vmovups 768(%rsp), %zmm19 | |
177 | vmovups 704(%rsp), %zmm20 | |
178 | vmovups 640(%rsp), %zmm21 | |
179 | vmovups 576(%rsp), %zmm22 | |
180 | vmovups 512(%rsp), %zmm23 | |
181 | vmovups 448(%rsp), %zmm24 | |
182 | vmovups 384(%rsp), %zmm25 | |
183 | vmovups 320(%rsp), %zmm26 | |
184 | vmovups 256(%rsp), %zmm27 | |
185 | vmovups 192(%rsp), %zmm28 | |
186 | vmovups 128(%rsp), %zmm29 | |
187 | vmovups 64(%rsp), %zmm30 | |
188 | vmovups (%rsp), %zmm31 | |
189 | movq 1080(%rsp), %r14 | |
190 | cfi_restore (%r14) | |
191 | movq 1072(%rsp), %r15 | |
192 | cfi_restore (%r15) | |
193 | vmovups 1216(%rsp), %zmm1 | |
194 | jmp .LBL_1_2 | |
195 | ||
196 | .LBL_1_10: | |
197 | cfi_restore_state | |
198 | movzbl %r12b, %r15d | |
199 | vmovss 1156(%rsp,%r15,8), %xmm0 | |
d0007dc5 | 200 | call JUMPTARGET(logf) |
774488f8 AS |
201 | vmovss %xmm0, 1220(%rsp,%r15,8) |
202 | jmp .LBL_1_8 | |
203 | ||
204 | .LBL_1_12: | |
205 | movzbl %r12b, %r15d | |
206 | vmovss 1152(%rsp,%r15,8), %xmm0 | |
d0007dc5 | 207 | call JUMPTARGET(logf) |
774488f8 AS |
208 | vmovss %xmm0, 1216(%rsp,%r15,8) |
209 | jmp .LBL_1_7 | |
210 | #endif | |
211 | END (_ZGVeN16v_logf_knl) | |
212 | ||
213 | ENTRY (_ZGVeN16v_logf_skx) | |
f43cb35c | 214 | #ifndef HAVE_AVX512DQ_ASM_SUPPORT |
774488f8 AS |
215 | WRAPPER_IMPL_AVX512 _ZGVdN8v_logf |
216 | #else | |
217 | /* | |
218 | ALGORITHM DESCRIPTION: | |
219 | ||
220 | log(x) = exponent_x*log(2) + log(mantissa_x), if mantissa_x<4/3 | |
221 | log(x) = (exponent_x+1)*log(2) + log(0.5*mantissa_x), if mantissa_x>4/3 | |
222 | ||
223 | R = mantissa_x - 1, if mantissa_x<4/3 | |
224 | R = 0.5*mantissa_x - 1, if mantissa_x>4/3 | |
225 | |R|< 1/3 | |
226 | ||
227 | log(1+R) is approximated as a polynomial: degree 9 for 1-ulp, | |
228 | degree 7 for 4-ulp, degree 3 for half-precision. */ | |
229 | ||
230 | pushq %rbp | |
231 | cfi_adjust_cfa_offset (8) | |
232 | cfi_rel_offset (%rbp, 0) | |
233 | movq %rsp, %rbp | |
234 | cfi_def_cfa_register (%rbp) | |
235 | andq $-64, %rsp | |
236 | subq $1280, %rsp | |
237 | movq __svml_slog_data@GOTPCREL(%rip), %rax | |
238 | vmovups .L_2il0floatpacket.7(%rip), %zmm6 | |
239 | vmovups _iBrkValue(%rax), %zmm4 | |
240 | vmovups _sPoly_7(%rax), %zmm8 | |
241 | ||
242 | /* | |
243 | check for working range, | |
244 | set special argument mask (denormals/zero/Inf/NaN) | |
245 | */ | |
246 | vpaddd _iHiDelta(%rax), %zmm0, %zmm1 | |
247 | ||
248 | /* reduction: compute r,n */ | |
249 | vpsubd %zmm4, %zmm0, %zmm2 | |
250 | vpcmpd $5, _iLoRange(%rax), %zmm1, %k1 | |
251 | ||
252 | /* exponent_x (mantissa_x<4/3) or exponent_x+1 (mantissa_x>4/3) */ | |
253 | vpsrad $23, %zmm2, %zmm5 | |
254 | vpandd _iOffExpoMask(%rax), %zmm2, %zmm3 | |
255 | ||
256 | /* mantissa_x (mantissa_x<4/3), or 0.5*mantissa_x (mantissa_x>4/3) */ | |
257 | vpaddd %zmm4, %zmm3, %zmm7 | |
258 | ||
259 | /* reduced argument R */ | |
260 | vsubps _sOne(%rax), %zmm7, %zmm9 | |
261 | ||
262 | /* polynomial evaluation starts here */ | |
263 | vfmadd213ps _sPoly_6(%rax), %zmm9, %zmm8 | |
264 | vfmadd213ps _sPoly_5(%rax), %zmm9, %zmm8 | |
265 | vfmadd213ps _sPoly_4(%rax), %zmm9, %zmm8 | |
266 | vfmadd213ps _sPoly_3(%rax), %zmm9, %zmm8 | |
267 | vfmadd213ps _sPoly_2(%rax), %zmm9, %zmm8 | |
268 | vfmadd213ps _sPoly_1(%rax), %zmm9, %zmm8 | |
269 | vmulps %zmm9, %zmm8, %zmm10 | |
270 | ||
271 | /* polynomial evaluation end */ | |
272 | vfmadd213ps %zmm9, %zmm9, %zmm10 | |
273 | vpandnd %zmm1, %zmm1, %zmm6{%k1} | |
274 | vptestmd %zmm6, %zmm6, %k0 | |
275 | vcvtdq2ps {rn-sae}, %zmm5, %zmm1 | |
276 | kmovw %k0, %ecx | |
277 | ||
278 | /* | |
279 | final reconstruction: | |
280 | add exponent_value*log2 to polynomial result | |
281 | */ | |
282 | vfmadd132ps _sLn2(%rax), %zmm10, %zmm1 | |
283 | testl %ecx, %ecx | |
284 | jne .LBL_2_3 | |
285 | ||
286 | .LBL_2_2: | |
287 | cfi_remember_state | |
288 | vmovaps %zmm1, %zmm0 | |
289 | movq %rbp, %rsp | |
290 | cfi_def_cfa_register (%rsp) | |
291 | popq %rbp | |
292 | cfi_adjust_cfa_offset (-8) | |
293 | cfi_restore (%rbp) | |
294 | ret | |
295 | ||
296 | .LBL_2_3: | |
297 | cfi_restore_state | |
298 | vmovups %zmm0, 1152(%rsp) | |
299 | vmovups %zmm1, 1216(%rsp) | |
300 | je .LBL_2_2 | |
301 | ||
302 | xorb %dl, %dl | |
303 | xorl %eax, %eax | |
304 | kmovw %k4, 1048(%rsp) | |
305 | kmovw %k5, 1040(%rsp) | |
306 | kmovw %k6, 1032(%rsp) | |
307 | kmovw %k7, 1024(%rsp) | |
308 | vmovups %zmm16, 960(%rsp) | |
309 | vmovups %zmm17, 896(%rsp) | |
310 | vmovups %zmm18, 832(%rsp) | |
311 | vmovups %zmm19, 768(%rsp) | |
312 | vmovups %zmm20, 704(%rsp) | |
313 | vmovups %zmm21, 640(%rsp) | |
314 | vmovups %zmm22, 576(%rsp) | |
315 | vmovups %zmm23, 512(%rsp) | |
316 | vmovups %zmm24, 448(%rsp) | |
317 | vmovups %zmm25, 384(%rsp) | |
318 | vmovups %zmm26, 320(%rsp) | |
319 | vmovups %zmm27, 256(%rsp) | |
320 | vmovups %zmm28, 192(%rsp) | |
321 | vmovups %zmm29, 128(%rsp) | |
322 | vmovups %zmm30, 64(%rsp) | |
323 | vmovups %zmm31, (%rsp) | |
324 | movq %rsi, 1064(%rsp) | |
325 | movq %rdi, 1056(%rsp) | |
326 | movq %r12, 1096(%rsp) | |
327 | cfi_offset_rel_rsp (12, 1096) | |
328 | movb %dl, %r12b | |
329 | movq %r13, 1088(%rsp) | |
330 | cfi_offset_rel_rsp (13, 1088) | |
331 | movl %ecx, %r13d | |
332 | movq %r14, 1080(%rsp) | |
333 | cfi_offset_rel_rsp (14, 1080) | |
334 | movl %eax, %r14d | |
335 | movq %r15, 1072(%rsp) | |
336 | cfi_offset_rel_rsp (15, 1072) | |
337 | cfi_remember_state | |
338 | ||
339 | .LBL_2_6: | |
340 | btl %r14d, %r13d | |
341 | jc .LBL_2_12 | |
342 | ||
343 | .LBL_2_7: | |
344 | lea 1(%r14), %esi | |
345 | btl %esi, %r13d | |
346 | jc .LBL_2_10 | |
347 | ||
348 | .LBL_2_8: | |
349 | incb %r12b | |
350 | addl $2, %r14d | |
351 | cmpb $16, %r12b | |
352 | jb .LBL_2_6 | |
353 | ||
354 | kmovw 1048(%rsp), %k4 | |
355 | kmovw 1040(%rsp), %k5 | |
356 | kmovw 1032(%rsp), %k6 | |
357 | kmovw 1024(%rsp), %k7 | |
358 | vmovups 960(%rsp), %zmm16 | |
359 | vmovups 896(%rsp), %zmm17 | |
360 | vmovups 832(%rsp), %zmm18 | |
361 | vmovups 768(%rsp), %zmm19 | |
362 | vmovups 704(%rsp), %zmm20 | |
363 | vmovups 640(%rsp), %zmm21 | |
364 | vmovups 576(%rsp), %zmm22 | |
365 | vmovups 512(%rsp), %zmm23 | |
366 | vmovups 448(%rsp), %zmm24 | |
367 | vmovups 384(%rsp), %zmm25 | |
368 | vmovups 320(%rsp), %zmm26 | |
369 | vmovups 256(%rsp), %zmm27 | |
370 | vmovups 192(%rsp), %zmm28 | |
371 | vmovups 128(%rsp), %zmm29 | |
372 | vmovups 64(%rsp), %zmm30 | |
373 | vmovups (%rsp), %zmm31 | |
374 | vmovups 1216(%rsp), %zmm1 | |
375 | movq 1064(%rsp), %rsi | |
376 | movq 1056(%rsp), %rdi | |
377 | movq 1096(%rsp), %r12 | |
378 | cfi_restore (%r12) | |
379 | movq 1088(%rsp), %r13 | |
380 | cfi_restore (%r13) | |
381 | movq 1080(%rsp), %r14 | |
382 | cfi_restore (%r14) | |
383 | movq 1072(%rsp), %r15 | |
384 | cfi_restore (%r15) | |
385 | jmp .LBL_2_2 | |
386 | ||
387 | .LBL_2_10: | |
388 | cfi_restore_state | |
389 | movzbl %r12b, %r15d | |
390 | vmovss 1156(%rsp,%r15,8), %xmm0 | |
391 | vzeroupper | |
392 | vmovss 1156(%rsp,%r15,8), %xmm0 | |
393 | ||
d0007dc5 | 394 | call JUMPTARGET(logf) |
774488f8 AS |
395 | |
396 | vmovss %xmm0, 1220(%rsp,%r15,8) | |
397 | jmp .LBL_2_8 | |
398 | ||
399 | .LBL_2_12: | |
400 | movzbl %r12b, %r15d | |
401 | vmovss 1152(%rsp,%r15,8), %xmm0 | |
402 | vzeroupper | |
403 | vmovss 1152(%rsp,%r15,8), %xmm0 | |
404 | ||
d0007dc5 | 405 | call JUMPTARGET(logf) |
774488f8 AS |
406 | |
407 | vmovss %xmm0, 1216(%rsp,%r15,8) | |
408 | jmp .LBL_2_7 | |
409 | ||
410 | #endif | |
411 | END (_ZGVeN16v_logf_skx) | |
412 | ||
413 | .section .rodata, "a" | |
414 | .L_2il0floatpacket.7: | |
415 | .long 0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff,0xffffffff | |
416 | .type .L_2il0floatpacket.7,@object |