125c28e8Piotr Jasiukajtis/*
225c28e8Piotr Jasiukajtis * CDDL HEADER START
325c28e8Piotr Jasiukajtis *
425c28e8Piotr Jasiukajtis * The contents of this file are subject to the terms of the
525c28e8Piotr Jasiukajtis * Common Development and Distribution License (the "License").
625c28e8Piotr Jasiukajtis * You may not use this file except in compliance with the License.
725c28e8Piotr Jasiukajtis *
825c28e8Piotr Jasiukajtis * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
925c28e8Piotr Jasiukajtis * or http://www.opensolaris.org/os/licensing.
1025c28e8Piotr Jasiukajtis * See the License for the specific language governing permissions
1125c28e8Piotr Jasiukajtis * and limitations under the License.
1225c28e8Piotr Jasiukajtis *
1325c28e8Piotr Jasiukajtis * When distributing Covered Code, include this CDDL HEADER in each
1425c28e8Piotr Jasiukajtis * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1525c28e8Piotr Jasiukajtis * If applicable, add the following below this CDDL HEADER, with the
1625c28e8Piotr Jasiukajtis * fields enclosed by brackets "[]" replaced with your own identifying
1725c28e8Piotr Jasiukajtis * information: Portions Copyright [yyyy] [name of copyright owner]
1825c28e8Piotr Jasiukajtis *
1925c28e8Piotr Jasiukajtis * CDDL HEADER END
2025c28e8Piotr Jasiukajtis */
2125c28e8Piotr Jasiukajtis/*
2225c28e8Piotr Jasiukajtis * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
2325c28e8Piotr Jasiukajtis */
2425c28e8Piotr Jasiukajtis/*
2525c28e8Piotr Jasiukajtis * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
2625c28e8Piotr Jasiukajtis * Use is subject to license terms.
2725c28e8Piotr Jasiukajtis */
2825c28e8Piotr Jasiukajtis
2925c28e8Piotr Jasiukajtis        .file "exp2.s"
3025c28e8Piotr Jasiukajtis
3125c28e8Piotr Jasiukajtis#include "libm.h"
3225c28e8Piotr JasiukajtisLIBM_ANSI_PRAGMA_WEAK(exp2,function)
3325c28e8Piotr Jasiukajtis
3425c28e8Piotr Jasiukajtis	ENTRY(exp2)
3525c28e8Piotr Jasiukajtis	movl	8(%esp),%ecx		/ ecx <-- hi_32(x)
3625c28e8Piotr Jasiukajtis	andl	$0x7fffffff,%ecx	/ ecx <-- hi_32(|x|)
3725c28e8Piotr Jasiukajtis	cmpl	$0x3ff00000,%ecx	/ Is |x| < 1?
3825c28e8Piotr Jasiukajtis	jb	.shortcut		/ If so, take a shortcut.
3925c28e8Piotr Jasiukajtis	je	.check_tail		/ |x| may be only slightly < ln(2)
4025c28e8Piotr Jasiukajtis	cmpl	$0x7ff00000,%ecx	/ hi_32(|x|) >= hi_32(INF)?
4125c28e8Piotr Jasiukajtis	jae	.not_finite		/ if so, x is not finite
4225c28e8Piotr Jasiukajtis.finite_non_special:			/ Here, 1 < |x| < INF
4325c28e8Piotr Jasiukajtis	fldl	4(%esp)			/ push arg
4425c28e8Piotr Jasiukajtis	fld	%st(0)			/ duplicate stack top
4525c28e8Piotr Jasiukajtis	frndint				/ [x],x
4625c28e8Piotr Jasiukajtis	fucom				/ x integral?
4725c28e8Piotr Jasiukajtis	fstsw	%ax
4825c28e8Piotr Jasiukajtis	sahf
4925c28e8Piotr Jasiukajtis	je      .x_integral		/ branch if x integral
5025c28e8Piotr Jasiukajtis	fxch				/ x, [x]
5125c28e8Piotr Jasiukajtis	fsub	%st(1),%st		/ x-[x], [x]
5225c28e8Piotr Jasiukajtis	f2xm1				/ 2**(x-[x])-1, [x]
5325c28e8Piotr Jasiukajtis	fld1				/ 1,2**(x-[x])-1, [x]
5425c28e8Piotr Jasiukajtis	faddp	%st,%st(1)		/ 2**(x-[x]), [x]
5525c28e8Piotr Jasiukajtis	fscale				/ 2**x = 2**(arg), [x]
5625c28e8Piotr Jasiukajtis	fstp	%st(1)
5725c28e8Piotr Jasiukajtis	ret
5825c28e8Piotr Jasiukajtis
5925c28e8Piotr Jasiukajtis.x_integral:
6025c28e8Piotr Jasiukajtis	fstp	%st(0)			/ ,x
6125c28e8Piotr Jasiukajtis	fld1				/ 1 = 2**0, x
6225c28e8Piotr Jasiukajtis	fscale				/ 2**(0 + x) = 2**x, x
6325c28e8Piotr Jasiukajtis	fstp	%st(1)			/ 2**x
6425c28e8Piotr Jasiukajtis	ret
6525c28e8Piotr Jasiukajtis
6625c28e8Piotr Jasiukajtis.check_tail:
6725c28e8Piotr Jasiukajtis	movl	4(%esp),%edx		/ edx <-- lo_32(x)
6825c28e8Piotr Jasiukajtis	cmpl	$0x00000000,%edx	/ Is |x| slightly > 1?
6925c28e8Piotr Jasiukajtis	ja	.finite_non_special	/ branch if |x| slightly > 1
7025c28e8Piotr Jasiukajtis.shortcut:
7125c28e8Piotr Jasiukajtis	/ Here, |x| <= 1,
7225c28e8Piotr Jasiukajtis	/ whence x is in f2xm1's domain.
7325c28e8Piotr Jasiukajtis	fldl	4(%esp)			/ push x
7425c28e8Piotr Jasiukajtis	f2xm1				/ 2**x - 1
7525c28e8Piotr Jasiukajtis	fld1				/ 1,2**x - 1
7625c28e8Piotr Jasiukajtis	faddp	%st,%st(1)		/ 2**x
7725c28e8Piotr Jasiukajtis	ret
7825c28e8Piotr Jasiukajtis
7925c28e8Piotr Jasiukajtis.not_finite:
8025c28e8Piotr Jasiukajtis	cmpl	$0x7ff00000,%ecx	/ hi_32(|x|) > hi_32(INF)?
8125c28e8Piotr Jasiukajtis	ja	.NaN_or_pinf		/ if so, x is NaN
8225c28e8Piotr Jasiukajtis	movl	4(%esp),%edx		/ edx <-- lo_32(x)
8325c28e8Piotr Jasiukajtis	cmpl	$0,%edx			/ lo_32(x) = 0?
8425c28e8Piotr Jasiukajtis	jne	.NaN_or_pinf		/ if not, x is NaN
8525c28e8Piotr Jasiukajtis	movl	8(%esp),%eax		/ eax <-- hi_32(x)
8625c28e8Piotr Jasiukajtis	andl	$0x80000000,%eax	/ here, x is infinite, but +/-?
8725c28e8Piotr Jasiukajtis	jz	.NaN_or_pinf		/ branch if x = +INF
8825c28e8Piotr Jasiukajtis	fldz				/ Here, x = -inf, so return 0
8925c28e8Piotr Jasiukajtis	ret
9025c28e8Piotr Jasiukajtis
9125c28e8Piotr Jasiukajtis.NaN_or_pinf:
9225c28e8Piotr Jasiukajtis	/ Here, x = NaN or +inf, so load x and return immediately.
9325c28e8Piotr Jasiukajtis	fldl	4(%esp)
9425c28e8Piotr Jasiukajtis	fwait
9525c28e8Piotr Jasiukajtis	ret
9625c28e8Piotr Jasiukajtis	.align	4
9725c28e8Piotr Jasiukajtis	SET_SIZE(exp2)