Home | History | Annotate | Line # | Download | only in i387
e_exp.S revision 1.12
      1  1.12  christos /*	$NetBSD: e_exp.S,v 1.12 2002/02/27 16:32:46 christos Exp $	*/
      2  1.12  christos 
      3  1.12  christos /*
      4  1.12  christos  * Copyright (c) 1993,94 Winning Strategies, Inc.
      5  1.12  christos  * All rights reserved.
      6  1.12  christos  *
      7  1.12  christos  * Redistribution and use in source and binary forms, with or without
      8  1.12  christos  * modification, are permitted provided that the following conditions
      9  1.12  christos  * are met:
     10  1.12  christos  * 1. Redistributions of source code must retain the above copyright
     11  1.12  christos  *    notice, this list of conditions and the following disclaimer.
     12  1.12  christos  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.12  christos  *    notice, this list of conditions and the following disclaimer in the
     14  1.12  christos  *    documentation and/or other materials provided with the distribution.
     15  1.12  christos  * 3. All advertising materials mentioning features or use of this software
     16  1.12  christos  *    must display the following acknowledgement:
     17  1.12  christos  *      This product includes software developed by Winning Strategies, Inc.
     18  1.12  christos  * 4. The name of the author may not be used to endorse or promote products
     19  1.12  christos  *    derived from this software without specific prior written permission.
     20  1.12  christos  *
     21  1.12  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  1.12  christos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.12  christos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.12  christos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.12  christos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  1.12  christos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.12  christos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.12  christos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.12  christos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  1.12  christos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  1.12  christos  */
     32  1.12  christos 
     33   1.1       jtc /*
     34  1.12  christos  * Written by:
     35  1.12  christos  *	J.T. Conklin (jtc (at) wimsey.com), Winning Strategies, Inc.
     36   1.1       jtc  */
     37   1.1       jtc 
     38   1.1       jtc #include <machine/asm.h>
     39   1.1       jtc 
     40  1.10      fvdl #include "abi.h"
     41  1.10      fvdl 
     42  1.12  christos RCSID("$NetBSD: e_exp.S,v 1.12 2002/02/27 16:32:46 christos Exp $")
     43  1.12  christos #if 0
     44  1.12  christos RCSID("$FreeBSD: src/lib/msun/i387/e_exp.S,v 1.8.2.1 2000/07/10 09:16:28 obrien Exp $")
     45  1.12  christos #endif
     46   1.2       jtc 
     47   1.1       jtc /* e^x = 2^(x * log2(e)) */
     48   1.1       jtc ENTRY(__ieee754_exp)
     49  1.12  christos #ifndef __i386__
     50  1.12  christos 	/*
     51  1.12  christos 	 * XXX: This code is broken and needs to be merged with the i386 case.
     52  1.12  christos 	 */
     53  1.10      fvdl 	fstcw	-12(%rsp)
     54  1.10      fvdl 	movw	-12(%rsp),%dx
     55  1.10      fvdl 	orw	$0x0180,%dx
     56  1.10      fvdl 	movw	%dx,-16(%rsp)
     57  1.10      fvdl 	fldcw	-16(%rsp)
     58  1.10      fvdl 	movsd	%xmm0,-8(%rsp)
     59  1.10      fvdl 	fldl	-8(%rsp)
     60   1.6       jtc 
     61   1.1       jtc 	fldl2e
     62   1.1       jtc 	fmulp				/* x * log2(e) */
     63  1.10      fvdl 	fld	%st(0)
     64   1.1       jtc 	frndint				/* int(x * log2(e)) */
     65   1.7       jtc 	fxch	%st(1)
     66   1.7       jtc 	fsub	%st(1),%st		/* fract(x * log2(e)) */
     67   1.8    simonb 	f2xm1				/* 2^(fract(x * log2(e))) - 1 */
     68   1.1       jtc 	fld1
     69   1.1       jtc 	faddp				/* 2^(fract(x * log2(e))) */
     70   1.1       jtc 	fscale				/* e^x */
     71  1.10      fvdl 	fstp	%st(1)
     72   1.6       jtc 
     73  1.10      fvdl 	fstpl	-8(%rsp)
     74  1.10      fvdl 	movsd	-8(%rsp),%xmm0
     75  1.11      fvdl 	fldcw	-12(%rsp)
     76  1.12  christos 	ret
     77  1.12  christos #else
     78  1.12  christos 	/*
     79  1.12  christos 	 * If x is +-Inf, then the subtraction would give Inf-Inf = NaN.
     80  1.12  christos 	 * Avoid this.  Also avoid it if x is NaN for convenience.
     81  1.12  christos 	 */
     82  1.12  christos 	movl	8(%esp),%eax
     83  1.12  christos 	andl	$0x7fffffff,%eax
     84  1.12  christos 	cmpl	$0x7ff00000,%eax
     85  1.12  christos 	jae	x_Inf_or_NaN
     86  1.12  christos 
     87  1.12  christos 	fldl	4(%esp)
     88  1.12  christos 
     89  1.12  christos 	/*
     90  1.12  christos 	 * Ensure that the rounding mode is to nearest (to give the smallest
     91  1.12  christos 	 * possible fraction) and that the precision is as high as possible.
     92  1.12  christos 	 * We may as well mask interrupts if we switch the mode.
     93  1.12  christos 	 */
     94  1.12  christos 	fstcw	4(%esp)
     95  1.12  christos 	movl	4(%esp),%eax
     96  1.12  christos 	andl	$0x0300,%eax
     97  1.12  christos 	cmpl	$0x0300,%eax		/* RC == 0 && PC == 3? */
     98  1.12  christos 	je	1f			/* jump if mode is good */
     99  1.12  christos 	movl	$0x137f,8(%esp)
    100  1.12  christos 	fldcw	8(%esp)
    101  1.12  christos 1:
    102  1.12  christos 	fldl2e
    103  1.12  christos 	fmulp				/* x * log2(e) */
    104  1.12  christos 	fst	%st(1)
    105  1.12  christos 	frndint				/* int(x * log2(e)) */
    106  1.12  christos 	fst	%st(2)
    107  1.12  christos 	fsubrp				/* fract(x * log2(e)) */
    108  1.12  christos 	f2xm1				/* 2^(fract(x * log2(e))) - 1 */
    109  1.12  christos 	fld1
    110  1.12  christos 	faddp				/* 2^(fract(x * log2(e))) */
    111  1.12  christos 	fscale				/* e^x */
    112  1.12  christos 	fstp	%st(1)
    113  1.12  christos 	je	1f
    114  1.12  christos 	fldcw	4(%esp)
    115  1.12  christos 1:
    116  1.12  christos 	ret
    117  1.12  christos 
    118  1.12  christos x_Inf_or_NaN:
    119  1.12  christos 	/*
    120  1.12  christos 	 * Return 0 if x is -Inf.  Otherwise just return x, although the
    121  1.12  christos 	 * C version would return (x + x) (Real Indefinite) if x is a NaN.
    122  1.12  christos 	 */
    123  1.12  christos 	cmpl	$0xfff00000,8(%esp)
    124  1.12  christos 	jne	x_not_minus_Inf
    125  1.12  christos 	cmpl	$0,4(%esp)
    126  1.12  christos 	jne	x_not_minus_Inf
    127  1.12  christos 	fldz
    128  1.12  christos 	ret
    129  1.12  christos 
    130  1.12  christos x_not_minus_Inf:
    131  1.12  christos 	fldl	4(%esp)
    132  1.12  christos 	ret
    133  1.10      fvdl #endif
    134