1 /* Function log2f vectorized with AVX2.
2 Copyright (C) 2021-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 * 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_slog2_data_internal
35 #define iOffExpoMask 96
41 .section .text.avx2, "ax", @progbits
42 ENTRY(_ZGVdN8v_log2f_avx2)
44 cfi_def_cfa_offset(16)
51 /* reduction: compute r, n */
52 vmovups iBrkValue+__svml_slog2_data_internal(%rip), %ymm4
53 vmovups sPoly+64+__svml_slog2_data_internal(%rip), %ymm9
54 vmovups sPoly+128+__svml_slog2_data_internal(%rip), %ymm10
55 vmovups sPoly+192+__svml_slog2_data_internal(%rip), %ymm12
56 vpsubd %ymm4, %ymm0, %ymm1
57 vcmplt_oqps MinNorm+__svml_slog2_data_internal(%rip), %ymm0, %ymm5
58 vcmpnle_uqps MaxNorm+__svml_slog2_data_internal(%rip), %ymm0, %ymm6
59 vpand iOffExpoMask+__svml_slog2_data_internal(%rip), %ymm1, %ymm3
60 vpsrad $23, %ymm1, %ymm2
61 vmovups sPoly+__svml_slog2_data_internal(%rip), %ymm1
62 vpaddd %ymm4, %ymm3, %ymm8
63 vcvtdq2ps %ymm2, %ymm14
64 vsubps One+__svml_slog2_data_internal(%rip), %ymm8, %ymm13
65 vfmadd213ps sPoly+32+__svml_slog2_data_internal(%rip), %ymm13, %ymm1
66 vfmadd213ps sPoly+96+__svml_slog2_data_internal(%rip), %ymm13, %ymm9
67 vmulps %ymm13, %ymm13, %ymm11
68 vfmadd213ps sPoly+160+__svml_slog2_data_internal(%rip), %ymm13, %ymm10
69 vfmadd213ps sPoly+224+__svml_slog2_data_internal(%rip), %ymm13, %ymm12
70 vfmadd213ps %ymm9, %ymm11, %ymm1
71 vfmadd213ps %ymm10, %ymm11, %ymm1
72 vfmadd213ps %ymm12, %ymm11, %ymm1
73 vfmadd213ps sPoly+256+__svml_slog2_data_internal(%rip), %ymm13, %ymm1
74 vorps %ymm6, %ymm5, %ymm7
76 /* combine and get argument value range mask */
78 vfmadd213ps %ymm14, %ymm13, %ymm1
81 /* Go to special inputs processing branch */
82 jne L(SPECIAL_VALUES_BRANCH)
83 # LOE rbx r12 r13 r14 r15 edx ymm0 ymm1
86 * and exit the function
103 L(SPECIAL_VALUES_BRANCH):
104 vmovups %ymm0, 32(%rsp)
105 vmovups %ymm1, 64(%rsp)
106 # LOE rbx r12 r13 r14 r15 edx ymm1
109 # LOE rbx r12 r13 r14 r15 eax edx
113 /* DW_CFA_expression: r12 (r12) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -32; DW_OP_and; DW_OP_const4s: -80; DW_OP_plus) */
114 .cfi_escape 0x10, 0x0c, 0x0e, 0x38, 0x1c, 0x0d, 0xe0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0xb0, 0xff, 0xff, 0xff, 0x22
117 /* DW_CFA_expression: r13 (r13) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -32; DW_OP_and; DW_OP_const4s: -88; DW_OP_plus) */
118 .cfi_escape 0x10, 0x0d, 0x0e, 0x38, 0x1c, 0x0d, 0xe0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0xa8, 0xff, 0xff, 0xff, 0x22
121 /* DW_CFA_expression: r14 (r14) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -32; DW_OP_and; DW_OP_const4s: -96; DW_OP_plus) */
122 .cfi_escape 0x10, 0x0e, 0x0e, 0x38, 0x1c, 0x0d, 0xe0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0xa0, 0xff, 0xff, 0xff, 0x22
123 # LOE rbx r15 r12d r13d
132 /* Call scalar math function */
133 jc L(SCALAR_MATH_CALL)
134 # LOE rbx r15 r12d r13d
140 L(SPECIAL_VALUES_LOOP):
144 /* Check bits in range mask */
145 jl L(RANGEMASK_CHECK)
146 # LOE rbx r15 r12d r13d
154 vmovups 64(%rsp), %ymm1
158 /* DW_CFA_expression: r12 (r12) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -32; DW_OP_and; DW_OP_const4s: -80; DW_OP_plus) */
159 .cfi_escape 0x10, 0x0c, 0x0e, 0x38, 0x1c, 0x0d, 0xe0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0xb0, 0xff, 0xff, 0xff, 0x22
160 /* DW_CFA_expression: r13 (r13) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -32; DW_OP_and; DW_OP_const4s: -88; DW_OP_plus) */
161 .cfi_escape 0x10, 0x0d, 0x0e, 0x38, 0x1c, 0x0d, 0xe0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0xa8, 0xff, 0xff, 0xff, 0x22
162 /* DW_CFA_expression: r14 (r14) (DW_OP_lit8; DW_OP_minus; DW_OP_const4s: -32; DW_OP_and; DW_OP_const4s: -96; DW_OP_plus) */
163 .cfi_escape 0x10, 0x0e, 0x0e, 0x38, 0x1c, 0x0d, 0xe0, 0xff, 0xff, 0xff, 0x1a, 0x0d, 0xa0, 0xff, 0xff, 0xff, 0x22
164 # LOE rbx r12 r13 r14 r15 ymm1
166 /* Scalar math function call
167 * to process special input
172 vmovss 32(%rsp, %r14, 4), %xmm0
174 # LOE rbx r14 r15 r12d r13d xmm0
176 vmovss %xmm0, 64(%rsp, %r14, 4)
178 /* Process special inputs in loop */
179 jmp L(SPECIAL_VALUES_LOOP)
180 # LOE rbx r15 r12d r13d
181 END(_ZGVdN8v_log2f_avx2)
183 .section .rodata, "a"
186 #ifdef __svml_slog2_data_internal_typedef
187 typedef unsigned int VUINT32;
189 __declspec(align(32)) VUINT32 MinNorm[8][1];
190 __declspec(align(32)) VUINT32 MaxNorm[8][1];
191 __declspec(align(32)) VUINT32 iBrkValue[8][1];
192 __declspec(align(32)) VUINT32 iOffExpoMask[8][1];
193 __declspec(align(32)) VUINT32 One[8][1];
194 __declspec(align(32)) VUINT32 sPoly[9][8][1];
195 } __svml_slog2_data_internal;
197 __svml_slog2_data_internal:
199 .long 0x00800000, 0x00800000, 0x00800000, 0x00800000, 0x00800000, 0x00800000, 0x00800000, 0x00800000
202 .long 0x7f7fffff, 0x7f7fffff, 0x7f7fffff, 0x7f7fffff, 0x7f7fffff, 0x7f7fffff, 0x7f7fffff, 0x7f7fffff
203 /* iBrkValue = SP 2/3 */
205 .long 0x3f2aaaab, 0x3f2aaaab, 0x3f2aaaab, 0x3f2aaaab, 0x3f2aaaab, 0x3f2aaaab, 0x3f2aaaab, 0x3f2aaaab
206 /* iOffExpoMask = SP significand mask */
208 .long 0x007fffff, 0x007fffff, 0x007fffff, 0x007fffff, 0x007fffff, 0x007fffff, 0x007fffff, 0x007fffff
211 .long 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000
214 .long 0x3e554012, 0x3e554012, 0x3e554012, 0x3e554012, 0x3e554012, 0x3e554012, 0x3e554012, 0x3e554012 /* coeff9 */
215 .long 0xbe638E14, 0xbe638E14, 0xbe638E14, 0xbe638E14, 0xbe638E14, 0xbe638E14, 0xbe638E14, 0xbe638E14 /* coeff8 */
216 .long 0x3e4D660B, 0x3e4D660B, 0x3e4D660B, 0x3e4D660B, 0x3e4D660B, 0x3e4D660B, 0x3e4D660B, 0x3e4D660B /* coeff7 */
217 .long 0xbe727824, 0xbe727824, 0xbe727824, 0xbe727824, 0xbe727824, 0xbe727824, 0xbe727824, 0xbe727824 /* coeff6 */
218 .long 0x3e93DD07, 0x3e93DD07, 0x3e93DD07, 0x3e93DD07, 0x3e93DD07, 0x3e93DD07, 0x3e93DD07, 0x3e93DD07 /* coeff5 */
219 .long 0xbeB8B969, 0xbeB8B969, 0xbeB8B969, 0xbeB8B969, 0xbeB8B969, 0xbeB8B969, 0xbeB8B969, 0xbeB8B969 /* coeff4 */
220 .long 0x3eF637C0, 0x3eF637C0, 0x3eF637C0, 0x3eF637C0, 0x3eF637C0, 0x3eF637C0, 0x3eF637C0, 0x3eF637C0 /* coeff3 */
221 .long 0xbf38AA2B, 0xbf38AA2B, 0xbf38AA2B, 0xbf38AA2B, 0xbf38AA2B, 0xbf38AA2B, 0xbf38AA2B, 0xbf38AA2B /* coeff2 */
222 .long 0x3fB8AA3B, 0x3fB8AA3B, 0x3fB8AA3B, 0x3fB8AA3B, 0x3fB8AA3B, 0x3fB8AA3B, 0x3fB8AA3B, 0x3fB8AA3B /* coeff1 */
224 .type __svml_slog2_data_internal, @object
225 .size __svml_slog2_data_internal, .-__svml_slog2_data_internal