1 /* Compute cubic root of 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 <machine/asm.h>
22 #include <libm-alias-double.h>
28 f7: .double -0.145263899385486377
29 ASM_SIZE_DIRECTIVE(f7)
31 f6: .double 0.784932344976639262
32 ASM_SIZE_DIRECTIVE(f6)
34 f5: .double -1.83469277483613086
35 ASM_SIZE_DIRECTIVE(f5)
37 f4: .double 2.44693122563534430
38 ASM_SIZE_DIRECTIVE(f4)
40 f3: .double -2.11499494167371287
41 ASM_SIZE_DIRECTIVE(f3)
43 f2: .double 1.50819193781584896
44 ASM_SIZE_DIRECTIVE(f2)
46 f1: .double 0.354895765043919860
47 ASM_SIZE_DIRECTIVE(f1)
49 #define CBRT2 1.2599210498948731648
50 #define ONE_CBRT2 0.793700525984099737355196796584
51 #define SQR_CBRT2 1.5874010519681994748
52 #define ONE_SQR_CBRT2 0.629960524947436582364439673883
55 factor: .double ONE_SQR_CBRT2
60 ASM_SIZE_DIRECTIVE(factor)
63 two54: .byte 0, 0, 0, 0, 0, 0, 0x50, 0x43
64 ASM_SIZE_DIRECTIVE(two54)
67 #define MO(op) op##@GOTOFF(%ebx)
68 #define MOX(op,x) op##@GOTOFF(%ebx,x,1)
71 #define MOX(op,x) op(x)
79 andl $0x7fffffff, %eax
83 cmpl $0x7ff00000, %eax
88 cfi_adjust_cfa_offset (4)
89 cfi_rel_offset (ebx, 0)
93 cmpl $0x00100000, %eax
111 andl $0x7fffffff, %eax
114 andl $0x800fffff, %edx
116 orl $0x3fe00000, %edx
121 fldl 8(%esp) /* xm */
125 fldl 4(%esp) /* xm */
129 /* The following code has two tracks:
130 a) compute the normalized cbrt value
131 b) compute xe/3 and xe%3
132 The right track computes the value for b) and this is done
133 in an optimized way by avoiding division.
135 But why two tracks at all? Very easy: efficiency. Some FP
136 instruction can overlap with a certain amount of integer (and
137 FP) instructions. So we get (except for the imull) all
138 instructions for free. */
140 fld %st(0) /* xm : xm */
142 fmull MO(f7) /* f7*xm : xm */
143 movl $1431655766, %eax
144 faddl MO(f6) /* f6+f7*xm : xm */
146 fmul %st(1) /* (f6+f7*xm)*xm : xm */
148 faddl MO(f5) /* f5+(f6+f7*xm)*xm : xm */
150 fmul %st(1) /* (f5+(f6+f7*xm)*xm)*xm : xm */
152 faddl MO(f4) /* f4+(f5+(f6+f7*xm)*xm)*xm : xm */
153 fmul %st(1) /* (f4+(f5+(f6+f7*xm)*xm)*xm)*xm : xm */
154 faddl MO(f3) /* f3+(f4+(f5+(f6+f7*xm)*xm)*xm)*xm : xm */
155 fmul %st(1) /* (f3+(f4+(f5+(f6+f7*xm)*xm)*xm)*xm)*xm : xm */
156 faddl MO(f2) /* f2+(f3+(f4+(f5+(f6+f7*xm)*xm)*xm)*xm)*xm : xm */
157 fmul %st(1) /* (f2+(f3+(f4+(f5+(f6+f7*xm)*xm)*xm)*xm)*xm)*xm : xm */
158 faddl MO(f1) /* u:=f1+(f2+(f3+(f4+(f5+(f6+f7*xm)*xm)*xm)*xm)*xm)*xm : xm */
160 fld %st /* u : u : xm */
161 fmul %st(1) /* u*u : u : xm */
162 fld %st(2) /* xm : u*u : u : xm */
163 fadd %st /* 2*xm : u*u : u : xm */
164 fxch %st(1) /* u*u : 2*xm : u : xm */
165 fmul %st(2) /* t2:=u*u*u : 2*xm : u : xm */
167 fadd %st, %st(1) /* t2 : t2+2*xm : u : xm */
168 leal (%edx,%edx,2),%edx
169 fadd %st(0) /* 2*t2 : t2+2*xm : u : xm */
171 faddp %st, %st(3) /* t2+2*xm : u : 2*t2+xm */
173 fmulp /* u*(t2+2*xm) : 2*t2+xm */
174 fdivp %st, %st(1) /* u*(t2+2*xm)/(2*t2+xm) */
175 fmull MOX(16+factor,%ecx) /* u*(t2+2*xm)/(2*t2+xm)*FACT */
177 cfi_adjust_cfa_offset (4)
178 fildl (%esp) /* xe/3 : u*(t2+2*xm)/(2*t2+xm)*FACT */
179 fxch /* u*(t2+2*xm)/(2*t2+xm)*FACT : xe/3 */
180 fscale /* u*(t2+2*xm)/(2*t2+xm)*FACT*2^xe/3 */
182 cfi_adjust_cfa_offset (-4)
186 cfi_adjust_cfa_offset (-4)
197 /* Return the argument. */
201 libm_alias_double (__cbrt, cbrt)