1 /* Compute cubic root of long double value.
2 Copyright (C) 1997-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/>. */
19 #include <libm-alias-ldouble.h>
20 #include <machine/asm.h>
26 f8: .tfloat 0.161617097923756032
27 ASM_SIZE_DIRECTIVE(f8)
30 f7: .tfloat -0.988553671195413709
31 ASM_SIZE_DIRECTIVE(f7)
34 f6: .tfloat 2.65298938441952296
35 ASM_SIZE_DIRECTIVE(f6)
38 f5: .tfloat -4.11151425200350531
39 ASM_SIZE_DIRECTIVE(f5)
42 f4: .tfloat 4.09559907378707839
43 ASM_SIZE_DIRECTIVE(f4)
46 f3: .tfloat -2.82414939754975962
47 ASM_SIZE_DIRECTIVE(f3)
50 f2: .tfloat 1.67595307700780102
51 ASM_SIZE_DIRECTIVE(f2)
54 f1: .tfloat 0.338058687610520237
55 ASM_SIZE_DIRECTIVE(f1)
57 #define CBRT2 1.2599210498948731648
58 #define ONE_CBRT2 0.793700525984099737355196796584
59 #define SQR_CBRT2 1.5874010519681994748
60 #define ONE_SQR_CBRT2 0.629960524947436582364439673883
62 /* We make the entries in the following table all 16 bytes
63 wide to avoid having to implement a multiplication by 10. */
66 factor: .tfloat ONE_SQR_CBRT2
67 .byte 0, 0, 0, 0, 0, 0
69 .byte 0, 0, 0, 0, 0, 0
71 .byte 0, 0, 0, 0, 0, 0
73 .byte 0, 0, 0, 0, 0, 0
75 ASM_SIZE_DIRECTIVE(factor)
79 two64: .byte 0, 0, 0, 0, 0, 0, 0xf0, 0x43
80 ASM_SIZE_DIRECTIVE(two64)
83 #define MO(op) op##@GOTOFF(%ebx)
84 #define MOX(op,x) op##@GOTOFF(%ebx,x,1)
87 #define MOX(op,x) op(x)
105 cfi_adjust_cfa_offset (4)
106 cfi_rel_offset (ebx, 0)
130 2: andl $0x8000, %edx
137 fldt 8(%esp) /* xm */
141 fldt 4(%esp) /* xm */
145 /* The following code has two tracks:
146 a) compute the normalized cbrt value
147 b) compute xe/3 and xe%3
148 The right track computes the value for b) and this is done
149 in an optimized way by avoiding division.
151 But why two tracks at all? Very easy: efficiency. Some FP
152 instruction can overlap with a certain amount of integer (and
153 FP) instructions. So we get (except for the imull) all
154 instructions for free. */
156 fldt MO(f8) /* f8 : xm */
157 fmul %st(1) /* f8*xm : xm */
160 faddp /* f7+f8*xm : xm */
161 fmul %st(1) /* (f7+f8*xm)*xm : xm */
162 movl $1431655766, %eax
164 faddp /* f6+(f7+f8*xm)*xm : xm */
166 fmul %st(1) /* (f6+(f7+f8*xm)*xm)*xm : xm */
169 faddp /* f5+(f6+(f7+f8*xm)*xm)*xm : xm */
171 fmul %st(1) /* (f5+(f6+(f7+f8*xm)*xm)*xm)*xm : xm */
174 faddp /* f4+(f5+(f6+(f7+f8*xm)*xm)*xm)*xm : xm */
175 fmul %st(1) /* (f4+(f5+(f6+(f7+f8*xm)*xm)*xm)*xm)*xm : xm */
177 faddp /* f3+(f4+(f5+(f6+(f7+f8*xm)*xm)*xm)*xm)*xm : xm */
178 fmul %st(1) /* (f3+(f4+(f5+(f6+(f7+f8*xm)*xm)*xm)*xm)*xm)*xm : xm */
180 faddp /* f2+(f3+(f4+(f5+(f6+(f7+f8*xm)*xm)*xm)*xm)*xm)*xm : xm */
181 fmul %st(1) /* (f2+(f3+(f4+(f5+(f6+(f7+f8*xm)*xm)*xm)*xm)*xm)*xm)*xm : xm */
183 faddp /* u:=f1+(f2+(f3+(f4+(f5+(f6+(f7+f8*xm)*xm)*xm)*xm)*xm)*xm)*xm : xm */
185 fld %st /* u : u : xm */
186 fmul %st(1) /* u*u : u : xm */
187 fld %st(2) /* xm : u*u : u : xm */
188 fadd %st /* 2*xm : u*u : u : xm */
189 fxch %st(1) /* u*u : 2*xm : u : xm */
190 fmul %st(2) /* t2:=u*u*u : 2*xm : u : xm */
192 fadd %st, %st(1) /* t2 : t2+2*xm : u : xm */
193 leal (%edx,%edx,2),%edx
194 fadd %st(0) /* 2*t2 : t2+2*xm : u : xm */
196 faddp %st, %st(3) /* t2+2*xm : u : 2*t2+xm */
198 fmulp /* u*(t2+2*xm) : 2*t2+xm */
199 fdivp %st, %st(1) /* u*(t2+2*xm)/(2*t2+xm) */
200 fldt MOX(32+factor,%ecx)
201 fmulp /* u*(t2+2*xm)/(2*t2+xm)*FACT */
203 cfi_adjust_cfa_offset (4)
204 fildl (%esp) /* xe/3 : u*(t2+2*xm)/(2*t2+xm)*FACT */
205 fxch /* u*(t2+2*xm)/(2*t2+xm)*FACT : xe/3 */
206 fscale /* u*(t2+2*xm)/(2*t2+xm)*FACT*2^xe/3 */
208 cfi_adjust_cfa_offset (-4)
212 cfi_adjust_cfa_offset (-4)
223 /* Return the argument. */
228 libm_alias_ldouble (__cbrt, cbrt)