1 /* ix87 specific implementation of pow function.
2 Copyright (C) 1996-2015 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 /* If y is even, take the absolute value of x. Otherwise,
170 ensure all intermediate values that might overflow have the
176 6: shrdl $1, %edx, %eax
180 fmul %st(1) // x : ST*x
182 5: fld %st // x : x : ST*x
183 fabs // |x| : x : ST*x
184 fmulp // |x|*x : ST*x
193 30: fldt 4(%esp) // x : y
194 fldl MO(one) // 1.0 : x : y
195 fucomp %st(1) // x : y
203 cfi_adjust_cfa_offset (8)
205 cfi_adjust_cfa_offset (-8)
209 cfi_adjust_cfa_offset (8)
211 2: // y is a large integer (absolute value at least 1L<<63).
212 // If y has absolute value at least 1L<<78, then any finite
213 // nonzero x will result in 0 (underflow), 1 or infinity (overflow).
214 // Saturate y to those bounds to avoid overflow in the calculation
218 fcompl MO(p78) // y : x
223 fldl MO(p78) // 1L<<78 : x
226 fchs // -(1L<<78) : x
228 3: /* y is a real number. */
230 cfi_adjust_cfa_offset (28)
232 fstpt (%esp) // <empty>
233 call HIDDEN_JUMPTARGET (__powl_helper) // <result>
235 cfi_adjust_cfa_offset (-36)
240 11: fstp %st(0) // pop y
246 12: fstp %st(0) // pop y
248 fldt 4(%esp) // x : 1
250 fucompp // < 1, == 1, or > 1
254 je 13f // jump if x is NaN
257 je 14f // jump if |x| == 1
262 fldl MOX(inf_zero, %edx, 4)
270 13: fldt 4(%esp) // load x == NaN
273 cfi_adjust_cfa_offset (8)
278 jz 16f // jump if x == +inf
280 // fistpll raises invalid exception for |y| >= 1L<<63, but y
281 // may be odd unless we know |y| >= 1L<<64.
288 fldl MO(p63) // p63 : y
293 // We must find out whether y is an odd integer.
296 fildll (%esp) // int(y) : y
302 // OK, the value is an integer, but is it odd?
304 cfi_adjust_cfa_offset (-4)
306 cfi_adjust_cfa_offset (-4)
308 jz 18f // jump if not odd
309 // It's an odd integer.
311 fldl MOX(minf_mzero, %edx, 8)
314 cfi_adjust_cfa_offset (8)
318 cfi_adjust_cfa_offset (-8)
322 fldl MOX(inf_zero, %eax, 1)
325 cfi_adjust_cfa_offset (8)
327 17: shll $30, %edx // sign bit for y in right position
329 cfi_adjust_cfa_offset (-8)
331 fldl MOX(inf_zero, %edx, 8)
334 cfi_adjust_cfa_offset (8)
341 // x is ±0 and y is < 0. We must find out whether y is an odd integer.
345 // fistpll raises invalid exception for |y| >= 1L<<63, but y
346 // may be odd unless we know |y| >= 1L<<64.
353 fldl MO(p63) // p63 : y
360 fildll (%esp) // int(y) : y
366 // OK, the value is an integer, but is it odd?
368 cfi_adjust_cfa_offset (-4)
370 cfi_adjust_cfa_offset (-4)
372 jz 27f // jump if not odd
373 // It's an odd integer.
374 // Raise divide-by-zero exception and get minus infinity value.
380 cfi_adjust_cfa_offset (8)
383 cfi_adjust_cfa_offset (-8)
384 27: // Raise divide-by-zero exception and get infinity value.
389 cfi_adjust_cfa_offset (8)
391 // x is ±0 and y is > 0. We must find out whether y is an odd integer.
395 // fistpll raises invalid exception for |y| >= 1L<<63, but y
396 // may be odd unless we know |y| >= 1L<<64.
402 fldl MO(p63) // p63 : y
409 fildll (%esp) // int(y) : y
415 // OK, the value is an integer, but is it odd?
417 cfi_adjust_cfa_offset (-4)
419 cfi_adjust_cfa_offset (-4)
421 jz 24f // jump if not odd
422 // It's an odd integer.
426 cfi_adjust_cfa_offset (8)
428 23: addl $8, %esp // Don't use 2 x pop
429 cfi_adjust_cfa_offset (-8)
434 strong_alias (__ieee754_powl, __powl_finite)