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