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.
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_logf_data.h"
21 #include "svml_s_wrapper_impl.h"
23 .section .text.evex512, "ax", @progbits
24 ENTRY (_ZGVeN16v_logf_knl)
26 ALGORITHM DESCRIPTION:
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
31 R = mantissa_x - 1, if mantissa_x<4/3
32 R = 0.5*mantissa_x - 1, if mantissa_x>4/3
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. */
39 cfi_adjust_cfa_offset (8)
40 cfi_rel_offset (%rbp, 0)
42 cfi_def_cfa_register (%rbp)
45 movq __svml_slog_data@GOTPCREL(%rip), %rax
48 /* reduction: compute r,n */
49 vpsubd _iBrkValue(%rax), %zmm0, %zmm2
50 vmovups _sPoly_7(%rax), %zmm7
51 vpandd _iOffExpoMask(%rax), %zmm2, %zmm3
53 /* exponent_x (mantissa_x<4/3) or exponent_x+1 (mantissa_x>4/3) */
54 vpsrad $23, %zmm2, %zmm4
56 /* check for working range,
57 set special argument mask (denormals/zero/Inf/NaN)
59 vpaddd _iHiDelta(%rax), %zmm0, %zmm1
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
66 /* reduced argument R */
67 vsubps _sOne(%rax), %zmm6, %zmm8
68 vpbroadcastd %ecx, %zmm5{%k1}{z}
70 /* polynomial evaluation starts here */
71 vfmadd213ps _sPoly_6(%rax), %zmm8, %zmm7
72 vptestmd %zmm5, %zmm5, %k0
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
81 /* polynomial evaluation end */
82 vfmadd213ps %zmm8, %zmm8, %zmm9
86 add exponent_value*log2 to polynomial result
88 vfmadd132ps _sLn2(%rax), %zmm9, %zmm1
96 cfi_def_cfa_register (%rsp)
98 cfi_adjust_cfa_offset (-8)
104 vmovups %zmm0, 1152(%rsp)
105 vmovups %zmm1, 1216(%rsp)
109 kmovw %k4, 1048(%rsp)
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)
135 movq %r13, 1088(%rsp)
136 cfi_offset_rel_rsp (13, 1088)
138 movq %r14, 1080(%rsp)
139 cfi_offset_rel_rsp (14, 1080)
141 movq %r15, 1072(%rsp)
142 cfi_offset_rel_rsp (15, 1072)
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
167 movq 1088(%rsp), %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
188 movq 1072(%rsp), %r15
190 vmovups 1216(%rsp), %zmm1
196 vmovss 1156(%rsp,%r15,8), %xmm0
197 call JUMPTARGET(logf)
198 vmovss %xmm0, 1220(%rsp,%r15,8)
203 vmovss 1152(%rsp,%r15,8), %xmm0
204 call JUMPTARGET(logf)
205 vmovss %xmm0, 1216(%rsp,%r15,8)
207 END (_ZGVeN16v_logf_knl)
209 ENTRY (_ZGVeN16v_logf_skx)
211 ALGORITHM DESCRIPTION:
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
216 R = mantissa_x - 1, if mantissa_x<4/3
217 R = 0.5*mantissa_x - 1, if mantissa_x>4/3
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. */
224 cfi_adjust_cfa_offset (8)
225 cfi_rel_offset (%rbp, 0)
227 cfi_def_cfa_register (%rbp)
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
236 check for working range,
237 set special argument mask (denormals/zero/Inf/NaN)
239 vpaddd _iHiDelta(%rax), %zmm0, %zmm1
241 /* reduction: compute r,n */
242 vpsubd %zmm4, %zmm0, %zmm2
243 vpcmpd $5, _iLoRange(%rax), %zmm1, %k1
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
249 /* mantissa_x (mantissa_x<4/3), or 0.5*mantissa_x (mantissa_x>4/3) */
250 vpaddd %zmm4, %zmm3, %zmm7
252 /* reduced argument R */
253 vsubps _sOne(%rax), %zmm7, %zmm9
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
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
272 final reconstruction:
273 add exponent_value*log2 to polynomial result
275 vfmadd132ps _sLn2(%rax), %zmm10, %zmm1
283 cfi_def_cfa_register (%rsp)
285 cfi_adjust_cfa_offset (-8)
291 vmovups %zmm0, 1152(%rsp)
292 vmovups %zmm1, 1216(%rsp)
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)
322 movq %r13, 1088(%rsp)
323 cfi_offset_rel_rsp (13, 1088)
325 movq %r14, 1080(%rsp)
326 cfi_offset_rel_rsp (14, 1080)
328 movq %r15, 1072(%rsp)
329 cfi_offset_rel_rsp (15, 1072)
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
372 movq 1088(%rsp), %r13
374 movq 1080(%rsp), %r14
376 movq 1072(%rsp), %r15
383 vmovss 1156(%rsp,%r15,8), %xmm0
385 vmovss 1156(%rsp,%r15,8), %xmm0
387 call JUMPTARGET(logf)
389 vmovss %xmm0, 1220(%rsp,%r15,8)
394 vmovss 1152(%rsp,%r15,8), %xmm0
396 vmovss 1152(%rsp,%r15,8), %xmm0
398 call JUMPTARGET(logf)
400 vmovss %xmm0, 1216(%rsp,%r15,8)
403 END (_ZGVeN16v_logf_skx)