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