1/* Function log10f vectorized with SSE4.
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 * log10(x) = k*log10(2.0) - log10(Rcp) + poly_approximation(R)
25 * log10(Rcp) is tabulated
26 *
27 *
28 */
29
30/* Offsets for data table __svml_slog10_data_internal
31 */
32#define MinNorm 0
33#define MaxNorm 16
34#define L2H 32
35#define L2L 48
36#define iBrkValue 64
37#define iOffExpoMask 80
38#define One 96
39#define sPoly 112
40#define L2 256
41
42#include <sysdep.h>
43
44 .section .text.sse4, "ax", @progbits
45ENTRY(_ZGVbN4v_log10f_sse4)
46 subq $72, %rsp
47 cfi_def_cfa_offset(80)
48 movaps %xmm0, %xmm1
49
50 /* reduction: compute r, n */
51 movdqu iBrkValue+__svml_slog10_data_internal(%rip), %xmm2
52 movaps %xmm0, %xmm4
53 movdqu iOffExpoMask+__svml_slog10_data_internal(%rip), %xmm10
54 psubd %xmm2, %xmm1
55 pand %xmm1, %xmm10
56 psrad $23, %xmm1
57 paddd %xmm2, %xmm10
58 movaps %xmm0, %xmm3
59 movups sPoly+__svml_slog10_data_internal(%rip), %xmm5
60 movups sPoly+32+__svml_slog10_data_internal(%rip), %xmm6
61 movups sPoly+64+__svml_slog10_data_internal(%rip), %xmm7
62 movups sPoly+96+__svml_slog10_data_internal(%rip), %xmm9
63 cvtdq2ps %xmm1, %xmm12
64 cmpltps MinNorm+__svml_slog10_data_internal(%rip), %xmm4
65 cmpnleps MaxNorm+__svml_slog10_data_internal(%rip), %xmm3
66 subps One+__svml_slog10_data_internal(%rip), %xmm10
67 mulps %xmm10, %xmm5
68 movaps %xmm10, %xmm8
69 mulps %xmm10, %xmm6
70 mulps %xmm10, %xmm8
71 addps sPoly+16+__svml_slog10_data_internal(%rip), %xmm5
72 mulps %xmm10, %xmm7
73 addps sPoly+48+__svml_slog10_data_internal(%rip), %xmm6
74 mulps %xmm10, %xmm9
75 mulps %xmm8, %xmm5
76 addps sPoly+80+__svml_slog10_data_internal(%rip), %xmm7
77 addps sPoly+112+__svml_slog10_data_internal(%rip), %xmm9
78 addps %xmm5, %xmm6
79 mulps %xmm8, %xmm6
80 orps %xmm3, %xmm4
81
82 /* combine and get argument value range mask */
83 movmskps %xmm4, %edx
84 movups L2L+__svml_slog10_data_internal(%rip), %xmm1
85 addps %xmm6, %xmm7
86 mulps %xmm12, %xmm1
87 mulps %xmm7, %xmm8
88 movups L2H+__svml_slog10_data_internal(%rip), %xmm11
89 addps %xmm8, %xmm9
90 mulps %xmm11, %xmm12
91 mulps %xmm10, %xmm9
92 addps sPoly+128+__svml_slog10_data_internal(%rip), %xmm9
93 mulps %xmm9, %xmm10
94 addps %xmm10, %xmm1
95 addps %xmm12, %xmm1
96 testl %edx, %edx
97
98 /* Go to special inputs processing branch */
99 jne L(SPECIAL_VALUES_BRANCH)
100 # LOE rbx rbp r12 r13 r14 r15 edx xmm0 xmm1
101
102 /* Restore registers
103 * and exit the function
104 */
105
106L(EXIT):
107 movaps %xmm1, %xmm0
108 addq $72, %rsp
109 cfi_def_cfa_offset(8)
110 ret
111 cfi_def_cfa_offset(80)
112
113 /* Branch to process
114 * special inputs
115 */
116
117L(SPECIAL_VALUES_BRANCH):
118 movups %xmm0, 32(%rsp)
119 movups %xmm1, 48(%rsp)
120 # LOE rbx rbp r12 r13 r14 r15 edx
121
122 xorl %eax, %eax
123 movq %r12, 16(%rsp)
124 cfi_offset(12, -64)
125 movl %eax, %r12d
126 movq %r13, 8(%rsp)
127 cfi_offset(13, -72)
128 movl %edx, %r13d
129 movq %r14, (%rsp)
130 cfi_offset(14, -80)
131 # LOE rbx rbp r15 r12d r13d
132
133 /* Range mask
134 * bits check
135 */
136
137L(RANGEMASK_CHECK):
138 btl %r12d, %r13d
139
140 /* Call scalar math function */
141 jc L(SCALAR_MATH_CALL)
142 # LOE rbx rbp r15 r12d r13d
143
144 /* Special inputs
145 * processing loop
146 */
147
148L(SPECIAL_VALUES_LOOP):
149 incl %r12d
150 cmpl $4, %r12d
151
152 /* Check bits in range mask */
153 jl L(RANGEMASK_CHECK)
154 # LOE rbx rbp r15 r12d r13d
155
156 movq 16(%rsp), %r12
157 cfi_restore(12)
158 movq 8(%rsp), %r13
159 cfi_restore(13)
160 movq (%rsp), %r14
161 cfi_restore(14)
162 movups 48(%rsp), %xmm1
163
164 /* Go to exit */
165 jmp L(EXIT)
166 cfi_offset(12, -64)
167 cfi_offset(13, -72)
168 cfi_offset(14, -80)
169 # LOE rbx rbp r12 r13 r14 r15 xmm1
170
171 /* Scalar math function call
172 * to process special input
173 */
174
175L(SCALAR_MATH_CALL):
176 movl %r12d, %r14d
177 movss 32(%rsp, %r14, 4), %xmm0
178 call log10f@PLT
179 # LOE rbx rbp r14 r15 r12d r13d xmm0
180
181 movss %xmm0, 48(%rsp, %r14, 4)
182
183 /* Process special inputs in loop */
184 jmp L(SPECIAL_VALUES_LOOP)
185 # LOE rbx rbp r15 r12d r13d
186END(_ZGVbN4v_log10f_sse4)
187
188 .section .rodata, "a"
189 .align 16
190
191#ifdef __svml_slog10_data_internal_typedef
192typedef unsigned int VUINT32;
193typedef struct {
194 __declspec(align(16)) VUINT32 MinNorm[4][1];
195 __declspec(align(16)) VUINT32 MaxNorm[4][1];
196 __declspec(align(16)) VUINT32 L2H[4][1];
197 __declspec(align(16)) VUINT32 L2L[4][1];
198 __declspec(align(16)) VUINT32 iBrkValue[4][1];
199 __declspec(align(16)) VUINT32 iOffExpoMask[4][1];
200 __declspec(align(16)) VUINT32 One[4][1];
201 __declspec(align(16)) VUINT32 sPoly[9][4][1];
202 __declspec(align(16)) VUINT32 L2[4][1];
203} __svml_slog10_data_internal;
204#endif
205__svml_slog10_data_internal:
206 /* MinNorm */
207 .long 0x00800000, 0x00800000, 0x00800000, 0x00800000
208 /* MaxNorm */
209 .align 16
210 .long 0x7f7fffff, 0x7f7fffff, 0x7f7fffff, 0x7f7fffff
211 /* L2H */
212 .align 16
213 .long 0x3e9a2100, 0x3e9a2100, 0x3e9a2100, 0x3e9a2100
214 /* L2L */
215 .align 16
216 .long 0xb64AF600, 0xb64AF600, 0xb64AF600, 0xb64AF600
217 /* iBrkValue = SP 2/3 */
218 .align 16
219 .long 0x3f2aaaab, 0x3f2aaaab, 0x3f2aaaab, 0x3f2aaaab
220 /* iOffExpoMask = SP significand mask */
221 .align 16
222 .long 0x007fffff, 0x007fffff, 0x007fffff, 0x007fffff
223 /* sOne = SP 1.0 */
224 .align 16
225 .long 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000
226 /* spoly[9] */
227 .align 16
228 .long 0x3d8063B4, 0x3d8063B4, 0x3d8063B4, 0x3d8063B4 /* coeff9 */
229 .long 0xbd890073, 0xbd890073, 0xbd890073, 0xbd890073 /* coeff8 */
230 .long 0x3d775317, 0x3d775317, 0x3d775317, 0x3d775317 /* coeff7 */
231 .long 0xbd91FB27, 0xbd91FB27, 0xbd91FB27, 0xbd91FB27 /* coeff6 */
232 .long 0x3dB20B96, 0x3dB20B96, 0x3dB20B96, 0x3dB20B96 /* coeff5 */
233 .long 0xbdDE6E20, 0xbdDE6E20, 0xbdDE6E20, 0xbdDE6E20 /* coeff4 */
234 .long 0x3e143CE5, 0x3e143CE5, 0x3e143CE5, 0x3e143CE5 /* coeff3 */
235 .long 0xbe5E5BC5, 0xbe5E5BC5, 0xbe5E5BC5, 0xbe5E5BC5 /* coeff2 */
236 .long 0x3eDE5BD9, 0x3eDE5BD9, 0x3eDE5BD9, 0x3eDE5BD9 /* coeff1 */
237 /* L2 */
238 .align 16
239 .long 0x3e9a209b, 0x3e9a209b, 0x3e9a209b, 0x3e9a209b
240 .align 16
241 .type __svml_slog10_data_internal, @object
242 .size __svml_slog10_data_internal, .-__svml_slog10_data_internal
243

source code of glibc/sysdeps/x86_64/fpu/multiarch/svml_s_log10f4_core_sse4.S