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