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##(%rip)
78 cmpb $0x40, %ah // is y == 0 ?
81 cmpb $0x05, %ah // is y == ±inf ?
84 cmpb $0x01, %ah // is y == NaN ?
104 /* fistpll raises invalid exception for |y| >= 1L<<63. */
105 fldl MO(p63) // 1L<<63 : y : x
106 fld %st(1) // y : 1L<<63 : y : x
107 fabs // |y| : 1L<<63 : y : x
108 fcomip %st(1), %st // 1L<<63 : y : x
112 /* First see whether `y' is a natural number. In this case we
113 can use a more precise algorithm. */
115 fistpll -8(%rsp) // y : x
116 fildll -8(%rsp) // int(y) : y : x
117 fucomip %st(1),%st // y : x
120 // If y has absolute value at most 0x1p-79, then any finite
121 // nonzero x will result in 1. Saturate y to those bounds to
122 // avoid underflow in the calculation of y*log2(x).
123 fldl MO(pm79) // 0x1p-79 : y : x
124 fld %st(1) // y : 0x1p-79 : y : x
125 fabs // |y| : 0x1p-79 : y : x
126 fcomip %st(1), %st // 0x1p-79 : y : x
130 fldl MO(pm79) // 0x1p-79 : x
136 9: /* OK, we have an integer value for y. Unless very small
137 (we use < 8), use the algorithm for real exponent to avoid
138 accumulation of errors. */
139 fldl MO(p3) // 8 : y : x
140 fld %st(1) // y : 8 : y : x
141 fabs // |y| : 8 : y : x
142 fcomip %st(1), %st // 8 : y : x
149 jns 4f // y >= 0, jump
150 fdivrl MO(one) // 1/x (now referred to as x)
154 4: fldl MO(one) // 1 : x
157 /* If y is even, take the absolute value of x. Otherwise,
158 ensure all intermediate values that might overflow have the
164 6: shrdl $1, %edx, %eax
168 fmul %st(1) // x : ST*x
170 5: fld %st // x : x : ST*x
171 fabs // |x| : x : ST*x
172 fmulp // |x|*x : ST*x
181 30: fldt 8(%rsp) // x : y
182 fldl MO(one) // 1.0 : x : y
183 fucomip %st(1),%st // x : y
190 2: // y is a large integer (absolute value at least 1L<<63).
191 // If y has absolute value at least 1L<<78, then any finite
192 // nonzero x will result in 0 (underflow), 1 or infinity (overflow).
193 // Saturate y to those bounds to avoid overflow in the calculation
195 fldl MO(p78) // 1L<<78 : y : x
196 fld %st(1) // y : 1L<<78 : y : x
197 fabs // |y| : 1L<<78 : y : x
198 fcomip %st(1), %st // 1L<<78 : y : x
202 fldl MO(p78) // 1L<<78 : x
205 fchs // -(1L<<78) : x
207 3: /* y is a real number. */
209 cfi_adjust_cfa_offset (40)
211 fstpt (%rsp) // <empty>
212 call HIDDEN_JUMPTARGET (__powl_helper) // <result>
214 cfi_adjust_cfa_offset (-40)
219 11: fstp %st(0) // pop y
225 12: fstp %st(0) // pop y
227 fldt 8(%rsp) // x : 1
229 fucompp // < 1, == 1, or > 1
233 je 13f // jump if x is NaN
236 je 14f // jump if |x| == 1
242 lea inf_zero(%rip),%rcx
245 fldl inf_zero(,%rdx, 4)
254 13: fldt 8(%rsp) // load x == NaN
261 jz 16f // jump if x == +inf
263 // fistpll raises invalid exception for |y| >= 1L<<63, but y
264 // may be odd unless we know |y| >= 1L<<64.
265 fldl MO(p64) // 1L<<64 : y
266 fld %st(1) // y : 1L<<64 : y
267 fabs // |y| : 1L<<64 : y
268 fcomip %st(1), %st // 1L<<64 : y
271 fldl MO(p63) // p63 : y
276 // We must find out whether y is an odd integer.
278 fistpll -8(%rsp) // y
279 fildll -8(%rsp) // int(y) : y
281 ffreep %st // <empty>
284 // OK, the value is an integer, but is it odd?
288 jz 18f // jump if not odd
289 // It's an odd integer.
292 lea minf_mzero(%rip),%rcx
295 fldl minf_mzero(,%rdx, 8)
305 lea inf_zero(%rip),%rcx
308 fldl inf_zero(,%rax, 1)
313 17: shll $30, %edx // sign bit for y in right position
316 lea inf_zero(%rip),%rcx
319 fldl inf_zero(,%rdx, 8)
329 // x is ±0 and y is < 0. We must find out whether y is an odd integer.
333 // fistpll raises invalid exception for |y| >= 1L<<63, but y
334 // may be odd unless we know |y| >= 1L<<64.
335 fldl MO(p64) // 1L<<64 : y
336 fld %st(1) // y : 1L<<64 : y
337 fabs // |y| : 1L<<64 : y
338 fcomip %st(1), %st // 1L<<64 : y
341 fldl MO(p63) // p63 : y
347 fistpll -8(%rsp) // y
348 fildll -8(%rsp) // int(y) : y
350 ffreep %st // <empty>
353 // OK, the value is an integer, but is it odd?
357 jz 27f // jump if not odd
358 // It's an odd integer.
359 // Raise divide-by-zero exception and get minus infinity value.
367 27: // Raise divide-by-zero exception and get infinity value.
373 // x is ±0 and y is > 0. We must find out whether y is an odd integer.
377 // fistpll raises invalid exception for |y| >= 1L<<63, but y
378 // may be odd unless we know |y| >= 1L<<64.
379 fldl MO(p64) // 1L<<64 : y
381 fcomi %st(1), %st // y : 1L<<64
384 fldl MO(p63) // p63 : y
390 fistpll -8(%rsp) // y
391 fildll -8(%rsp) // int(y) : y
393 ffreep %st // <empty>
396 // OK, the value is an integer, but is it odd?
400 jz 24f // jump if not odd
401 // It's an odd integer.
411 strong_alias (__ieee754_powl, __powl_finite)