1 /* ix87 specific implementation of pow function.
2 Copyright (C) 1996, 1997, 1998, 1999, 2001, 2004, 2005, 2007
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
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, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 /* Reacros modifications */
23 #define ALIGNARG(log2) log2
24 #define ASM_TYPE_DIRECTIVE(name,typearg)
25 #define ASM_SIZE_DIRECTIVE(name)
26 #define cfi_adjust_cfa_offset(x)
34 ASM_TYPE_DIRECTIVE(infinity,@object)
37 .byte 0, 0, 0, 0, 0, 0, 0xf0, 0x7f
38 ASM_SIZE_DIRECTIVE(infinity)
39 ASM_TYPE_DIRECTIVE(zero,@object)
41 ASM_SIZE_DIRECTIVE(zero)
42 ASM_TYPE_DIRECTIVE(minf_mzero,@object)
45 .byte 0, 0, 0, 0, 0, 0, 0xf0, 0xff
47 .byte 0, 0, 0, 0, 0, 0, 0, 0x80
48 ASM_SIZE_DIRECTIVE(minf_mzero)
49 ASM_TYPE_DIRECTIVE(one,@object)
51 ASM_SIZE_DIRECTIVE(one)
52 ASM_TYPE_DIRECTIVE(limit,@object)
54 ASM_SIZE_DIRECTIVE(limit)
55 ASM_TYPE_DIRECTIVE(p63,@object)
56 p63: .byte 0, 0, 0, 0, 0, 0, 0xe0, 0x43
57 ASM_SIZE_DIRECTIVE(p63)
60 #define MO(op) op##@GOTOFF(%ecx)
61 #define MOX(op,x,f) op##@GOTOFF(%ecx,x,f)
64 #define MOX(op,x,f) op(,x,f)
80 cmpb $0x40, %ah // is y == 0 ?
83 cmpb $0x05, %ah // is y == ±inf ?
86 cmpb $0x01, %ah // is y == NaN ?
92 cfi_adjust_cfa_offset (8)
106 /* fistpll raises invalid exception for |y| >= 1L<<63. */
109 fcompl MO(p63) // y : x
114 /* First see whether `y' is a natural number. In this case we
115 can use a more precise algorithm. */
117 fistpll (%esp) // y : x
118 fildll (%esp) // int(y) : y : x
119 fucomp %st(1) // y : x
124 /* OK, we have an integer value for y. */
126 cfi_adjust_cfa_offset (-4)
128 cfi_adjust_cfa_offset (-4)
131 jns 4f // y >= 0, jump
132 fdivrl MO(one) // 1/x (now referred to as x)
136 4: fldl MO(one) // 1 : x
139 6: shrdl $1, %edx, %eax
142 fmul %st(1) // x : ST*x
144 5: fmul %st(0), %st // x*x : ST*x
153 30: fldl 4(%esp) // x : y
154 fldl MO(one) // 1.0 : x : y
155 fucomp %st(1) // x : y
163 cfi_adjust_cfa_offset (8)
165 2: /* y is a real number. */
167 fldl MO(one) // 1.0 : x : y
168 fldl MO(limit) // 0.29 : 1.0 : x : y
169 fld %st(2) // x : 0.29 : 1.0 : x : y
170 fsub %st(2) // x-1 : 0.29 : 1.0 : x : y
171 fabs // |x-1| : 0.29 : 1.0 : x : y
172 fucompp // 1.0 : x : y
177 fsub %st(1) // x-1 : 1.0 : y
178 fyl2xp1 // log2(x) : y
181 7: fyl2x // log2(x) : y
182 8: fmul %st(1) // y*log2(x) : y
183 fst %st(1) // y*log2(x) : y*log2(x)
184 frndint // int(y*log2(x)) : y*log2(x)
185 fsubr %st, %st(1) // int(y*log2(x)) : fract(y*log2(x))
186 fxch // fract(y*log2(x)) : int(y*log2(x))
187 f2xm1 // 2^fract(y*log2(x))-1 : int(y*log2(x))
188 faddl MO(one) // 2^fract(y*log2(x)) : int(y*log2(x))
189 fscale // 2^fract(y*log2(x))*2^int(y*log2(x)) : int(y*log2(x))
191 cfi_adjust_cfa_offset (-8)
192 fstp %st(1) // 2^fract(y*log2(x))*2^int(y*log2(x))
198 11: fstp %st(0) // pop y
204 12: fstp %st(0) // pop y
206 fldl 4(%esp) // x : 1
208 fucompp // < 1, == 1, or > 1
212 je 13f // jump if x is NaN
215 je 14f // jump if |x| == 1
220 fldl MOX(inf_zero, %edx, 4)
228 13: fldl 4(%esp) // load x == NaN
231 cfi_adjust_cfa_offset (8)
236 jz 16f // jump if x == +inf
238 // We must find out whether y is an odd integer.
241 fildll (%esp) // int(y) : y
247 // OK, the value is an integer, but is the number of bits small
248 // enough so that all are coming from the mantissa?
250 cfi_adjust_cfa_offset (-4)
252 cfi_adjust_cfa_offset (-4)
254 jz 18f // jump if not odd
259 155: cmpl $0x00200000, %eax
260 ja 18f // does not fit in mantissa bits
261 // It's an odd integer.
263 fldl MOX(minf_mzero, %edx, 8)
266 cfi_adjust_cfa_offset (8)
270 cfi_adjust_cfa_offset (-8)
274 fldl MOX(inf_zero, %eax, 1)
277 cfi_adjust_cfa_offset (8)
279 17: shll $30, %edx // sign bit for y in right position
281 cfi_adjust_cfa_offset (-8)
283 fldl MOX(inf_zero, %edx, 8)
286 cfi_adjust_cfa_offset (8)
293 // x is ±0 and y is < 0. We must find out whether y is an odd integer.
299 fildll (%esp) // int(y) : y
305 // OK, the value is an integer, but is the number of bits small
306 // enough so that all are coming from the mantissa?
308 cfi_adjust_cfa_offset (-4)
310 cfi_adjust_cfa_offset (-4)
312 jz 27f // jump if not odd
313 cmpl $0xffe00000, %edx
314 jbe 27f // does not fit in mantissa bits
315 // It's an odd integer.
316 // Raise divide-by-zero exception and get minus infinity value.
322 cfi_adjust_cfa_offset (8)
325 cfi_adjust_cfa_offset (-8)
326 27: // Raise divide-by-zero exception and get infinity value.
331 cfi_adjust_cfa_offset (8)
333 // x is ±0 and y is > 0. We must find out whether y is an odd integer.
339 fildll (%esp) // int(y) : y
345 // OK, the value is an integer, but is the number of bits small
346 // enough so that all are coming from the mantissa?
348 cfi_adjust_cfa_offset (-4)
350 cfi_adjust_cfa_offset (-4)
352 jz 24f // jump if not odd
353 cmpl $0xffe00000, %edx
354 jae 24f // does not fit in mantissa bits
355 // It's an odd integer.
359 cfi_adjust_cfa_offset (8)
361 23: addl $8, %esp // Don't use 2 x pop
362 cfi_adjust_cfa_offset (-8)