Merge remote-tracking branch 'nsz/exp'
[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 expl
54 .type expl,@function
55 expl:
56         fldt 4(%esp)
57         jmp 2f
58
59 .global exp
60 .type exp,@function
61 exp:
62         fldl 4(%esp)
63 2:      fldl2e
64         fmulp
65         jmp 1f
66
67 .global exp2
68 .type exp2,@function
69 exp2:
70         fldl 4(%esp)
71 1:      pushl $0x467ff000
72         flds (%esp)       # 16380
73         xorl %eax,%eax
74         pushl $0x80000000
75         push %eax
76         fld %st(1)
77         fabs
78         fucomp %st(1)
79         fnstsw
80         fstp %st(0)
81         sahf
82         ja 3f             # |x| > 16380
83         jp 2f             # x is nan (avoid invalid except in fistp)
84         fld %st(0)
85         fistpl 8(%esp)
86         fildl 8(%esp)
87         fxch %st(1)
88         fsub %st(1)
89         mov $0x3fff,%eax
90         add %eax,8(%esp)
91         f2xm1
92         fld1
93         faddp             # 2^(x-rint(x))
94         fldt (%esp)       # 2^rint(x)
95         fmulp
96         fstp %st(1)
97 2:      add $12,%esp
98         ret
99
100 3:      fld %st(0)
101         fstpt (%esp)
102         fld1
103         mov 8(%esp),%ax
104         and $0x7fff,%ax
105         cmp $0x7fff,%ax
106         je 1f             # x = +-inf
107         fld %st(1)
108         frndint
109         fxch %st(2)
110         fsub %st(2)       # st(0)=x-rint(x), st(1)=1, st(2)=rint(x)
111         f2xm1
112         faddp             # 2^(x-rint(x))
113 1:      fscale
114         fstp %st(1)
115         add $12,%esp
116         ret