rework langinfo code for ABI compat and for use by time code
[musl] / src / math / x86_64 / exp2l.s
1 .global expm1l
2 .type expm1l,@function
3 expm1l:
4         fldt 8(%rsp)
5         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 exp2l
26 .type exp2l,@function
27 exp2l:
28         fldt 8(%rsp)
29 1:      mov $0x467ff000,%eax
30         mov %eax,-16(%rsp)
31         mov $0x80000000,%eax
32         mov %eax,-20(%rsp)
33         xor %eax,%eax
34         mov %eax,-24(%rsp)
35         flds -16(%rsp)    # 16380
36         fld %st(1)
37         fabs
38         fucom %st(1)
39         fnstsw
40         fstp %st(0)
41         fstp %st(0)
42         sahf
43         ja 3f             # |x| > 16380
44         jp 2f             # x is nan (avoid invalid except in fistp)
45         fld %st(0)
46         fistpl -16(%rsp)
47         fildl -16(%rsp)
48         fxch %st(1)
49         fsub %st(1)
50         mov $0x3fff,%eax
51         add %eax,-16(%rsp)
52         f2xm1
53         fld1
54         faddp             # 2^(x-rint(x))
55         fldt -24(%rsp)    # 2^rint(x)
56         fmulp
57 2:      fstp %st(1)
58         ret
59
60 3:      fld %st(0)
61         fstpt -24(%rsp)
62         fld1
63         mov -15(%rsp),%ax
64         and $0x7fff,%ax
65         cmp $0x7fff,%ax
66         je 1f             # x = +-inf
67         fld %st(1)
68         frndint
69         fxch %st(2)
70         fsub %st(2)       # st(0)=x-rint(x), st(1)=1, st(2)=rint(x)
71         f2xm1
72         faddp             # 2^(x-rint(x))
73 1:      fscale
74         fstp %st(1)
75         ret