math: fix i386/expl.s with more precise x*log2e
[musl] / src / math / i386 / exp.s
1 .global expm1f
2 .type expm1f,@function
3 expm1f:
4         flds 4(%esp)
5         jmp 1f
6
7 .global expm1l
8 .type expm1l,@function
9 expm1l:
10         fldt 4(%esp)
11         jmp 1f
12
13 .global expm1
14 .type expm1,@function
15 expm1:
16         fldl 4(%esp)
17 1:      fldl2e
18         fmulp
19         fld1
20         fld %st(1)
21         fabs
22         fucom %st(1)
23         fnstsw %ax
24         fstp %st(0)
25         fstp %st(0)
26         sahf
27         ja 1f
28         f2xm1
29         ret
30 1:      call 1f
31         fld1
32         fsubrp
33         ret
34
35 .global exp2f
36 .type exp2f,@function
37 exp2f:
38         flds 4(%esp)
39         jmp 1f
40
41 .global exp2l
42 .type exp2l,@function
43 exp2l:
44         fldt 4(%esp)
45         jmp 1f
46
47 .global expf
48 .type expf,@function
49 expf:
50         flds 4(%esp)
51         jmp 2f
52
53 .global exp
54 .type exp,@function
55 exp:
56         fldl 4(%esp)
57 2:      fldl2e
58         fmulp
59         jmp 1f
60
61 .global exp2
62 .type exp2,@function
63 exp2:
64         fldl 4(%esp)
65 1:      pushl $0x467ff000
66         flds (%esp)       # 16380
67         xorl %eax,%eax
68         pushl $0x80000000
69         push %eax
70         fld %st(1)
71         fabs
72         fucomp %st(1)
73         fnstsw
74         fstp %st(0)
75         sahf
76         ja 3f             # |x| > 16380
77         jp 2f             # x is nan (avoid invalid except in fistp)
78         fld %st(0)
79         fistpl 8(%esp)
80         fildl 8(%esp)
81         fxch %st(1)
82         fsub %st(1)
83         mov $0x3fff,%eax
84         add %eax,8(%esp)
85         f2xm1
86         fld1
87         faddp             # 2^(x-rint(x))
88         fldt (%esp)       # 2^rint(x)
89         fmulp
90         fstp %st(1)
91 2:      add $12,%esp
92         ret
93
94 3:      fld %st(0)
95         fstpt (%esp)
96         fld1
97         mov 8(%esp),%ax
98         and $0x7fff,%ax
99         cmp $0x7fff,%ax
100         je 1f             # x = +-inf
101         fld %st(1)
102         frndint
103         fxch %st(2)
104         fsub %st(2)       # st(0)=x-rint(x), st(1)=1, st(2)=rint(x)
105         f2xm1
106         faddp             # 2^(x-rint(x))
107 1:      fscale
108         fstp %st(1)
109         add $12,%esp
110         ret