1 /* ix87 specific implementation of pow function.
2 Copyright (C) 1996-2014 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #include <machine/asm.h>
22 .section .rodata.cst8,"aM",@progbits,8
27 ASM_SIZE_DIRECTIVE(one)
29 p3: .byte 0, 0, 0, 0, 0, 0, 0x20, 0x40
30 ASM_SIZE_DIRECTIVE(p3)
32 p63: .byte 0, 0, 0, 0, 0, 0, 0xe0, 0x43
33 ASM_SIZE_DIRECTIVE(p63)
35 p64: .byte 0, 0, 0, 0, 0, 0, 0xf0, 0x43
36 ASM_SIZE_DIRECTIVE(p64)
38 p78: .byte 0, 0, 0, 0, 0, 0, 0xd0, 0x44
39 ASM_SIZE_DIRECTIVE(p78)
41 pm79: .byte 0, 0, 0, 0, 0, 0, 0, 0x3b
42 ASM_SIZE_DIRECTIVE(pm79)
44 .section .rodata.cst16,"aM",@progbits,16
47 .type infinity,@object
50 .byte 0, 0, 0, 0, 0, 0, 0xf0, 0x7f
51 ASM_SIZE_DIRECTIVE(infinity)
54 ASM_SIZE_DIRECTIVE(zero)
55 .type minf_mzero,@object
58 .byte 0, 0, 0, 0, 0, 0, 0xf0, 0xff
60 .byte 0, 0, 0, 0, 0, 0, 0, 0x80
61 ASM_SIZE_DIRECTIVE(minf_mzero)
64 # define MO(op) op##@GOTOFF(%ecx)
65 # define MOX(op,x,f) op##@GOTOFF(%ecx,x,f)
68 # define MOX(op,x,f) op(,x,f)
83 cmpb $0x40, %ah // is y == 0 ?
86 cmpb $0x05, %ah // is y == ±inf ?
89 cmpb $0x01, %ah // is y == NaN ?
95 cfi_adjust_cfa_offset (8)
112 /* fistpll raises invalid exception for |y| >= 1L<<63. */
115 fcompl MO(p63) // y : x
120 /* First see whether `y' is a natural number. In this case we
121 can use a more precise algorithm. */
123 fistpll (%esp) // y : x
124 fildll (%esp) // int(y) : y : x
125 fucomp %st(1) // y : x
130 // If y has absolute value at most 0x1p-79, then any finite
131 // nonzero x will result in 1. Saturate y to those bounds to
132 // avoid underflow in the calculation of y*log2(x).
135 fcompl MO(pm79) // y : x
140 fldl MO(pm79) // 0x1p-79 : x
146 9: /* OK, we have an integer value for y. Unless very small
147 (we use < 8), use the algorithm for real exponent to avoid
148 accumulation of errors. */
151 fcompl MO(p3) // y : x
156 cfi_adjust_cfa_offset (-4)
158 cfi_adjust_cfa_offset (-4)
161 jns 4f // y >= 0, jump
162 fdivrl MO(one) // 1/x (now referred to as x)
166 4: fldl MO(one) // 1 : x
169 6: shrdl $1, %edx, %eax
172 fmul %st(1) // x : ST*x
174 5: fmul %st(0), %st // x*x : ST*x
183 30: fldt 4(%esp) // x : y
184 fldl MO(one) // 1.0 : x : y
185 fucomp %st(1) // x : y
193 cfi_adjust_cfa_offset (8)
195 cfi_adjust_cfa_offset (-8)
199 cfi_adjust_cfa_offset (8)
201 2: // y is a large integer (absolute value at least 8), but
202 // may be odd unless at least 1L<<64. So it may be necessary
203 // to adjust the sign of a negative result afterwards.
207 // If y has absolute value at least 1L<<78, then any finite
208 // nonzero x will result in 0 (underflow), 1 or infinity (overflow).
209 // Saturate y to those bounds to avoid overflow in the calculation
211 fld %st // y : y : |x|
212 fabs // |y| : y : |x|
213 fcompl MO(p78) // y : |x|
218 fldl MO(p78) // 1L<<78 : |x|
221 fchs // -(1L<<78) : |x|
223 3: /* y is a real number. */
225 cfi_adjust_cfa_offset (28)
227 fstpt (%esp) // <empty>
229 call HIDDEN_JUMPTARGET (__powl_helper) // <result>
232 cfi_adjust_cfa_offset (-28)
235 // x is negative. If y is an odd integer, negate the result.
239 fldt 24(%esp) // y : abs(result)
240 fld %st // y : y : abs(result)
241 fabs // |y| : y : abs(result)
242 fcompl MO(p64) // y : abs(result)
246 fldl MO(p63) // p63 : y : abs(result)
247 fxch // y : p63 : abs(result)
248 fprem // y%p63 : p63 : abs(result)
249 fstp %st(1) // y%p63 : abs(result)
251 // We must find out whether y is an odd integer.
252 fld %st // y : y : abs(result)
253 fistpll (%esp) // y : abs(result)
254 fildll (%esp) // int(y) : y : abs(result)
255 fucompp // abs(result)
260 // OK, the value is an integer, but is it odd?
262 cfi_adjust_cfa_offset (-4)
264 cfi_adjust_cfa_offset (-4)
266 jz 290f // jump if not odd
267 // It's an odd integer.
270 cfi_adjust_cfa_offset (8)
271 291: fstp %st(0) // abs(result)
273 cfi_adjust_cfa_offset (-8)
278 11: fstp %st(0) // pop y
284 12: fstp %st(0) // pop y
286 fldt 4(%esp) // x : 1
288 fucompp // < 1, == 1, or > 1
292 je 13f // jump if x is NaN
295 je 14f // jump if |x| == 1
300 fldl MOX(inf_zero, %edx, 4)
308 13: fldt 4(%esp) // load x == NaN
311 cfi_adjust_cfa_offset (8)
316 jz 16f // jump if x == +inf
318 // fistpll raises invalid exception for |y| >= 1L<<63, but y
319 // may be odd unless we know |y| >= 1L<<64.
326 fldl MO(p63) // p63 : y
331 // We must find out whether y is an odd integer.
334 fildll (%esp) // int(y) : y
340 // OK, the value is an integer, but is it odd?
342 cfi_adjust_cfa_offset (-4)
344 cfi_adjust_cfa_offset (-4)
346 jz 18f // jump if not odd
347 // It's an odd integer.
349 fldl MOX(minf_mzero, %edx, 8)
352 cfi_adjust_cfa_offset (8)
356 cfi_adjust_cfa_offset (-8)
360 fldl MOX(inf_zero, %eax, 1)
363 cfi_adjust_cfa_offset (8)
365 17: shll $30, %edx // sign bit for y in right position
367 cfi_adjust_cfa_offset (-8)
369 fldl MOX(inf_zero, %edx, 8)
372 cfi_adjust_cfa_offset (8)
379 // x is ±0 and y is < 0. We must find out whether y is an odd integer.
383 // fistpll raises invalid exception for |y| >= 1L<<63, but y
384 // may be odd unless we know |y| >= 1L<<64.
391 fldl MO(p63) // p63 : y
398 fildll (%esp) // int(y) : y
404 // OK, the value is an integer, but is it odd?
406 cfi_adjust_cfa_offset (-4)
408 cfi_adjust_cfa_offset (-4)
410 jz 27f // jump if not odd
411 // It's an odd integer.
412 // Raise divide-by-zero exception and get minus infinity value.
418 cfi_adjust_cfa_offset (8)
421 cfi_adjust_cfa_offset (-8)
422 27: // Raise divide-by-zero exception and get infinity value.
427 cfi_adjust_cfa_offset (8)
429 // x is ±0 and y is > 0. We must find out whether y is an odd integer.
433 // fistpll raises invalid exception for |y| >= 1L<<63, but y
434 // may be odd unless we know |y| >= 1L<<64.
440 fldl MO(p63) // p63 : y
447 fildll (%esp) // int(y) : y
453 // OK, the value is an integer, but is it odd?
455 cfi_adjust_cfa_offset (-4)
457 cfi_adjust_cfa_offset (-4)
459 jz 24f // jump if not odd
460 // It's an odd integer.
464 cfi_adjust_cfa_offset (8)
466 23: addl $8, %esp // Don't use 2 x pop
467 cfi_adjust_cfa_offset (-8)
472 strong_alias (__ieee754_powl, __powl_finite)