1 /* Function log2 vectorized with AVX-512.
2 Copyright (C) 2021-2022 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 * Get short reciprocal approximation Rcp ~ 1/mantissa(x)
24 * log2(x) = k - log2(Rcp) + poly_approximation(R)
25 * log2(Rcp) is tabulated
30 /* Offsets for data table __svml_dlog2_data_internal_avx512
35 #define poly_coeff9 256
36 #define poly_coeff8 320
37 #define poly_coeff7 384
38 #define poly_coeff6 448
39 #define poly_coeff5 512
40 #define poly_coeff4 576
41 #define poly_coeff3 640
42 #define poly_coeff2 704
43 #define poly_coeff1 768
48 .section .text.evex512,"ax",@progbits
49 ENTRY(_ZGVeN8v_log2_skx)
51 cfi_def_cfa_offset(16)
58 vgetmantpd $8, {sae}, %zmm7, %zmm6
59 vmovups One+__svml_dlog2_data_internal_avx512(%rip), %zmm2
60 vmovups poly_coeff5+__svml_dlog2_data_internal_avx512(%rip), %zmm12
61 vmovups poly_coeff3+__svml_dlog2_data_internal_avx512(%rip), %zmm13
63 /* Start polynomial evaluation */
64 vmovups poly_coeff9+__svml_dlog2_data_internal_avx512(%rip), %zmm10
65 vmovups poly_coeff8+__svml_dlog2_data_internal_avx512(%rip), %zmm0
66 vmovups poly_coeff7+__svml_dlog2_data_internal_avx512(%rip), %zmm11
67 vmovups poly_coeff6+__svml_dlog2_data_internal_avx512(%rip), %zmm14
69 /* Prepare exponent correction: DblRcp<0.75? */
70 vmovups C075+__svml_dlog2_data_internal_avx512(%rip), %zmm1
73 vmovups __svml_dlog2_data_internal_avx512(%rip), %zmm4
76 vgetexppd {sae}, %zmm7, %zmm5
78 /* DblRcp ~ 1/Mantissa */
82 vfpclasspd $94, %zmm7, %k0
84 /* round DblRcp to 4 fractional bits (RN mode, no Precision exception) */
85 vrndscalepd $88, {sae}, %zmm8, %zmm3
86 vmovups poly_coeff4+__svml_dlog2_data_internal_avx512(%rip), %zmm8
89 /* Reduced argument: R = DblRcp*Mantissa - 1 */
90 vfmsub213pd {rn-sae}, %zmm2, %zmm3, %zmm6
91 vcmppd $17, {sae}, %zmm1, %zmm3, %k1
92 vfmadd231pd {rn-sae}, %zmm6, %zmm12, %zmm8
93 vmovups poly_coeff2+__svml_dlog2_data_internal_avx512(%rip), %zmm12
94 vfmadd231pd {rn-sae}, %zmm6, %zmm10, %zmm0
95 vfmadd231pd {rn-sae}, %zmm6, %zmm11, %zmm14
96 vmovups poly_coeff1+__svml_dlog2_data_internal_avx512(%rip), %zmm1
99 vmulpd {rn-sae}, %zmm6, %zmm6, %zmm15
100 vfmadd231pd {rn-sae}, %zmm6, %zmm13, %zmm12
102 /* Prepare table index */
103 vpsrlq $48, %zmm3, %zmm9
105 /* add 1 to Expon if DblRcp<0.75 */
106 vaddpd {rn-sae}, %zmm2, %zmm5, %zmm5{%k1}
107 vmulpd {rn-sae}, %zmm15, %zmm15, %zmm13
108 vfmadd213pd {rn-sae}, %zmm14, %zmm15, %zmm0
109 vfmadd213pd {rn-sae}, %zmm12, %zmm15, %zmm8
110 vpermt2pd Log_tbl+64+__svml_dlog2_data_internal_avx512(%rip), %zmm9, %zmm4
113 vfmadd213pd {rn-sae}, %zmm8, %zmm13, %zmm0
114 vfmadd213pd {rn-sae}, %zmm1, %zmm6, %zmm0
115 vfmadd213pd {rn-sae}, %zmm4, %zmm0, %zmm6
116 vaddpd {rn-sae}, %zmm6, %zmm5, %zmm0
119 /* Go to special inputs processing branch */
120 jne L(SPECIAL_VALUES_BRANCH)
121 # LOE rbx r12 r13 r14 r15 edx zmm0 zmm7
124 * and exit the function
140 L(SPECIAL_VALUES_BRANCH):
141 vmovups %zmm7, 64(%rsp)
142 vmovups %zmm0, 128(%rsp)
143 # LOE rbx r12 r13 r14 r15 edx zmm0
146 # LOE rbx r12 r13 r14 r15 eax edx
150 /* DW_CFA_expression: r12 (r12) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -64; DW_OP_and; DW_OP_const4s: -176; DW_OP_plus) */
151 .cfi_escape 0x10, 0x0c, 0x0e, 0x38, 0x1c, 0x0d, 0xc0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0x50, 0xff, 0xff, 0xff, 0x22
154 /* DW_CFA_expression: r13 (r13) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -64; DW_OP_and; DW_OP_const4s: -184; DW_OP_plus) */
155 .cfi_escape 0x10, 0x0d, 0x0e, 0x38, 0x1c, 0x0d, 0xc0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0x48, 0xff, 0xff, 0xff, 0x22
158 /* DW_CFA_expression: r14 (r14) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -64; DW_OP_and; DW_OP_const4s: -192; DW_OP_plus) */
159 .cfi_escape 0x10, 0x0e, 0x0e, 0x38, 0x1c, 0x0d, 0xc0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0x40, 0xff, 0xff, 0xff, 0x22
160 # LOE rbx r15 r12d r13d
169 /* Call scalar math function */
170 jc L(SCALAR_MATH_CALL)
171 # LOE rbx r15 r12d r13d
177 L(SPECIAL_VALUES_LOOP):
181 /* Check bits in range mask */
182 jl L(RANGEMASK_CHECK)
183 # LOE rbx r15 r12d r13d
191 vmovups 128(%rsp), %zmm0
195 /* DW_CFA_expression: r12 (r12) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -64; DW_OP_and; DW_OP_const4s: -176; DW_OP_plus) */
196 .cfi_escape 0x10, 0x0c, 0x0e, 0x38, 0x1c, 0x0d, 0xc0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0x50, 0xff, 0xff, 0xff, 0x22
197 /* DW_CFA_expression: r13 (r13) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -64; DW_OP_and; DW_OP_const4s: -184; DW_OP_plus) */
198 .cfi_escape 0x10, 0x0d, 0x0e, 0x38, 0x1c, 0x0d, 0xc0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0x48, 0xff, 0xff, 0xff, 0x22
199 /* DW_CFA_expression: r14 (r14) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -64; DW_OP_and; DW_OP_const4s: -192; DW_OP_plus) */
200 .cfi_escape 0x10, 0x0e, 0x0e, 0x38, 0x1c, 0x0d, 0xc0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0x40, 0xff, 0xff, 0xff, 0x22
201 # LOE rbx r12 r13 r14 r15 zmm0
203 /* Scalar math fucntion call
204 * to process special input
209 movsd 64(%rsp,%r14,8), %xmm0
211 # LOE rbx r14 r15 r12d r13d xmm0
213 movsd %xmm0, 128(%rsp,%r14,8)
215 /* Process special inputs in loop */
216 jmp L(SPECIAL_VALUES_LOOP)
217 # LOE rbx r15 r12d r13d
218 END(_ZGVeN8v_log2_skx)
220 .section .rodata, "a"
223 #ifdef __svml_dlog2_data_internal_avx512_typedef
224 typedef unsigned int VUINT32;
226 __declspec(align(64)) VUINT32 Log_tbl[16][2];
227 __declspec(align(64)) VUINT32 One[8][2];
228 __declspec(align(64)) VUINT32 C075[8][2];
229 __declspec(align(64)) VUINT32 poly_coeff9[8][2];
230 __declspec(align(64)) VUINT32 poly_coeff8[8][2];
231 __declspec(align(64)) VUINT32 poly_coeff7[8][2];
232 __declspec(align(64)) VUINT32 poly_coeff6[8][2];
233 __declspec(align(64)) VUINT32 poly_coeff5[8][2];
234 __declspec(align(64)) VUINT32 poly_coeff4[8][2];
235 __declspec(align(64)) VUINT32 poly_coeff3[8][2];
236 __declspec(align(64)) VUINT32 poly_coeff2[8][2];
237 __declspec(align(64)) VUINT32 poly_coeff1[8][2];
238 } __svml_dlog2_data_internal_avx512;
240 __svml_dlog2_data_internal_avx512:
242 .quad 0x0000000000000000
243 .quad 0xbfb663f6fac91316
244 .quad 0xbfc5c01a39fbd688
245 .quad 0xbfcfbc16b902680a
246 .quad 0xbfd49a784bcd1b8b
247 .quad 0xbfd91bba891f1709
248 .quad 0xbfdd6753e032ea0f
249 .quad 0xbfe0c10500d63aa6
250 .quad 0x3fda8ff971810a5e
251 .quad 0x3fd6cb0f6865c8ea
252 .quad 0x3fd32bfee370ee68
253 .quad 0x3fcf5fd8a9063e35
254 .quad 0x3fc8a8980abfbd32
255 .quad 0x3fc22dadc2ab3497
256 .quad 0x3fb7d60496cfbb4c
257 .quad 0x3fa77394c9d958d5
260 .quad 0x3ff0000000000000, 0x3ff0000000000000, 0x3ff0000000000000, 0x3ff0000000000000, 0x3ff0000000000000, 0x3ff0000000000000, 0x3ff0000000000000, 0x3ff0000000000000
263 .quad 0x3fe8000000000000, 0x3fe8000000000000, 0x3fe8000000000000, 0x3fe8000000000000, 0x3fe8000000000000, 0x3fe8000000000000, 0x3fe8000000000000, 0x3fe8000000000000
264 /*== poly_coeff9 ==*/
266 .quad 0x3fc4904bda0e1d12, 0x3fc4904bda0e1d12, 0x3fc4904bda0e1d12, 0x3fc4904bda0e1d12, 0x3fc4904bda0e1d12, 0x3fc4904bda0e1d12, 0x3fc4904bda0e1d12, 0x3fc4904bda0e1d12
267 /*== poly_coeff8 ==*/
269 .quad 0xbfc71fb84deb5cce, 0xbfc71fb84deb5cce, 0xbfc71fb84deb5cce, 0xbfc71fb84deb5cce, 0xbfc71fb84deb5cce, 0xbfc71fb84deb5cce, 0xbfc71fb84deb5cce, 0xbfc71fb84deb5cce
270 /*== poly_coeff7 ==*/
272 .quad 0x3fca617351818613, 0x3fca617351818613, 0x3fca617351818613, 0x3fca617351818613, 0x3fca617351818613, 0x3fca617351818613, 0x3fca617351818613, 0x3fca617351818613
273 /*== poly_coeff6 ==*/
275 .quad 0xbfcec707e4e3144c, 0xbfcec707e4e3144c, 0xbfcec707e4e3144c, 0xbfcec707e4e3144c, 0xbfcec707e4e3144c, 0xbfcec707e4e3144c, 0xbfcec707e4e3144c, 0xbfcec707e4e3144c
276 /*== poly_coeff5 ==*/
278 .quad 0x3fd2776c5114d91a, 0x3fd2776c5114d91a, 0x3fd2776c5114d91a, 0x3fd2776c5114d91a, 0x3fd2776c5114d91a, 0x3fd2776c5114d91a, 0x3fd2776c5114d91a, 0x3fd2776c5114d91a
279 /*== poly_coeff4 ==*/
281 .quad 0xbfd71547653d0f8d, 0xbfd71547653d0f8d, 0xbfd71547653d0f8d, 0xbfd71547653d0f8d, 0xbfd71547653d0f8d, 0xbfd71547653d0f8d, 0xbfd71547653d0f8d, 0xbfd71547653d0f8d
282 /*== poly_coeff3 ==*/
284 .quad 0x3fdec709dc3a029f, 0x3fdec709dc3a029f, 0x3fdec709dc3a029f, 0x3fdec709dc3a029f, 0x3fdec709dc3a029f, 0x3fdec709dc3a029f, 0x3fdec709dc3a029f, 0x3fdec709dc3a029f
285 /*== poly_coeff2 ==*/
287 .quad 0xbfe71547652b82d4, 0xbfe71547652b82d4, 0xbfe71547652b82d4, 0xbfe71547652b82d4, 0xbfe71547652b82d4, 0xbfe71547652b82d4, 0xbfe71547652b82d4, 0xbfe71547652b82d4
288 /*== poly_coeff1 ==*/
290 .quad 0x3ff71547652b82fe, 0x3ff71547652b82fe, 0x3ff71547652b82fe, 0x3ff71547652b82fe, 0x3ff71547652b82fe, 0x3ff71547652b82fe, 0x3ff71547652b82fe, 0x3ff71547652b82fe
292 .type __svml_dlog2_data_internal_avx512,@object
293 .size __svml_dlog2_data_internal_avx512,.-__svml_dlog2_data_internal_avx512