1 /* ix87 specific implementation of pow function.
2 Copyright (C) 1996-2019 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>
21 #include <i386-math-asm.h>
23 .section .rodata.cst8,"aM",@progbits,8
28 ASM_SIZE_DIRECTIVE(one)
30 p2: .byte 0, 0, 0, 0, 0, 0, 0x10, 0x40
31 ASM_SIZE_DIRECTIVE(p2)
33 p63: .byte 0, 0, 0, 0, 0, 0, 0xe0, 0x43
34 ASM_SIZE_DIRECTIVE(p63)
36 p64: .byte 0, 0, 0, 0, 0, 0, 0xf0, 0x43
37 ASM_SIZE_DIRECTIVE(p64)
39 p78: .byte 0, 0, 0, 0, 0, 0, 0xd0, 0x44
40 ASM_SIZE_DIRECTIVE(p78)
42 pm79: .byte 0, 0, 0, 0, 0, 0, 0, 0x3b
43 ASM_SIZE_DIRECTIVE(pm79)
45 .section .rodata.cst16,"aM",@progbits,16
48 .type infinity,@object
51 .byte 0, 0, 0, 0, 0, 0, 0xf0, 0x7f
52 ASM_SIZE_DIRECTIVE(infinity)
55 ASM_SIZE_DIRECTIVE(zero)
56 .type minf_mzero,@object
59 .byte 0, 0, 0, 0, 0, 0, 0xf0, 0xff
61 .byte 0, 0, 0, 0, 0, 0, 0, 0x80
62 ASM_SIZE_DIRECTIVE(minf_mzero)
66 # define MO(op) op##@GOTOFF(%ecx)
67 # define MOX(op,x,f) op##@GOTOFF(%ecx,x,f)
70 # define MOX(op,x,f) op(,x,f)
85 cmpb $0x40, %ah // is y == 0 ?
88 cmpb $0x05, %ah // is y == ±inf ?
91 cmpb $0x01, %ah // is y == NaN ?
97 cfi_adjust_cfa_offset (8)
114 /* fistpll raises invalid exception for |y| >= 1L<<63. */
117 fcompl MO(p63) // y : x
122 /* First see whether `y' is a natural number. In this case we
123 can use a more precise algorithm. */
125 fistpll (%esp) // y : x
126 fildll (%esp) // int(y) : y : x
127 fucomp %st(1) // y : x
132 // If y has absolute value at most 0x1p-79, then any finite
133 // nonzero x will result in 1. Saturate y to those bounds to
134 // avoid underflow in the calculation of y*log2(x).
137 fcompl MO(pm79) // y : x
142 fldl MO(pm79) // 0x1p-79 : x
148 9: /* OK, we have an integer value for y. Unless very small
149 (we use < 4), use the algorithm for real exponent to avoid
150 accumulation of errors. */
153 fcompl MO(p2) // y : x
158 cfi_adjust_cfa_offset (-4)
160 cfi_adjust_cfa_offset (-4)
163 jns 4f // y >= 0, jump
164 fdivrl MO(one) // 1/x (now referred to as x)
168 4: fldl MO(one) // 1 : x
171 /* If y is even, take the absolute value of x. Otherwise,
172 ensure all intermediate values that might overflow have the
178 6: shrdl $1, %edx, %eax
182 fmul %st(1) // x : ST*x
184 5: fld %st // x : x : ST*x
185 fabs // |x| : x : ST*x
186 fmulp // |x|*x : ST*x
195 LDBL_CHECK_FORCE_UFLOW_NONNAN
199 30: fldt 4(%esp) // x : y
200 fldl MO(one) // 1.0 : x : y
201 fucomp %st(1) // x : y
205 31: /* At least one argument NaN, and result should be NaN. */
209 /* pow (1, NaN); check if the NaN signaling. */
210 testb $0x40, 23(%esp)
215 cfi_adjust_cfa_offset (8)
217 cfi_adjust_cfa_offset (-8)
221 cfi_adjust_cfa_offset (8)
223 2: // y is a large integer (absolute value at least 1L<<63).
224 // If y has absolute value at least 1L<<78, then any finite
225 // nonzero x will result in 0 (underflow), 1 or infinity (overflow).
226 // Saturate y to those bounds to avoid overflow in the calculation
230 fcompl MO(p78) // y : x
235 fldl MO(p78) // 1L<<78 : x
238 fchs // -(1L<<78) : x
240 3: /* y is a real number. */
242 cfi_adjust_cfa_offset (28)
244 fstpt (%esp) // <empty>
245 call HIDDEN_JUMPTARGET (__powl_helper) // <result>
247 cfi_adjust_cfa_offset (-36)
250 // pow(x,±0) = 1, unless x is sNaN
252 11: fstp %st(0) // pop y
263 112: testb $0x40, 11(%esp)
270 12: fstp %st(0) // pop y
272 fldt 4(%esp) // x : 1
274 fucompp // < 1, == 1, or > 1
278 je 13f // jump if x is NaN
281 je 14f // jump if |x| == 1
286 fldl MOX(inf_zero, %edx, 4)
294 13: fldt 4(%esp) // load x == NaN
298 cfi_adjust_cfa_offset (8)
303 jz 16f // jump if x == +inf
305 // fistpll raises invalid exception for |y| >= 1L<<63, but y
306 // may be odd unless we know |y| >= 1L<<64.
313 fldl MO(p63) // p63 : y
318 // We must find out whether y is an odd integer.
321 fildll (%esp) // int(y) : y
327 // OK, the value is an integer, but is it odd?
329 cfi_adjust_cfa_offset (-4)
331 cfi_adjust_cfa_offset (-4)
333 jz 18f // jump if not odd
334 // It's an odd integer.
336 fldl MOX(minf_mzero, %edx, 8)
339 cfi_adjust_cfa_offset (8)
343 cfi_adjust_cfa_offset (-8)
347 fldl MOX(inf_zero, %eax, 1)
350 cfi_adjust_cfa_offset (8)
352 17: shll $30, %edx // sign bit for y in right position
354 cfi_adjust_cfa_offset (-8)
356 fldl MOX(inf_zero, %edx, 8)
359 cfi_adjust_cfa_offset (8)
366 // x is ±0 and y is < 0. We must find out whether y is an odd integer.
370 // fistpll raises invalid exception for |y| >= 1L<<63, but y
371 // may be odd unless we know |y| >= 1L<<64.
378 fldl MO(p63) // p63 : y
385 fildll (%esp) // int(y) : y
391 // OK, the value is an integer, but is it odd?
393 cfi_adjust_cfa_offset (-4)
395 cfi_adjust_cfa_offset (-4)
397 jz 27f // jump if not odd
398 // It's an odd integer.
399 // Raise divide-by-zero exception and get minus infinity value.
405 cfi_adjust_cfa_offset (8)
408 cfi_adjust_cfa_offset (-8)
409 27: // Raise divide-by-zero exception and get infinity value.
414 cfi_adjust_cfa_offset (8)
416 // x is ±0 and y is > 0. We must find out whether y is an odd integer.
420 // fistpll raises invalid exception for |y| >= 1L<<63, but y
421 // may be odd unless we know |y| >= 1L<<64.
427 fldl MO(p63) // p63 : y
434 fildll (%esp) // int(y) : y
440 // OK, the value is an integer, but is it odd?
442 cfi_adjust_cfa_offset (-4)
444 cfi_adjust_cfa_offset (-4)
446 jz 24f // jump if not odd
447 // It's an odd integer.
451 cfi_adjust_cfa_offset (8)
453 23: addl $8, %esp // Don't use 2 x pop
454 cfi_adjust_cfa_offset (-8)
459 strong_alias (__ieee754_powl, __powl_finite)