e_exp.S revision 217108
12116Sjkh/* 22116Sjkh * Copyright (c) 1993,94 Winning Strategies, Inc. 32116Sjkh * All rights reserved. 42116Sjkh * 52116Sjkh * Redistribution and use in source and binary forms, with or without 62116Sjkh * modification, are permitted provided that the following conditions 72116Sjkh * are met: 82116Sjkh * 1. Redistributions of source code must retain the above copyright 92116Sjkh * notice, this list of conditions and the following disclaimer. 102116Sjkh * 2. Redistributions in binary form must reproduce the above copyright 112116Sjkh * notice, this list of conditions and the following disclaimer in the 122116Sjkh * documentation and/or other materials provided with the distribution. 132116Sjkh * 3. All advertising materials mentioning features or use of this software 142116Sjkh * must display the following acknowledgement: 152116Sjkh * This product includes software developed by Winning Strategies, Inc. 162116Sjkh * 4. The name of the author may not be used to endorse or promote products 172116Sjkh * derived from this software without specific prior written permission. 182116Sjkh * 192116Sjkh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 202116Sjkh * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 212116Sjkh * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 222116Sjkh * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 232116Sjkh * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 242116Sjkh * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 252116Sjkh * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 262116Sjkh * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 272116Sjkh * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 282116Sjkh * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 292116Sjkh */ 302116Sjkh 312116Sjkh/* 322116Sjkh * Written by: 332116Sjkh * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. 342116Sjkh */ 352116Sjkh 3623577Sbde#include <machine/asm.h> 37213337Sdim__FBSDID("$FreeBSD: head/lib/msun/i387/e_exp.S 217108 2011-01-07 16:13:12Z kib $") 382116Sjkh 392116Sjkh/* e^x = 2^(x * log2(e)) */ 40141280SdasENTRY(exp) 4122802Sbde /* 4222802Sbde * If x is +-Inf, then the subtraction would give Inf-Inf = NaN. 4322802Sbde * Avoid this. Also avoid it if x is NaN for convenience. 4422802Sbde */ 4522802Sbde movl 8(%esp),%eax 4622802Sbde andl $0x7fffffff,%eax 4722802Sbde cmpl $0x7ff00000,%eax 4822802Sbde jae x_Inf_or_NaN 4922802Sbde 502116Sjkh fldl 4(%esp) 5122802Sbde 5222802Sbde /* 53151879Sbde * Extended precision is needed to reduce the maximum error from 54151879Sbde * hundreds of ulps to less than 1 ulp. Switch to it if necessary. 55151879Sbde * We may as well set the rounding mode to to-nearest and mask traps 56151879Sbde * if we switch. 5722802Sbde */ 5822802Sbde fstcw 4(%esp) 5922802Sbde movl 4(%esp),%eax 6022802Sbde andl $0x0300,%eax 6122802Sbde cmpl $0x0300,%eax /* RC == 0 && PC == 3? */ 6222802Sbde je 1f /* jump if mode is good */ 6322802Sbde movl $0x137f,8(%esp) 6422802Sbde fldcw 8(%esp) 6522802Sbde1: 662116Sjkh fldl2e 672116Sjkh fmulp /* x * log2(e) */ 6861335Sbde fst %st(1) 692116Sjkh frndint /* int(x * log2(e)) */ 7061335Sbde fst %st(2) 712116Sjkh fsubrp /* fract(x * log2(e)) */ 722116Sjkh f2xm1 /* 2^(fract(x * log2(e))) - 1 */ 732116Sjkh fld1 742116Sjkh faddp /* 2^(fract(x * log2(e))) */ 752116Sjkh fscale /* e^x */ 7661335Sbde fstp %st(1) 7722802Sbde je 1f 7822802Sbde fldcw 4(%esp) 7922802Sbde1: 802116Sjkh ret 8122802Sbde 8222802Sbdex_Inf_or_NaN: 8322802Sbde /* 84151879Sbde * Return 0 if x is -Inf. Otherwise just return x; when x is Inf 85151879Sbde * this gives Inf, and when x is a NaN this gives the same result 86151879Sbde * as (x + x) (x quieted). 8722802Sbde */ 8822802Sbde cmpl $0xfff00000,8(%esp) 8922802Sbde jne x_not_minus_Inf 9022802Sbde cmpl $0,4(%esp) 9122802Sbde jne x_not_minus_Inf 9222802Sbde fldz 9322802Sbde ret 9422802Sbde 9522802Sbdex_not_minus_Inf: 9622802Sbde fldl 4(%esp) 9722802Sbde ret 98192760SattilioEND(exp) 99217108Skib 100217108Skib .section .note.GNU-stack,"",%progbits 101