import vanilla x86_64 code as x32
[oweals/musl.git] / src / math / x32 / exp2l.s
1 .global expm1l
2 .type expm1l,@function
3 expm1l:
4         fldt 8(%rsp)
5         fldl2e
6         fmulp
7         movl $0xc2820000,-4(%rsp)
8         flds -4(%rsp)
9         fucomp %st(1)
10         fnstsw %ax
11         sahf
12         fld1
13         jb 1f
14                 # x*log2e <= -65, return -1 without underflow
15         fstp %st(1)
16         fchs
17         ret
18 1:      fld %st(1)
19         fabs
20         fucom %st(1)
21         fnstsw %ax
22         fstp %st(0)
23         fstp %st(0)
24         sahf
25         ja 1f
26         f2xm1
27         ret
28 1:      push %rax
29         call 1f
30         pop %rax
31         fld1
32         fsubrp
33         ret
34
35 .global exp2l
36 .type exp2l,@function
37 exp2l:
38         fldt 8(%rsp)
39 1:      fld %st(0)
40         sub $16,%rsp
41         fstpt (%rsp)
42         mov 8(%rsp),%ax
43         and $0x7fff,%ax
44         cmp $0x3fff+13,%ax
45         jb 4f             # |x| < 8192
46         cmp $0x3fff+15,%ax
47         jae 3f            # |x| >= 32768
48         fsts (%rsp)
49         cmpl $0xc67ff800,(%rsp)
50         jb 2f             # x > -16382
51         movl $0x5f000000,(%rsp)
52         flds (%rsp)       # 0x1p63
53         fld %st(1)
54         fsub %st(1)
55         faddp
56         fucomp %st(1)
57         fnstsw
58         sahf
59         je 2f             # x - 0x1p63 + 0x1p63 == x
60         movl $1,(%rsp)
61         flds (%rsp)       # 0x1p-149
62         fdiv %st(1)
63         fstps (%rsp)      # raise underflow
64 2:      fld1
65         fld %st(1)
66         frndint
67         fxch %st(2)
68         fsub %st(2)       # st(0)=x-rint(x), st(1)=1, st(2)=rint(x)
69         f2xm1
70         faddp             # 2^(x-rint(x))
71 1:      fscale
72         fstp %st(1)
73         add $16,%rsp
74         ret
75 3:      xor %eax,%eax
76 4:      cmp $0x3fff-64,%ax
77         fld1
78         jb 1b             # |x| < 0x1p-64
79         fstpt (%rsp)
80         fistl 8(%rsp)
81         fildl 8(%rsp)
82         fsubrp %st(1)
83         addl $0x3fff,8(%rsp)
84         f2xm1
85         fld1
86         faddp             # 2^(x-rint(x))
87         fldt (%rsp)       # 2^rint(x)
88         fmulp
89         add $16,%rsp
90         ret