1 /* Compute cubic root of long double value.
2 Copyright (C) 1997-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Dirk Alboth <dirka@uni-paderborn.de> and
5 Ulrich Drepper <drepper@cygnus.com>, 1997.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <http://www.gnu.org/licenses/>. */
21 #include <libm-alias-ldouble.h>
22 #include <machine/asm.h>
28 f8: .tfloat 0.161617097923756032
29 ASM_SIZE_DIRECTIVE(f8)
32 f7: .tfloat -0.988553671195413709
33 ASM_SIZE_DIRECTIVE(f7)
36 f6: .tfloat 2.65298938441952296
37 ASM_SIZE_DIRECTIVE(f6)
40 f5: .tfloat -4.11151425200350531
41 ASM_SIZE_DIRECTIVE(f5)
44 f4: .tfloat 4.09559907378707839
45 ASM_SIZE_DIRECTIVE(f4)
48 f3: .tfloat -2.82414939754975962
49 ASM_SIZE_DIRECTIVE(f3)
52 f2: .tfloat 1.67595307700780102
53 ASM_SIZE_DIRECTIVE(f2)
56 f1: .tfloat 0.338058687610520237
57 ASM_SIZE_DIRECTIVE(f1)
59 #define CBRT2 1.2599210498948731648
60 #define ONE_CBRT2 0.793700525984099737355196796584
61 #define SQR_CBRT2 1.5874010519681994748
62 #define ONE_SQR_CBRT2 0.629960524947436582364439673883
64 /* We make the entries in the following table all 16 bytes
65 wide to avoid having to implement a multiplication by 10. */
68 factor: .tfloat ONE_SQR_CBRT2
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 .byte 0, 0, 0, 0, 0, 0
77 ASM_SIZE_DIRECTIVE(factor)
81 two64: .byte 0, 0, 0, 0, 0, 0, 0xf0, 0x43
82 ASM_SIZE_DIRECTIVE(two64)
85 #define MO(op) op##@GOTOFF(%ebx)
86 #define MOX(op,x) op##@GOTOFF(%ebx,x,1)
89 #define MOX(op,x) op(x)
107 cfi_adjust_cfa_offset (4)
108 cfi_rel_offset (ebx, 0)
132 2: andl $0x8000, %edx
139 fldt 8(%esp) /* xm */
143 fldt 4(%esp) /* xm */
147 /* The following code has two tracks:
148 a) compute the normalized cbrt value
149 b) compute xe/3 and xe%3
150 The right track computes the value for b) and this is done
151 in an optimized way by avoiding division.
153 But why two tracks at all? Very easy: efficiency. Some FP
154 instruction can overlap with a certain amount of integer (and
155 FP) instructions. So we get (except for the imull) all
156 instructions for free. */
158 fldt MO(f8) /* f8 : xm */
159 fmul %st(1) /* f8*xm : xm */
162 faddp /* f7+f8*xm : xm */
163 fmul %st(1) /* (f7+f8*xm)*xm : xm */
164 movl $1431655766, %eax
166 faddp /* f6+(f7+f8*xm)*xm : xm */
168 fmul %st(1) /* (f6+(f7+f8*xm)*xm)*xm : xm */
171 faddp /* f5+(f6+(f7+f8*xm)*xm)*xm : xm */
173 fmul %st(1) /* (f5+(f6+(f7+f8*xm)*xm)*xm)*xm : xm */
176 faddp /* f4+(f5+(f6+(f7+f8*xm)*xm)*xm)*xm : xm */
177 fmul %st(1) /* (f4+(f5+(f6+(f7+f8*xm)*xm)*xm)*xm)*xm : xm */
179 faddp /* f3+(f4+(f5+(f6+(f7+f8*xm)*xm)*xm)*xm)*xm : xm */
180 fmul %st(1) /* (f3+(f4+(f5+(f6+(f7+f8*xm)*xm)*xm)*xm)*xm)*xm : xm */
182 faddp /* f2+(f3+(f4+(f5+(f6+(f7+f8*xm)*xm)*xm)*xm)*xm)*xm : xm */
183 fmul %st(1) /* (f2+(f3+(f4+(f5+(f6+(f7+f8*xm)*xm)*xm)*xm)*xm)*xm)*xm : xm */
185 faddp /* u:=f1+(f2+(f3+(f4+(f5+(f6+(f7+f8*xm)*xm)*xm)*xm)*xm)*xm)*xm : xm */
187 fld %st /* u : u : xm */
188 fmul %st(1) /* u*u : u : xm */
189 fld %st(2) /* xm : u*u : u : xm */
190 fadd %st /* 2*xm : u*u : u : xm */
191 fxch %st(1) /* u*u : 2*xm : u : xm */
192 fmul %st(2) /* t2:=u*u*u : 2*xm : u : xm */
194 fadd %st, %st(1) /* t2 : t2+2*xm : u : xm */
195 leal (%edx,%edx,2),%edx
196 fadd %st(0) /* 2*t2 : t2+2*xm : u : xm */
198 faddp %st, %st(3) /* t2+2*xm : u : 2*t2+xm */
200 fmulp /* u*(t2+2*xm) : 2*t2+xm */
201 fdivp %st, %st(1) /* u*(t2+2*xm)/(2*t2+xm) */
202 fldt MOX(32+factor,%ecx)
203 fmulp /* u*(t2+2*xm)/(2*t2+xm)*FACT */
205 cfi_adjust_cfa_offset (4)
206 fildl (%esp) /* xe/3 : u*(t2+2*xm)/(2*t2+xm)*FACT */
207 fxch /* u*(t2+2*xm)/(2*t2+xm)*FACT : xe/3 */
208 fscale /* u*(t2+2*xm)/(2*t2+xm)*FACT*2^xe/3 */
210 cfi_adjust_cfa_offset (-4)
214 cfi_adjust_cfa_offset (-4)
225 /* Return the argument. */
230 libm_alias_ldouble (__cbrt, cbrt)