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
47 .section .text.evex512, "ax", @progbits
48 ENTRY(_ZGVeN8v_log2_skx)
50 cfi_def_cfa_offset(16)
57 vgetmantpd $8, {sae}, %zmm7, %zmm6
58 vmovups One+__svml_dlog2_data_internal_avx512(%rip), %zmm2
59 vmovups poly_coeff5+__svml_dlog2_data_internal_avx512(%rip), %zmm12
60 vmovups poly_coeff3+__svml_dlog2_data_internal_avx512(%rip), %zmm13
62 /* Start polynomial evaluation */
63 vmovups poly_coeff9+__svml_dlog2_data_internal_avx512(%rip), %zmm10
64 vmovups poly_coeff8+__svml_dlog2_data_internal_avx512(%rip), %zmm0
65 vmovups poly_coeff7+__svml_dlog2_data_internal_avx512(%rip), %zmm11
66 vmovups poly_coeff6+__svml_dlog2_data_internal_avx512(%rip), %zmm14
68 /* Prepare exponent correction: DblRcp<0.75? */
69 vmovups C075+__svml_dlog2_data_internal_avx512(%rip), %zmm1
72 vmovups __svml_dlog2_data_internal_avx512(%rip), %zmm4
75 vgetexppd {sae}, %zmm7, %zmm5
77 /* DblRcp ~ 1/Mantissa */
81 vfpclasspd $94, %zmm7, %k0
83 /* round DblRcp to 4 fractional bits (RN mode, no Precision exception) */
84 vrndscalepd $88, {sae}, %zmm8, %zmm3
85 vmovups poly_coeff4+__svml_dlog2_data_internal_avx512(%rip), %zmm8
88 /* Reduced argument: R = DblRcp*Mantissa - 1 */
89 vfmsub213pd {rn-sae}, %zmm2, %zmm3, %zmm6
90 vcmppd $17, {sae}, %zmm1, %zmm3, %k1
91 vfmadd231pd {rn-sae}, %zmm6, %zmm12, %zmm8
92 vmovups poly_coeff2+__svml_dlog2_data_internal_avx512(%rip), %zmm12
93 vfmadd231pd {rn-sae}, %zmm6, %zmm10, %zmm0
94 vfmadd231pd {rn-sae}, %zmm6, %zmm11, %zmm14
95 vmovups poly_coeff1+__svml_dlog2_data_internal_avx512(%rip), %zmm1
98 vmulpd {rn-sae}, %zmm6, %zmm6, %zmm15
99 vfmadd231pd {rn-sae}, %zmm6, %zmm13, %zmm12
101 /* Prepare table index */
102 vpsrlq $48, %zmm3, %zmm9
104 /* add 1 to Expon if DblRcp<0.75 */
105 vaddpd {rn-sae}, %zmm2, %zmm5, %zmm5{%k1}
106 vmulpd {rn-sae}, %zmm15, %zmm15, %zmm13
107 vfmadd213pd {rn-sae}, %zmm14, %zmm15, %zmm0
108 vfmadd213pd {rn-sae}, %zmm12, %zmm15, %zmm8
109 vpermt2pd Log_tbl+64+__svml_dlog2_data_internal_avx512(%rip), %zmm9, %zmm4
112 vfmadd213pd {rn-sae}, %zmm8, %zmm13, %zmm0
113 vfmadd213pd {rn-sae}, %zmm1, %zmm6, %zmm0
114 vfmadd213pd {rn-sae}, %zmm4, %zmm0, %zmm6
115 vaddpd {rn-sae}, %zmm6, %zmm5, %zmm0
118 /* Go to special inputs processing branch */
119 jne L(SPECIAL_VALUES_BRANCH)
120 # LOE rbx r12 r13 r14 r15 edx zmm0 zmm7
123 * and exit the function
139 L(SPECIAL_VALUES_BRANCH):
140 vmovups %zmm7, 64(%rsp)
141 vmovups %zmm0, 128(%rsp)
142 # LOE rbx r12 r13 r14 r15 edx zmm0
145 # LOE rbx r12 r13 r14 r15 eax edx
149 /* 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) */
150 .cfi_escape 0x10, 0x0c, 0x0e, 0x38, 0x1c, 0x0d, 0xc0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0x50, 0xff, 0xff, 0xff, 0x22
153 /* 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) */
154 .cfi_escape 0x10, 0x0d, 0x0e, 0x38, 0x1c, 0x0d, 0xc0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0x48, 0xff, 0xff, 0xff, 0x22
157 /* 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) */
158 .cfi_escape 0x10, 0x0e, 0x0e, 0x38, 0x1c, 0x0d, 0xc0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0x40, 0xff, 0xff, 0xff, 0x22
159 # LOE rbx r15 r12d r13d
168 /* Call scalar math function */
169 jc L(SCALAR_MATH_CALL)
170 # LOE rbx r15 r12d r13d
176 L(SPECIAL_VALUES_LOOP):
180 /* Check bits in range mask */
181 jl L(RANGEMASK_CHECK)
182 # LOE rbx r15 r12d r13d
190 vmovups 128(%rsp), %zmm0
194 /* 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) */
195 .cfi_escape 0x10, 0x0c, 0x0e, 0x38, 0x1c, 0x0d, 0xc0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0x50, 0xff, 0xff, 0xff, 0x22
196 /* 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) */
197 .cfi_escape 0x10, 0x0d, 0x0e, 0x38, 0x1c, 0x0d, 0xc0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0x48, 0xff, 0xff, 0xff, 0x22
198 /* 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) */
199 .cfi_escape 0x10, 0x0e, 0x0e, 0x38, 0x1c, 0x0d, 0xc0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0x40, 0xff, 0xff, 0xff, 0x22
200 # LOE rbx r12 r13 r14 r15 zmm0
202 /* Scalar math fucntion call
203 * to process special input
208 vmovsd 64(%rsp, %r14, 8), %xmm0
210 # LOE rbx r14 r15 r12d r13d xmm0
212 vmovsd %xmm0, 128(%rsp, %r14, 8)
214 /* Process special inputs in loop */
215 jmp L(SPECIAL_VALUES_LOOP)
216 # LOE rbx r15 r12d r13d
217 END(_ZGVeN8v_log2_skx)
219 .section .rodata, "a"
222 #ifdef __svml_dlog2_data_internal_avx512_typedef
223 typedef unsigned int VUINT32;
225 __declspec(align(64)) VUINT32 Log_tbl[16][2];
226 __declspec(align(64)) VUINT32 One[8][2];
227 __declspec(align(64)) VUINT32 C075[8][2];
228 __declspec(align(64)) VUINT32 poly_coeff9[8][2];
229 __declspec(align(64)) VUINT32 poly_coeff8[8][2];
230 __declspec(align(64)) VUINT32 poly_coeff7[8][2];
231 __declspec(align(64)) VUINT32 poly_coeff6[8][2];
232 __declspec(align(64)) VUINT32 poly_coeff5[8][2];
233 __declspec(align(64)) VUINT32 poly_coeff4[8][2];
234 __declspec(align(64)) VUINT32 poly_coeff3[8][2];
235 __declspec(align(64)) VUINT32 poly_coeff2[8][2];
236 __declspec(align(64)) VUINT32 poly_coeff1[8][2];
237 } __svml_dlog2_data_internal_avx512;
239 __svml_dlog2_data_internal_avx512:
241 .quad 0x0000000000000000
242 .quad 0xbfb663f6fac91316
243 .quad 0xbfc5c01a39fbd688
244 .quad 0xbfcfbc16b902680a
245 .quad 0xbfd49a784bcd1b8b
246 .quad 0xbfd91bba891f1709
247 .quad 0xbfdd6753e032ea0f
248 .quad 0xbfe0c10500d63aa6
249 .quad 0x3fda8ff971810a5e
250 .quad 0x3fd6cb0f6865c8ea
251 .quad 0x3fd32bfee370ee68
252 .quad 0x3fcf5fd8a9063e35
253 .quad 0x3fc8a8980abfbd32
254 .quad 0x3fc22dadc2ab3497
255 .quad 0x3fb7d60496cfbb4c
256 .quad 0x3fa77394c9d958d5
259 .quad 0x3ff0000000000000, 0x3ff0000000000000, 0x3ff0000000000000, 0x3ff0000000000000, 0x3ff0000000000000, 0x3ff0000000000000, 0x3ff0000000000000, 0x3ff0000000000000
262 .quad 0x3fe8000000000000, 0x3fe8000000000000, 0x3fe8000000000000, 0x3fe8000000000000, 0x3fe8000000000000, 0x3fe8000000000000, 0x3fe8000000000000, 0x3fe8000000000000
265 .quad 0x3fc4904bda0e1d12, 0x3fc4904bda0e1d12, 0x3fc4904bda0e1d12, 0x3fc4904bda0e1d12, 0x3fc4904bda0e1d12, 0x3fc4904bda0e1d12, 0x3fc4904bda0e1d12, 0x3fc4904bda0e1d12
268 .quad 0xbfc71fb84deb5cce, 0xbfc71fb84deb5cce, 0xbfc71fb84deb5cce, 0xbfc71fb84deb5cce, 0xbfc71fb84deb5cce, 0xbfc71fb84deb5cce, 0xbfc71fb84deb5cce, 0xbfc71fb84deb5cce
271 .quad 0x3fca617351818613, 0x3fca617351818613, 0x3fca617351818613, 0x3fca617351818613, 0x3fca617351818613, 0x3fca617351818613, 0x3fca617351818613, 0x3fca617351818613
274 .quad 0xbfcec707e4e3144c, 0xbfcec707e4e3144c, 0xbfcec707e4e3144c, 0xbfcec707e4e3144c, 0xbfcec707e4e3144c, 0xbfcec707e4e3144c, 0xbfcec707e4e3144c, 0xbfcec707e4e3144c
277 .quad 0x3fd2776c5114d91a, 0x3fd2776c5114d91a, 0x3fd2776c5114d91a, 0x3fd2776c5114d91a, 0x3fd2776c5114d91a, 0x3fd2776c5114d91a, 0x3fd2776c5114d91a, 0x3fd2776c5114d91a
280 .quad 0xbfd71547653d0f8d, 0xbfd71547653d0f8d, 0xbfd71547653d0f8d, 0xbfd71547653d0f8d, 0xbfd71547653d0f8d, 0xbfd71547653d0f8d, 0xbfd71547653d0f8d, 0xbfd71547653d0f8d
283 .quad 0x3fdec709dc3a029f, 0x3fdec709dc3a029f, 0x3fdec709dc3a029f, 0x3fdec709dc3a029f, 0x3fdec709dc3a029f, 0x3fdec709dc3a029f, 0x3fdec709dc3a029f, 0x3fdec709dc3a029f
286 .quad 0xbfe71547652b82d4, 0xbfe71547652b82d4, 0xbfe71547652b82d4, 0xbfe71547652b82d4, 0xbfe71547652b82d4, 0xbfe71547652b82d4, 0xbfe71547652b82d4, 0xbfe71547652b82d4
289 .quad 0x3ff71547652b82fe, 0x3ff71547652b82fe, 0x3ff71547652b82fe, 0x3ff71547652b82fe, 0x3ff71547652b82fe, 0x3ff71547652b82fe, 0x3ff71547652b82fe, 0x3ff71547652b82fe
291 .type __svml_dlog2_data_internal_avx512, @object
292 .size __svml_dlog2_data_internal_avx512, .-__svml_dlog2_data_internal_avx512