1/* Function logf vectorized with SSE4.
2 Copyright (C) 2014-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#include <sysdep.h>
20#include "svml_s_logf_data.h"
21
22 .section .text.sse4, "ax", @progbits
23ENTRY (_ZGVbN4v_logf_sse4)
24/*
25 ALGORITHM DESCRIPTION:
26
27 log(x) = exponent_x*log(2) + log(mantissa_x), if mantissa_x<4/3
28 log(x) = (exponent_x+1)*log(2) + log(0.5*mantissa_x), if mantissa_x>4/3
29
30 R = mantissa_x - 1, if mantissa_x<4/3
31 R = 0.5*mantissa_x - 1, if mantissa_x>4/3
32 |R|< 1/3
33
34 log(1+R) is approximated as a polynomial: degree 9 for 1-ulp,
35 degree 7 for 4-ulp, degree 3 for half-precision. */
36
37 pushq %rbp
38 cfi_adjust_cfa_offset (8)
39 cfi_rel_offset (%rbp, 0)
40 movq %rsp, %rbp
41 cfi_def_cfa_register (%rbp)
42 andq $-64, %rsp
43 subq $320, %rsp
44
45/* reduction: compute r,n */
46 movaps %xmm0, %xmm2
47
48/* check for working range,
49 set special argument mask (denormals/zero/Inf/NaN) */
50 movq __svml_slog_data@GOTPCREL(%rip), %rax
51 movdqu _iHiDelta(%rax), %xmm1
52 movdqu _iLoRange(%rax), %xmm4
53 paddd %xmm0, %xmm1
54 movdqu _iBrkValue(%rax), %xmm3
55 pcmpgtd %xmm1, %xmm4
56 movdqu _iOffExpoMask(%rax), %xmm1
57 psubd %xmm3, %xmm2
58 pand %xmm2, %xmm1
59
60/* exponent_x (mantissa_x<4/3) or exponent_x+1 (mantissa_x>4/3) */
61 psrad $23, %xmm2
62 paddd %xmm3, %xmm1
63 movups _sPoly_7(%rax), %xmm5
64
65/* mantissa_x (mantissa_x<4/3), or 0.5*mantissa_x (mantissa_x>4/3) */
66 cvtdq2ps %xmm2, %xmm6
67
68/* reduced argument R */
69 subps _sOne(%rax), %xmm1
70 movmskps %xmm4, %ecx
71
72/* final reconstruction:
73 add exponent_value*log2 to polynomial result */
74 mulps _sLn2(%rax), %xmm6
75
76/* polynomial evaluation starts here */
77 mulps %xmm1, %xmm5
78 addps _sPoly_6(%rax), %xmm5
79 mulps %xmm1, %xmm5
80 addps _sPoly_5(%rax), %xmm5
81 mulps %xmm1, %xmm5
82 addps _sPoly_4(%rax), %xmm5
83 mulps %xmm1, %xmm5
84 addps _sPoly_3(%rax), %xmm5
85 mulps %xmm1, %xmm5
86 addps _sPoly_2(%rax), %xmm5
87 mulps %xmm1, %xmm5
88 addps _sPoly_1(%rax), %xmm5
89 mulps %xmm1, %xmm5
90
91/* polynomial evaluation end */
92 mulps %xmm1, %xmm5
93 addps %xmm5, %xmm1
94 addps %xmm6, %xmm1
95 testl %ecx, %ecx
96 jne .LBL_1_3
97
98.LBL_1_2:
99 cfi_remember_state
100 movdqa %xmm1, %xmm0
101 movq %rbp, %rsp
102 cfi_def_cfa_register (%rsp)
103 popq %rbp
104 cfi_adjust_cfa_offset (-8)
105 cfi_restore (%rbp)
106 ret
107
108.LBL_1_3:
109 cfi_restore_state
110 movups %xmm0, 192(%rsp)
111 movups %xmm1, 256(%rsp)
112 je .LBL_1_2
113
114 xorb %dl, %dl
115 xorl %eax, %eax
116 movups %xmm8, 112(%rsp)
117 movups %xmm9, 96(%rsp)
118 movups %xmm10, 80(%rsp)
119 movups %xmm11, 64(%rsp)
120 movups %xmm12, 48(%rsp)
121 movups %xmm13, 32(%rsp)
122 movups %xmm14, 16(%rsp)
123 movups %xmm15, (%rsp)
124 movq %rsi, 136(%rsp)
125 movq %rdi, 128(%rsp)
126 movq %r12, 168(%rsp)
127 cfi_offset_rel_rsp (12, 168)
128 movb %dl, %r12b
129 movq %r13, 160(%rsp)
130 cfi_offset_rel_rsp (13, 160)
131 movl %ecx, %r13d
132 movq %r14, 152(%rsp)
133 cfi_offset_rel_rsp (14, 152)
134 movl %eax, %r14d
135 movq %r15, 144(%rsp)
136 cfi_offset_rel_rsp (15, 144)
137 cfi_remember_state
138
139.LBL_1_6:
140 btl %r14d, %r13d
141 jc .LBL_1_12
142
143.LBL_1_7:
144 lea 1(%r14), %esi
145 btl %esi, %r13d
146 jc .LBL_1_10
147
148.LBL_1_8:
149 incb %r12b
150 addl $2, %r14d
151 cmpb $16, %r12b
152 jb .LBL_1_6
153
154 movups 112(%rsp), %xmm8
155 movups 96(%rsp), %xmm9
156 movups 80(%rsp), %xmm10
157 movups 64(%rsp), %xmm11
158 movups 48(%rsp), %xmm12
159 movups 32(%rsp), %xmm13
160 movups 16(%rsp), %xmm14
161 movups (%rsp), %xmm15
162 movq 136(%rsp), %rsi
163 movq 128(%rsp), %rdi
164 movq 168(%rsp), %r12
165 cfi_restore (%r12)
166 movq 160(%rsp), %r13
167 cfi_restore (%r13)
168 movq 152(%rsp), %r14
169 cfi_restore (%r14)
170 movq 144(%rsp), %r15
171 cfi_restore (%r15)
172 movups 256(%rsp), %xmm1
173 jmp .LBL_1_2
174
175.LBL_1_10:
176 cfi_restore_state
177 movzbl %r12b, %r15d
178 movss 196(%rsp,%r15,8), %xmm0
179
180 call JUMPTARGET(logf)
181
182 movss %xmm0, 260(%rsp,%r15,8)
183 jmp .LBL_1_8
184
185.LBL_1_12:
186 movzbl %r12b, %r15d
187 movss 192(%rsp,%r15,8), %xmm0
188
189 call JUMPTARGET(logf)
190
191 movss %xmm0, 256(%rsp,%r15,8)
192 jmp .LBL_1_7
193
194END (_ZGVbN4v_logf_sse4)
195

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