xref: /minix3/lib/libm/arch/i387/e_expf.S (revision 2fe8fb192fe7e8720e3e7a77f928da545e872a6a)
1*2fe8fb19SBen Gras/*
2*2fe8fb19SBen Gras * Written by J.T. Conklin <jtc@NetBSD.org>.
3*2fe8fb19SBen Gras * Public domain.
4*2fe8fb19SBen Gras */
5*2fe8fb19SBen Gras
6*2fe8fb19SBen Gras#include <machine/asm.h>
7*2fe8fb19SBen Gras
8*2fe8fb19SBen Gras#include "abi.h"
9*2fe8fb19SBen Gras
10*2fe8fb19SBen Gras
11*2fe8fb19SBen GrasRCSID("$NetBSD: e_expf.S,v 1.6 2008/06/24 17:27:56 drochner Exp $")
12*2fe8fb19SBen Gras
13*2fe8fb19SBen Gras/* e^x = 2^(x * log2(e)) */
14*2fe8fb19SBen GrasENTRY(__ieee754_expf)
15*2fe8fb19SBen Gras	XMM_ONE_ARG_FLOAT_PROLOGUE
16*2fe8fb19SBen Gras
17*2fe8fb19SBen Gras	/*
18*2fe8fb19SBen Gras	 * catch +/-Inf and NaN arguments
19*2fe8fb19SBen Gras	 */
20*2fe8fb19SBen Gras	movl	ARG_FLOAT_ONE,%eax
21*2fe8fb19SBen Gras	andl	$0x7fffffff,%eax
22*2fe8fb19SBen Gras	cmpl	$0x7f800000,%eax
23*2fe8fb19SBen Gras	jae	x_Inf_or_NaN
24*2fe8fb19SBen Gras
25*2fe8fb19SBen Gras	flds	ARG_FLOAT_ONE
26*2fe8fb19SBen Gras	fldl2e
27*2fe8fb19SBen Gras	fmulp				/* x * log2(e) */
28*2fe8fb19SBen Gras	fld	%st(0)
29*2fe8fb19SBen Gras	frndint				/* int(x * log2(e)) */
30*2fe8fb19SBen Gras	fsubr	%st(0),%st(1)		/* fract(x * log2(e)) */
31*2fe8fb19SBen Gras	fxch
32*2fe8fb19SBen Gras	f2xm1				/* 2^(fract(x * log2(e))) - 1 */
33*2fe8fb19SBen Gras	fld1
34*2fe8fb19SBen Gras	faddp				/* 2^(fract(x * log2(e))) */
35*2fe8fb19SBen Gras	fscale				/* e^x */
36*2fe8fb19SBen Gras	fstp	%st(1)
37*2fe8fb19SBen Gras	XMM_FLOAT_EPILOGUE
38*2fe8fb19SBen Gras	ret
39*2fe8fb19SBen Gras
40*2fe8fb19SBen Grasx_Inf_or_NaN:
41*2fe8fb19SBen Gras	/*
42*2fe8fb19SBen Gras	 * Return 0 if x is -Inf.  Otherwise just return x, although the
43*2fe8fb19SBen Gras	 * C version would return (x + x) (Real Indefinite) if x is a NaN.
44*2fe8fb19SBen Gras	 */
45*2fe8fb19SBen Gras	movl	ARG_FLOAT_ONE,%eax
46*2fe8fb19SBen Gras	cmpl	$0xff800000,%eax
47*2fe8fb19SBen Gras	jne	x_not_minus_Inf
48*2fe8fb19SBen Gras	fldz
49*2fe8fb19SBen Gras	XMM_FLOAT_EPILOGUE
50*2fe8fb19SBen Gras	ret
51*2fe8fb19SBen Gras
52*2fe8fb19SBen Grasx_not_minus_Inf:
53*2fe8fb19SBen Gras	flds	ARG_FLOAT_ONE
54*2fe8fb19SBen Gras	XMM_FLOAT_EPILOGUE
55*2fe8fb19SBen Gras	ret
56