fix fesetenv(FE_DFL_ENV) on mips
[musl] / src / math / i386 / exp.s
1 .global expm1f
2 .type expm1f,@function
3 expm1f:
4         flds 4(%esp)
5         mov 4(%esp),%eax
6         add %eax,%eax
7         cmp $0x01000000,%eax
8         jae 1f
9                 # subnormal x, return x with underflow
10         fnstsw %ax
11         and $16,%ax
12         jnz 2f
13         fld %st(0)
14         fmul %st(1)
15         fstps 4(%esp)
16 2:      ret
17
18 .global expm1l
19 .type expm1l,@function
20 expm1l:
21         fldt 4(%esp)
22         jmp 1f
23
24 .global expm1
25 .type expm1,@function
26 expm1:
27         fldl 4(%esp)
28         mov 8(%esp),%eax
29         add %eax,%eax
30         cmp $0x00200000,%eax
31         jae 1f
32                 # subnormal x, return x with underflow
33         fnstsw %ax
34         and $16,%ax
35         jnz 2f
36         fsts 4(%esp)
37 2:      ret
38 1:      fldl2e
39         fmulp
40         mov $0xc2820000,%eax
41         push %eax
42         flds (%esp)
43         pop %eax
44         fucomp %st(1)
45         fnstsw %ax
46         sahf
47         fld1
48         jb 1f
49                 # x*log2e < -65, return -1 without underflow
50         fstp %st(1)
51         fchs
52         ret
53 1:      fld %st(1)
54         fabs
55         fucom %st(1)
56         fnstsw %ax
57         fstp %st(0)
58         fstp %st(0)
59         sahf
60         ja 1f
61         f2xm1
62         ret
63 1:      call 1f
64         fld1
65         fsubrp
66         ret
67
68 .global exp2f
69 .type exp2f,@function
70 exp2f:
71         flds 4(%esp)
72         jmp 1f
73
74 .global exp2l
75 .type exp2l,@function
76 exp2l:
77         fldt 4(%esp)
78         jmp 1f
79
80 .global expf
81 .type expf,@function
82 expf:
83         flds 4(%esp)
84         jmp 2f
85
86 .global exp
87 .type exp,@function
88 exp:
89         fldl 4(%esp)
90 2:      fldl2e
91         fmulp
92         jmp 1f
93
94 .global exp2
95 .type exp2,@function
96 exp2:
97         fldl 4(%esp)
98 1:      sub $12,%esp
99         fld %st(0)
100         fstpt (%esp)
101         mov 8(%esp),%ax
102         and $0x7fff,%ax
103         cmp $0x3fff+13,%ax
104         jb 4f             # |x| < 8192
105         cmp $0x3fff+15,%ax
106         jae 3f            # |x| >= 32768
107         fsts (%esp)
108         cmpl $0xc67ff800,(%esp)
109         jb 2f             # x > -16382
110         movl $0x5f000000,(%esp)
111         flds (%esp)       # 0x1p63
112         fld %st(1)
113         fsub %st(1)
114         faddp
115         fucomp %st(1)
116         fnstsw
117         sahf
118         je 2f             # x - 0x1p63 + 0x1p63 == x
119         movl $1,(%esp)
120         flds (%esp)       # 0x1p-149
121         fdiv %st(1)
122         fstps (%esp)      # raise underflow
123 2:      fld1
124         fld %st(1)
125         frndint
126         fxch %st(2)
127         fsub %st(2)       # st(0)=x-rint(x), st(1)=1, st(2)=rint(x)
128         f2xm1
129         faddp             # 2^(x-rint(x))
130 1:      fscale
131         fstp %st(1)
132         add $12,%esp
133         ret
134 3:      xor %eax,%eax
135 4:      cmp $0x3fff-64,%ax
136         fld1
137         jb 1b             # |x| < 0x1p-64
138         fstpt (%esp)
139         fistl 8(%esp)
140         fildl 8(%esp)
141         fsubrp %st(1)
142         addl $0x3fff,8(%esp)
143         f2xm1
144         fld1
145         faddp             # 2^(x-rint(x))
146         fldt (%esp)       # 2^rint(x)
147         fmulp
148         add $12,%esp
149         ret