]> sourceware.org Git - glibc.git/blob - sysdeps/i386/fpu/e_pow.S
Update.
[glibc.git] / sysdeps / i386 / fpu / e_pow.S
1 /* ix87 specific implementation of pow function.
2 Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
10
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 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 #include <machine/asm.h>
22
23 #ifdef __ELF__
24 .section .rodata
25 #else
26 .text
27 #endif
28
29 .align ALIGNARG(4)
30 ASM_TYPE_DIRECTIVE(infinity,@object)
31 inf_zero:
32 infinity:
33 .byte 0, 0, 0, 0, 0, 0, 0xf0, 0x7f
34 ASM_SIZE_DIRECTIVE(infinity)
35 ASM_TYPE_DIRECTIVE(zero,@object)
36 zero: .double 0.0
37 ASM_SIZE_DIRECTIVE(zero)
38 ASM_TYPE_DIRECTIVE(minf_mzero,@object)
39 minf_mzero:
40 minfinity:
41 .byte 0, 0, 0, 0, 0, 0, 0xf0, 0xff
42 mzero:
43 .byte 0, 0, 0, 0, 0, 0, 0, 0x80
44 ASM_SIZE_DIRECTIVE(minf_mzero)
45 ASM_TYPE_DIRECTIVE(one,@object)
46 one: .double 1.0
47 ASM_SIZE_DIRECTIVE(one)
48 ASM_TYPE_DIRECTIVE(limit,@object)
49 limit: .double 0.29
50 ASM_SIZE_DIRECTIVE(limit)
51
52 #ifdef PIC
53 #define MO(op) op##@GOTOFF(%ecx)
54 #define MOX(op,x,f) op##@GOTOFF(%ecx,x,f)
55 #else
56 #define MO(op) op
57 #define MOX(op,x,f) op(,x,f)
58 #endif
59
60 .text
61 ENTRY(__ieee754_pow)
62 fldl 12(%esp) // y
63 fxam
64
65 #ifdef PIC
66 call 1f
67 1: popl %ecx
68 addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ecx
69 #endif
70
71 fnstsw
72 movb %ah, %dl
73 andb $0x45, %ah
74 cmpb $0x40, %ah // is y == 0 ?
75 je 11f
76
77 cmpb $0x05, %ah // is y == ±inf ?
78 je 12f
79
80 cmpb $0x01, %ah // is y == NaN ?
81 je 30f
82
83 fldl 4(%esp) // x : y
84
85 subl $8,%esp
86
87 fxam
88 fnstsw
89 movb %ah, %dh
90 andb $0x45, %ah
91 cmpb $0x40, %ah
92 je 20f // x is ±0
93
94 cmpb $0x05, %ah
95 je 15f // x is ±inf
96
97 fxch // y : x
98
99 /* First see whether `y' is a natural number. In this case we
100 can use a more precise algorithm. */
101 fld %st // y : y : x
102 fistpll (%esp) // y : x
103 fildll (%esp) // int(y) : y : x
104 fucomp %st(1) // y : x
105 fnstsw
106 sahf
107 jne 2f
108
109 /* OK, we have an integer value for y. */
110 popl %eax
111 popl %edx
112 orl $0, %edx
113 fstp %st(0) // x
114 jns 4f // y >= 0, jump
115 fdivrl MO(one) // 1/x (now referred to as x)
116 negl %eax
117 adcl $0, %edx
118 negl %edx
119 4: fldl MO(one) // 1 : x
120 fxch
121
122 6: shrdl $1, %edx, %eax
123 jnc 5f
124 fxch
125 fmul %st(1) // x : ST*x
126 fxch
127 5: fmul %st(0), %st // x*x : ST*x
128 shrl $1, %edx
129 movl %eax, %ecx
130 orl %edx, %ecx
131 jnz 6b
132 fstp %st(0) // ST*x
133 30: ret
134
135 .align ALIGNARG(4)
136 2: /* y is a real number. */
137 fxch // x : y
138 fldl MO(one) // 1.0 : x : y
139 fld %st(1) // x : 1.0 : x : y
140 fsub %st(1) // x-1 : 1.0 : x : y
141 fabs // |x-1| : 1.0 : x : y
142 fcompl MO(limit) // 1.0 : x : y
143 fnstsw
144 fxch // x : 1.0 : y
145 sahf
146 ja 7f
147 fsub %st(1) // x-1 : 1.0 : y
148 fyl2xp1 // log2(x) : y
149 jmp 8f
150
151 7: fyl2x // log2(x) : y
152 8: fmul %st(1) // y*log2(x) : y
153 fst %st(1) // y*log2(x) : y*log2(x)
154 frndint // int(y*log2(x)) : y*log2(x)
155 fsubr %st, %st(1) // int(y*log2(x)) : fract(y*log2(x))
156 fxch // fract(y*log2(x)) : int(y*log2(x))
157 f2xm1 // 2^fract(y*log2(x))-1 : int(y*log2(x))
158 faddl MO(one) // 2^fract(y*log2(x)) : int(y*log2(x))
159 fscale // 2^fract(y*log2(x))*2^int(y*log2(x)) : int(y*log2(x))
160 addl $8, %esp
161 fstp %st(1) // 2^fract(y*log2(x))*2^int(y*log2(x))
162 ret
163
164
165 // pow(x,±0) = 1
166 .align ALIGNARG(4)
167 11: fstp %st(0) // pop y
168 fldl MO(one)
169 ret
170
171 // y == ±inf
172 .align ALIGNARG(4)
173 12: fstp %st(0) // pop y
174 fldl 4(%esp) // x
175 fabs
176 fcompl MO(one) // < 1, == 1, or > 1
177 fnstsw
178 andb $0x45, %ah
179 cmpb $0x45, %ah
180 je 13f // jump if x is NaN
181
182 cmpb $0x40, %ah
183 je 14f // jump if |x| == 1
184
185 shlb $1, %ah
186 xorb %ah, %dl
187 andl $2, %edx
188 fldl MOX(inf_zero, %edx, 4)
189 ret
190
191 .align ALIGNARG(4)
192 14: fldl MO(infinity)
193 fmull MO(zero) // raise invalid exception
194 ret
195
196 .align ALIGNARG(4)
197 13: fldl 4(%esp) // load x == NaN
198 ret
199
200 .align ALIGNARG(4)
201 // x is ±inf
202 15: fstp %st(0) // y
203 testb $2, %dh
204 jz 16f // jump if x == +inf
205
206 // We must find out whether y is an odd integer.
207 fld %st // y : y
208 fistpll (%esp) // y
209 fildll (%esp) // int(y) : y
210 fucompp // <empty>
211 fnstsw
212 sahf
213 jne 17f
214
215 // OK, the value is an integer, but is the number of bits small
216 // enough so that all are coming from the mantissa?
217 popl %eax
218 popl %edx
219 andb $1, %al
220 jz 18f // jump if not odd
221 movl %edx, %eax
222 orl %edx, %edx
223 jns 155f
224 negl %eax
225 155: cmpl $0x00200000, %eax
226 ja 18f // does not fit in mantissa bits
227 // It's an odd integer.
228 shrl $31, %edx
229 fldl MOX(minf_mzero, %edx, 8)
230 ret
231
232 .align ALIGNARG(4)
233 16: fcompl MO(zero)
234 addl $8, %esp
235 fnstsw
236 shrl $5, %eax
237 andl $8, %eax
238 fldl MOX(inf_zero, %eax, 1)
239 ret
240
241 .align ALIGNARG(4)
242 17: shll $30, %edx // sign bit for y in right position
243 addl $8, %esp
244 18: shrl $31, %edx
245 fldl MOX(inf_zero, %edx, 8)
246 ret
247
248 .align ALIGNARG(4)
249 // x is ±0
250 20: fstp %st(0) // y
251 testb $2, %dl
252 jz 21f // y > 0
253
254 // x is ±0 and y is < 0. We must find out whether y is an odd integer.
255 testb $2, %dh
256 jz 25f
257
258 fld %st // y : y
259 fistpll (%esp) // y
260 fildll (%esp) // int(y) : y
261 fucompp // <empty>
262 fnstsw
263 sahf
264 jne 26f
265
266 // OK, the value is an integer, but is the number of bits small
267 // enough so that all are coming from the mantissa?
268 popl %eax
269 popl %edx
270 andb $1, %al
271 jz 27f // jump if not odd
272 cmpl $0xffe00000, %edx
273 jbe 27f // does not fit in mantissa bits
274 // It's an odd integer.
275 // Raise divide-by-zero exception and get minus infinity value.
276 fldl MO(one)
277 fdivl MO(zero)
278 fchs
279 ret
280
281 25: fstp %st(0)
282 26: addl $8, %esp
283 27: // Raise divide-by-zero exception and get infinity value.
284 fldl MO(one)
285 fdivl MO(zero)
286 ret
287
288 .align ALIGNARG(4)
289 // x is ±0 and y is > 0. We must find out whether y is an odd integer.
290 21: testb $2, %dh
291 jz 22f
292
293 fld %st // y : y
294 fistpll (%esp) // y
295 fildll (%esp) // int(y) : y
296 fucompp // <empty>
297 fnstsw
298 sahf
299 jne 23f
300
301 // OK, the value is an integer, but is the number of bits small
302 // enough so that all are coming from the mantissa?
303 popl %eax
304 popl %edx
305 andb $1, %al
306 jz 24f // jump if not odd
307 cmpl $0xffe00000, %edx
308 jae 24f // does not fit in mantissa bits
309 // It's an odd integer.
310 fldl MO(mzero)
311 ret
312
313 22: fstp %st(0)
314 23: addl $8, %esp // Don't use 2 x pop
315 24: fldl MO(zero)
316 ret
317
318 END(__ieee754_pow)
This page took 0.052019 seconds and 6 git commands to generate.