xref: /illumos-gate/usr/src/lib/libm/i386/src/expm1l.S (revision 55fea89d)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
23 */
24/*
25 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
26 * Use is subject to license terms.
27 */
28
29        .file "expm1l.s"
30
31#include "libm.h"
32LIBM_ANSI_PRAGMA_WEAK(expm1l,function)
33
34	.data
35	.align	4
36ln2_hi:	.long	0xd1d00000, 0xb17217f7, 0x00003ffe
37ln2_lo:	.long	0x4c67fc0d, 0x8654361c, 0x0000bfce
38
39	ENTRY(expm1l)
40	movl	12(%esp),%ecx		/ cx <--sign&bexp(x)
41	movl	%ecx,%eax		/ ax <--sign&bexp(x)
42	andl	$0x00007fff,%ecx	/ ecx <-- zero_xtnd(bexp(x))
43	cmpl	$0x00003ffe,%ecx	/ Is |x| < ln(2)?
44	jb	.shortcut		/ If so, take a shortcut.
45	je	.check_tail		/ |x| may be only slightly < ln(2)
46	cmpl	$0x00007fff,%ecx	/ bexp(|x|) = bexp(INF)?
47	je	.not_finite		/ if so, x is not finite
48	andl	$0x0000ffff,%eax	/ eax <-- sign&bexp(x)
49	cmpl	$0x0000c006,%eax	/ x <= -128?
50	jae	1f			/ if so, simply return -1
51	cmpl	$0x0000400d,%ecx	/ |x| < 16384 = 2^14?
52	jb	.finite_non_special	/ if so, proceed with argument reduction
53	fldt	4(%esp)			/ x >= 16384; x
54	fld1				/ 1, x
55	fscale				/ +Inf, x
56	fstp	%st(1)			/ +Inf
57	ret
58
59.finite_non_special:			/ -128 < x < -ln(2) || ln(2) < x < 2^14
60	fldt	4(%esp)			/ x
61	fld	%st(0)			/ x, x
62	fldl2e				/ log2(e), x, x
63	fmulp				/ z := x*log2(e), x
64	frndint				/ [z], x
65	fst	%st(2)			/ [z], x, [z]
66	PIC_SETUP(1)
67	fldt	PIC_L(ln2_hi)		/ ln2_hi, [z], x, [z]
68	fmulp				/ [z]*ln2_hi, x, [z]
69	fsubrp	%st,%st(1)		/ x-[z]*ln2_hi, [z]
70	fldt	PIC_L(ln2_lo)		/ ln2_lo, x-[z]*ln2_hi, [z]
71	PIC_WRAPUP
72	fmul	%st(2),%st		/ [z]*ln2_lo, x-[z]*ln2_hi, [z]
73	fsubrp	%st,%st(1)		/ r := x-[z]*ln(2), [z]
74	fldl2e				/ log2(e), r, [z]
75	fmulp				/ f := r*log2(e), [z]
76	f2xm1				/ 2^f-1,[z]
77	fld1				/ 1, 2^f-1, [z]
78	faddp	%st,%st(1)		/ 2^f, [z]
79	fscale				/ e^x, [z]
80	fstp	%st(1)			/ e^x
81	fld1				/ 1, e^x
82	fsubrp	%st,%st(1)		/ e^x-1
83	ret
84
85.check_tail:
86	movl	8(%esp),%ecx		/ ecx <-- hi_32(sgnfcnd(x))
87	cmpl	$0xb17217f7,%ecx	/ Is |x| < ln(2)?
88	ja	.finite_non_special
89	jb	.shortcut
90	movl	4(%esp),%edx		/ edx <-- lo_32(x)
91	cmpl	$0xd1cf79ab,%edx	/ Is |x| slightly < ln(2)?
92	ja	.finite_non_special	/ branch if |x| slightly > ln(2)
93.shortcut:
94	/ Here, |x| < ln(2), so |z| = |x/ln(2)| < 1,
95	/ whence z is in f2xm1's domain.
96	fldt	4(%esp)			/ x
97	fldl2e				/ log2(e), x
98	fmulp				/ z := x*log2(e)
99	f2xm1				/ 2^(x*log2(e))-1 = e^x-1
100	ret
101
102.not_finite:
103	movl	8(%esp),%ecx		/ ecx <-- hi_32(sgnfcnd(x))
104	cmpl	$0x80000000,%ecx	/ hi_32(|x|) = hi_32(INF)?
105	jne	.NaN_or_pinf		/ if not, x is NaN
106	movl	4(%esp),%edx		/ edx <-- lo_32(x)
107	cmpl	$0,%edx			/ lo_32(x) = 0?
108	jne	.NaN_or_pinf		/ if not, x is NaN
109	movl	12(%esp),%eax		/ ax <-- sign&bexp((x))
110	andl	$0x00008000,%eax	/ here, x is infinite, but +/-?
111	jz	.NaN_or_pinf		/ branch if x = +INF
1121:
113	fld1				/ Here, x = -inf, so return -1
114	fchs
115	ret
116
117.NaN_or_pinf:
118	/ Here, x = NaN or +inf, so load x and return immediately.
119	fldt	4(%esp)
120	ret
121	.align	4
122	SET_SIZE(expm1l)
123