Mon Dec 2 15:32:15 1996 Ulrich Drepper <drepper@cygnus.com>
[glibc.git] / sysdeps / libm-i387 / e_expl.S
blob2884efa6ce116e2b8abbd007276f97bced79e702
1 /*
2  * Written by J.T. Conklin <jtc@netbsd.org>.
3  * Public domain.
4  *
5  * Adapted for `long double' by Ulrich Drepper <drepper@cygnus.com>.
6  */
8 #include <machine/asm.h>
10 RCSID("$NetBSD: $")
12 /* e^x = 2^(x * log2l(e)) */
13 ENTRY(__ieee754_expl)
14         fldt    4(%esp)
15 /* I added the following ugly construct because expl(+-Inf) resulted
16    in NaN.  The ugliness results from the bright minds at Intel.
17    For the i686 the code can be written better.
18    -- drepper@cygnus.com.  */
19         fxam                            /* Is NaN or +-Inf?  */
20         fstsw   %ax
21         sahf
22         jnc     .LnoInfNaN              /* No, jump.   */
23         jp      .LisInf                 /* Is +-Inf, jump.  */
24 .LnoInfNaN:
25         fldl2e
26         fmulp                           /* x * log2(e) */
27         fstl    %st(1)
28         frndint                         /* int(x * log2(e)) */
29         fstl    %st(2)
30         fsubrp                          /* fract(x * log2(e)) */
31         f2xm1                           /* 2^(fract(x * log2(e))) - 1 */
32         fld1
33         faddp                           /* 2^(fract(x * log2(e))) */
34         fscale                          /* e^x */
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 PSEUDO_END (__ieee754_expl)