740bc7790f25f5fbfab4a85dbd7ff77b2abd756a
[musl] / src / math / x86_64 / expl.s
1 .global expm1l
2 .type expm1l,@function
3 expm1l:
4         fldt 8(%rsp)
5 1:      fldl2e
6         fmulp
7         fld1
8         fld %st(1)
9         fabs
10         fucom %st(1)
11         fnstsw %ax
12         fstp %st(0)
13         fstp %st(0)
14         sahf
15         ja 1f
16         f2xm1
17         ret
18 1:      push %rax
19         call 1f
20         pop %rax
21         fld1
22         fsubrp
23         ret
24
25 .global expl
26 .type expl,@function
27 expl:
28         fldt 8(%rsp)
29         fldl2e
30         fmulp
31         jmp 1f
32
33 .global exp2l
34 .type exp2l,@function
35 exp2l:
36         fldt 8(%rsp)
37 1:      mov $0x467ff000,%eax
38         mov %eax,-16(%rsp)
39         mov $0x80000000,%eax
40         mov %eax,-20(%rsp)
41         xor %eax,%eax
42         mov %eax,-24(%rsp)
43         flds -16(%rsp)    # 16380
44         fld %st(1)
45         fabs
46         fucom %st(1)
47         fnstsw
48         fstp %st(0)
49         fstp %st(0)
50         sahf
51         ja 3f             # |x| > 16380
52         jp 2f             # x is nan (avoid invalid except in fistp)
53         fld %st(0)
54         fistpl -16(%rsp)
55         fildl -16(%rsp)
56         fxch %st(1)
57         fsub %st(1)
58         mov $0x3fff,%eax
59         add %eax,-16(%rsp)
60         f2xm1
61         fld1
62         faddp             # 2^(x-rint(x))
63         fldt -24(%rsp)    # 2^rint(x)
64         fmulp
65 2:      fstp %st(1)
66         ret
67
68 3:      fld %st(0)
69         fstpt -24(%rsp)
70         fld1
71         mov -15(%rsp),%ax
72         and $0x7fff,%ax
73         cmp $0x7fff,%ax
74         je 1f             # x = +-inf
75         fld %st(1)
76         frndint
77         fxch %st(2)
78         fsub %st(2)       # st(0)=x-rint(x), st(1)=1, st(2)=rint(x)
79         f2xm1
80         faddp             # 2^(x-rint(x))
81 1:      fscale
82         fstp %st(1)
83         ret