1 /* ix87 specific implementation of pow function.
2 Copyright (C) 1996-2013 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)
109 /* fistpll raises invalid exception for |y| >= 1L<<63. */
112 fcompl MO(p63) // y : x
117 /* First see whether `y' is a natural number. In this case we
118 can use a more precise algorithm. */
120 fistpll (%esp) // y : x
121 fildll (%esp) // int(y) : y : x
122 fucomp %st(1) // y : x
127 // If y has absolute value at most 0x1p-79, then any finite
128 // nonzero x will result in 1. Saturate y to those bounds to
129 // avoid underflow in the calculation of y*log2(x).
132 fcompl MO(pm79) // y : x
137 fldl MO(pm79) // 0x1p-79 : x
143 9: /* OK, we have an integer value for y. Unless very small
144 (we use < 8), use the algorithm for real exponent to avoid
145 accumulation of errors. */
148 fcompl MO(p3) // y : x
153 cfi_adjust_cfa_offset (-4)
155 cfi_adjust_cfa_offset (-4)
158 jns 4f // y >= 0, jump
159 fdivrl MO(one) // 1/x (now referred to as x)
163 4: fldl MO(one) // 1 : x
166 6: shrdl $1, %edx, %eax
169 fmul %st(1) // x : ST*x
171 5: fmul %st(0), %st // x*x : ST*x
180 30: fldt 4(%esp) // x : y
181 fldl MO(one) // 1.0 : x : y
182 fucomp %st(1) // x : y
190 cfi_adjust_cfa_offset (8)
192 2: // y is a large integer (absolute value at least 8), but
193 // may be odd unless at least 1L<<64. So it may be necessary
194 // to adjust the sign of a negative result afterwards.
198 // If y has absolute value at least 1L<<78, then any finite
199 // nonzero x will result in 0 (underflow), 1 or infinity (overflow).
200 // Saturate y to those bounds to avoid overflow in the calculation
202 fld %st // y : y : |x|
203 fabs // |y| : y : |x|
204 fcompl MO(p78) // y : |x|
209 fldl MO(p78) // 1L<<78 : |x|
212 fchs // -(1L<<78) : |x|
214 3: /* y is a real number. */
216 cfi_adjust_cfa_offset (28)
218 fstpt (%esp) // <empty>
220 call HIDDEN_JUMPTARGET (__powl_helper) // <result>
223 cfi_adjust_cfa_offset (-28)
226 // x is negative. If y is an odd integer, negate the result.
230 fldt 24(%esp) // y : abs(result)
231 fld %st // y : y : abs(result)
232 fabs // |y| : y : abs(result)
233 fcompl MO(p64) // y : abs(result)
237 fldl MO(p63) // p63 : y : abs(result)
238 fxch // y : p63 : abs(result)
239 fprem // y%p63 : p63 : abs(result)
240 fstp %st(1) // y%p63 : abs(result)
242 // We must find out whether y is an odd integer.
243 fld %st // y : y : abs(result)
244 fistpll (%esp) // y : abs(result)
245 fildll (%esp) // int(y) : y : abs(result)
246 fucompp // abs(result)
251 // OK, the value is an integer, but is it odd?
253 cfi_adjust_cfa_offset (-4)
255 cfi_adjust_cfa_offset (-4)
257 jz 290f // jump if not odd
258 // It's an odd integer.
261 cfi_adjust_cfa_offset (8)
262 291: fstp %st(0) // abs(result)
264 cfi_adjust_cfa_offset (-8)
269 11: fstp %st(0) // pop y
275 12: fstp %st(0) // pop y
277 fldt 4(%esp) // x : 1
279 fucompp // < 1, == 1, or > 1
283 je 13f // jump if x is NaN
286 je 14f // jump if |x| == 1
291 fldl MOX(inf_zero, %edx, 4)
299 13: fldt 4(%esp) // load x == NaN
302 cfi_adjust_cfa_offset (8)
307 jz 16f // jump if x == +inf
309 // fistpll raises invalid exception for |y| >= 1L<<63, but y
310 // may be odd unless we know |y| >= 1L<<64.
317 fldl MO(p63) // p63 : y
322 // We must find out whether y is an odd integer.
325 fildll (%esp) // int(y) : y
331 // OK, the value is an integer, but is it odd?
333 cfi_adjust_cfa_offset (-4)
335 cfi_adjust_cfa_offset (-4)
337 jz 18f // jump if not odd
338 // It's an odd integer.
340 fldl MOX(minf_mzero, %edx, 8)
343 cfi_adjust_cfa_offset (8)
347 cfi_adjust_cfa_offset (-8)
351 fldl MOX(inf_zero, %eax, 1)
354 cfi_adjust_cfa_offset (8)
356 17: shll $30, %edx // sign bit for y in right position
358 cfi_adjust_cfa_offset (-8)
360 fldl MOX(inf_zero, %edx, 8)
363 cfi_adjust_cfa_offset (8)
370 // x is ±0 and y is < 0. We must find out whether y is an odd integer.
374 // fistpll raises invalid exception for |y| >= 1L<<63, but y
375 // may be odd unless we know |y| >= 1L<<64.
382 fldl MO(p63) // p63 : y
389 fildll (%esp) // int(y) : y
395 // OK, the value is an integer, but is it odd?
397 cfi_adjust_cfa_offset (-4)
399 cfi_adjust_cfa_offset (-4)
401 jz 27f // jump if not odd
402 // It's an odd integer.
403 // Raise divide-by-zero exception and get minus infinity value.
409 cfi_adjust_cfa_offset (8)
412 cfi_adjust_cfa_offset (-8)
413 27: // Raise divide-by-zero exception and get infinity value.
418 cfi_adjust_cfa_offset (8)
420 // x is ±0 and y is > 0. We must find out whether y is an odd integer.
424 // fistpll raises invalid exception for |y| >= 1L<<63, but y
425 // may be odd unless we know |y| >= 1L<<64.
431 fldl MO(p63) // p63 : y
438 fildll (%esp) // int(y) : y
444 // OK, the value is an integer, but is it odd?
446 cfi_adjust_cfa_offset (-4)
448 cfi_adjust_cfa_offset (-4)
450 jz 24f // jump if not odd
451 // It's an odd integer.
455 cfi_adjust_cfa_offset (8)
457 23: addl $8, %esp // Don't use 2 x pop
458 cfi_adjust_cfa_offset (-8)
463 strong_alias (__ieee754_powl, __powl_finite)