1 | /* Function log2 vectorized with AVX-512. |
2 | Copyright (C) 2021-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 | /* |
20 | * ALGORITHM DESCRIPTION: |
21 | * |
22 | * Get short reciprocal approximation Rcp ~ 1/mantissa(x) |
23 | * R = Rcp*x - 1.0 |
24 | * log2(x) = k - log2(Rcp) + poly_approximation(R) |
25 | * log2(Rcp) is tabulated |
26 | * |
27 | * |
28 | */ |
29 | |
30 | /* Offsets for data table __svml_dlog2_data_internal_avx512 |
31 | */ |
32 | #define Log_tbl 0 |
33 | #define One 128 |
34 | #define C075 192 |
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 |
44 | |
45 | #include <sysdep.h> |
46 | |
47 | .section .text.evex512, "ax" , @progbits |
48 | ENTRY(_ZGVeN8v_log2_skx) |
49 | pushq %rbp |
50 | cfi_def_cfa_offset(16) |
51 | movq %rsp, %rbp |
52 | cfi_def_cfa(6, 16) |
53 | cfi_offset(6, -16) |
54 | andq $-64, %rsp |
55 | subq $192, %rsp |
56 | vmovaps %zmm0, %zmm7 |
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 |
61 | |
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 |
67 | |
68 | /* Prepare exponent correction: DblRcp<0.75? */ |
69 | vmovups C075+__svml_dlog2_data_internal_avx512(%rip), %zmm1 |
70 | |
71 | /* Table lookup */ |
72 | vmovups __svml_dlog2_data_internal_avx512(%rip), %zmm4 |
73 | |
74 | /* GetExp(x) */ |
75 | vgetexppd {sae}, %zmm7, %zmm5 |
76 | |
77 | /* DblRcp ~ 1/Mantissa */ |
78 | vrcp14pd %zmm6, %zmm8 |
79 | |
80 | /* x<=0? */ |
81 | vfpclasspd $94, %zmm7, %k0 |
82 | |
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 |
86 | kmovw %k0, %edx |
87 | |
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 |
96 | |
97 | /* R^2 */ |
98 | vmulpd {rn-sae}, %zmm6, %zmm6, %zmm15 |
99 | vfmadd231pd {rn-sae}, %zmm6, %zmm13, %zmm12 |
100 | |
101 | /* Prepare table index */ |
102 | vpsrlq $48, %zmm3, %zmm9 |
103 | |
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 |
110 | |
111 | /* polynomial */ |
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 |
116 | testl %edx, %edx |
117 | |
118 | /* Go to special inputs processing branch */ |
119 | jne L(SPECIAL_VALUES_BRANCH) |
120 | # LOE rbx r12 r13 r14 r15 edx zmm0 zmm7 |
121 | |
122 | /* Restore registers |
123 | * and exit the function |
124 | */ |
125 | |
126 | L(EXIT): |
127 | movq %rbp, %rsp |
128 | popq %rbp |
129 | cfi_def_cfa(7, 8) |
130 | cfi_restore(6) |
131 | ret |
132 | cfi_def_cfa(6, 16) |
133 | cfi_offset(6, -16) |
134 | |
135 | /* Branch to process |
136 | * special inputs |
137 | */ |
138 | |
139 | L(SPECIAL_VALUES_BRANCH): |
140 | vmovups %zmm7, 64(%rsp) |
141 | vmovups %zmm0, 128(%rsp) |
142 | # LOE rbx r12 r13 r14 r15 edx zmm0 |
143 | |
144 | xorl %eax, %eax |
145 | # LOE rbx r12 r13 r14 r15 eax edx |
146 | |
147 | vzeroupper |
148 | movq %r12, 16(%rsp) |
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 |
151 | movl %eax, %r12d |
152 | movq %r13, 8(%rsp) |
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 |
155 | movl %edx, %r13d |
156 | movq %r14, (%rsp) |
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 |
160 | |
161 | /* Range mask |
162 | * bits check |
163 | */ |
164 | |
165 | L(RANGEMASK_CHECK): |
166 | btl %r12d, %r13d |
167 | |
168 | /* Call scalar math function */ |
169 | jc L(SCALAR_MATH_CALL) |
170 | # LOE rbx r15 r12d r13d |
171 | |
172 | /* Special inputs |
173 | * processing loop |
174 | */ |
175 | |
176 | L(SPECIAL_VALUES_LOOP): |
177 | incl %r12d |
178 | cmpl $8, %r12d |
179 | |
180 | /* Check bits in range mask */ |
181 | jl L(RANGEMASK_CHECK) |
182 | # LOE rbx r15 r12d r13d |
183 | |
184 | movq 16(%rsp), %r12 |
185 | cfi_restore(12) |
186 | movq 8(%rsp), %r13 |
187 | cfi_restore(13) |
188 | movq (%rsp), %r14 |
189 | cfi_restore(14) |
190 | vmovups 128(%rsp), %zmm0 |
191 | |
192 | /* Go to exit */ |
193 | jmp L(EXIT) |
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 |
201 | |
202 | /* Scalar math function call |
203 | * to process special input |
204 | */ |
205 | |
206 | L(SCALAR_MATH_CALL): |
207 | movl %r12d, %r14d |
208 | vmovsd 64(%rsp, %r14, 8), %xmm0 |
209 | call log2@PLT |
210 | # LOE rbx r14 r15 r12d r13d xmm0 |
211 | |
212 | vmovsd %xmm0, 128(%rsp, %r14, 8) |
213 | |
214 | /* Process special inputs in loop */ |
215 | jmp L(SPECIAL_VALUES_LOOP) |
216 | # LOE rbx r15 r12d r13d |
217 | END(_ZGVeN8v_log2_skx) |
218 | |
219 | .section .rodata, "a" |
220 | .align 64 |
221 | |
222 | #ifdef __svml_dlog2_data_internal_avx512_typedef |
223 | typedef unsigned int VUINT32; |
224 | typedef struct { |
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; |
238 | #endif |
239 | __svml_dlog2_data_internal_avx512: |
240 | /* Log_tbl */ |
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 |
257 | /* One */ |
258 | .align 64 |
259 | .quad 0x3ff0000000000000, 0x3ff0000000000000, 0x3ff0000000000000, 0x3ff0000000000000, 0x3ff0000000000000, 0x3ff0000000000000, 0x3ff0000000000000, 0x3ff0000000000000 |
260 | /* C075 0.75 */ |
261 | .align 64 |
262 | .quad 0x3fe8000000000000, 0x3fe8000000000000, 0x3fe8000000000000, 0x3fe8000000000000, 0x3fe8000000000000, 0x3fe8000000000000, 0x3fe8000000000000, 0x3fe8000000000000 |
263 | /* poly_coeff9 */ |
264 | .align 64 |
265 | .quad 0x3fc4904bda0e1d12, 0x3fc4904bda0e1d12, 0x3fc4904bda0e1d12, 0x3fc4904bda0e1d12, 0x3fc4904bda0e1d12, 0x3fc4904bda0e1d12, 0x3fc4904bda0e1d12, 0x3fc4904bda0e1d12 |
266 | /* poly_coeff8 */ |
267 | .align 64 |
268 | .quad 0xbfc71fb84deb5cce, 0xbfc71fb84deb5cce, 0xbfc71fb84deb5cce, 0xbfc71fb84deb5cce, 0xbfc71fb84deb5cce, 0xbfc71fb84deb5cce, 0xbfc71fb84deb5cce, 0xbfc71fb84deb5cce |
269 | /* poly_coeff7 */ |
270 | .align 64 |
271 | .quad 0x3fca617351818613, 0x3fca617351818613, 0x3fca617351818613, 0x3fca617351818613, 0x3fca617351818613, 0x3fca617351818613, 0x3fca617351818613, 0x3fca617351818613 |
272 | /* poly_coeff6 */ |
273 | .align 64 |
274 | .quad 0xbfcec707e4e3144c, 0xbfcec707e4e3144c, 0xbfcec707e4e3144c, 0xbfcec707e4e3144c, 0xbfcec707e4e3144c, 0xbfcec707e4e3144c, 0xbfcec707e4e3144c, 0xbfcec707e4e3144c |
275 | /* poly_coeff5 */ |
276 | .align 64 |
277 | .quad 0x3fd2776c5114d91a, 0x3fd2776c5114d91a, 0x3fd2776c5114d91a, 0x3fd2776c5114d91a, 0x3fd2776c5114d91a, 0x3fd2776c5114d91a, 0x3fd2776c5114d91a, 0x3fd2776c5114d91a |
278 | /* poly_coeff4 */ |
279 | .align 64 |
280 | .quad 0xbfd71547653d0f8d, 0xbfd71547653d0f8d, 0xbfd71547653d0f8d, 0xbfd71547653d0f8d, 0xbfd71547653d0f8d, 0xbfd71547653d0f8d, 0xbfd71547653d0f8d, 0xbfd71547653d0f8d |
281 | /* poly_coeff3 */ |
282 | .align 64 |
283 | .quad 0x3fdec709dc3a029f, 0x3fdec709dc3a029f, 0x3fdec709dc3a029f, 0x3fdec709dc3a029f, 0x3fdec709dc3a029f, 0x3fdec709dc3a029f, 0x3fdec709dc3a029f, 0x3fdec709dc3a029f |
284 | /* poly_coeff2 */ |
285 | .align 64 |
286 | .quad 0xbfe71547652b82d4, 0xbfe71547652b82d4, 0xbfe71547652b82d4, 0xbfe71547652b82d4, 0xbfe71547652b82d4, 0xbfe71547652b82d4, 0xbfe71547652b82d4, 0xbfe71547652b82d4 |
287 | /* poly_coeff1 */ |
288 | .align 64 |
289 | .quad 0x3ff71547652b82fe, 0x3ff71547652b82fe, 0x3ff71547652b82fe, 0x3ff71547652b82fe, 0x3ff71547652b82fe, 0x3ff71547652b82fe, 0x3ff71547652b82fe, 0x3ff71547652b82fe |
290 | .align 64 |
291 | .type __svml_dlog2_data_internal_avx512, @object |
292 | .size __svml_dlog2_data_internal_avx512, .-__svml_dlog2_data_internal_avx512 |
293 | |