1 /* Compute cubic root of float value.
2 Copyright (C) 1997 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 Library General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 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 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with the GNU C Library; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #include <machine/asm.h>
31 ASM_TYPE_DIRECTIVE(f1,@object)
32 f1: .double 0.492659620528969547
33 ASM_SIZE_DIRECTIVE(f1)
34 ASM_TYPE_DIRECTIVE(f2,@object)
35 f2: .double 0.697570460207922770
36 ASM_SIZE_DIRECTIVE(f2)
37 ASM_TYPE_DIRECTIVE(f3,@object)
38 f3: .double 0.191502161678719066
39 ASM_SIZE_DIRECTIVE(f3)
41 #define CBRT2 1.2599210498948731648
42 #define SQR_CBRT2 1.5874010519681994748
44 ASM_TYPE_DIRECTIVE(factor,@object)
45 factor: .double 1.0 / SQR_CBRT2
50 ASM_SIZE_DIRECTIVE(factor)
52 ASM_TYPE_DIRECTIVE(two25,@object)
53 two25: .byte 0, 0, 0, 0x4c
54 ASM_SIZE_DIRECTIVE(two25)
57 #define MO(op) op##@GOTOFF(%ebx)
58 #define MOX(op,x,f) op##@GOTOFF(%ebx,x,f)
61 #define MOX(op,x,f) op(,x,f)
69 andl $0x7fffffff, %eax
71 cmpl $0x7f800000, %eax
78 addl $_GLOBAL_OFFSET_TABLE_+[.-3b], %ebx
81 cmpl $0x00800000, %eax
99 andl $0x7fffffff, %eax
102 andl $0x807fffff, %edx
104 orl $0x3f000000, %edx
109 flds 8(%esp) /* xm */
113 flds 4(%esp) /* xm */
117 /* The following code has two track:
118 a) compute the normalized cbrt value
119 b) compute xe/3 and xe%3
120 The right track computes the value for b) and this is done
121 in an optimized way by avoiding division. */
123 fld %st(0) /* xm : xm */
124 fmull MO(f3) /* f3*xm : xm */
125 movl $1431655766, %eax
126 fsubrl MO(f2) /* f2-f3*xm : xm */
128 fmul %st(1) /* (f2-f3*xm)*xm : xm */
130 faddl MO(f1) /* u:=f1+(f2-f3*xm)*xm : xm */
132 fld %st /* u : u : xm */
134 fmul %st(1) /* u*u : u : xm */
135 fld %st(2) /* xm : u*u : u : xm */
136 fadd %st /* 2*xm : u*u : u : xm */
137 fxch %st(1) /* u*u : 2*xm : u : xm */
138 fmul %st(2) /* t2:=u*u*u : 2*xm : u : xm */
140 fadd %st, %st(1) /* t2 : t2+2*xm : u : xm */
141 leal (%edx,%edx,2),%edx
142 fadd %st(0) /* 2*t2 : t2+2*xm : u : xm */
144 faddp %st, %st(3) /* t2+2*xm : u : 2*t2+xm */
145 fmulp /* u*(t2+2*xm) : 2*t2+xm */
146 fdivp %st, %st(1) /* u*(t2+2*xm)/(2*t2+xm) */
147 fmull MOX(16+factor,%ecx,8) /* u*(t2+2*xm)/(2*t2+xm)*FACT */
149 fildl (%esp) /* xe/3 : u*(t2+2*xm)/(2*t2+xm)*FACT */
150 fxch /* u*(t2+2*xm)/(2*t2+xm)*FACT : xe/3 */
152 fscale /* u*(t2+2*xm)/(2*t2+xm)*FACT*2^xe/3 */
157 testl $0x80000000, 4(%esp)
162 /* Return the argument. */
166 weak_alias (__cbrtf, cbrtf)