update from main archive 961229
[glibc.git] / sysdeps / libm-i387 / e_expf.S
blobc8233eba5095bd4e424f20574f0cc84fad00349c
1 /*
2  * Written by J.T. Conklin <jtc@netbsd.org>.
3  * Public domain.
4  * Adapted for float type by Ulrich Drepper <drepper@cygnus.com>.
5  */
7 #include <machine/asm.h>
9 RCSID("$NetBSD: $")
11 /* e^x = 2^(x * log2(e)) */
12 ENTRY(__ieee754_expf)
13         flds    4(%esp)
14 /* I added the following ugly construct because exp(+-Inf) resulted
15    in NaN.  The ugliness results from the bright minds at Intel.
16    For the i686 the code can be written better.
17    -- drepper@cygnus.com.  */
18         fxam                            /* Is NaN or +-Inf?  */
19         fstsw   %ax
20         sahf
21         jnc     .LnoInfNaN              /* No, jump.   */
22         jp      .LisInf                 /* Is +-Inf, jump.  */
23 .LnoInfNaN:
24         fldl2e
25         fmulp                           /* x * log2(e) */
26         fstl    %st(1)
27         frndint                         /* int(x * log2(e)) */
28         fstl    %st(2)
29         fsubrp                          /* fract(x * log2(e)) */
30         f2xm1                           /* 2^(fract(x * log2(e))) - 1 */
31         fld1
32         faddp                           /* 2^(fract(x * log2(e))) */
33         fscale                          /* e^x */
34         fstp    %st(1)
35         ret
37 .LisInf:
38         andb    $2, %ah                 /* Test sign.  */
39         jz      .LpInf                  /* If positive, jump.  */
40         fldz                            /* Set result to 0.  */
41 .LpInf: ret
42 END (__ieee754_expf)